[ 
https://issues.apache.org/jira/browse/SCXML-240?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jacob Saoumi updated SCXML-240:
-------------------------------
    Description: 
I need to extend the state model to have user-defined properties. For example:

<state id="xy" cs:type="myStateType"></state>

The solution is to easy. Add the following methods to the 
org.apache.commons.scxml2.model.State class:

/**
     * set a user-defined property with the given {@code name}
     * 
     * @param name
     *            the name of the user-defined propery
     * @param value
     *            the value of the property
     */
    public final synchronized void setProperty(String name, String value)
    {
        if (this.extendProperties == null) {
            this.extendProperties = new HashMap<String, String>();
        }
        this.extendProperties.put(name, value);
    }

    /**
     * 
     * @param name
     *            the name of the user-defined propery
     * @return the value of the property with the given {@code name}
     */
    public final String getProperty(String name)
    {
        return extendProperties == null ? null : extendProperties.get(name);
    }

    /**
     * 
     * @return a set of user-defined properties names
     */
    public final Set<String> getPropertyNames()
    {
        return extendProperties == null ? null : extendProperties.keySet();
    }

    /**
     * 
     * @return the count of the user-defined properties
     */
    public final int getPropertyCount()
    {
        return extendProperties == null ? 0 : extendProperties.size();
    }

and extend the readState method of the SCXMLReader to read this properties from 
xml:

// reading user-defined properties
        int attrCount = reader.getAttributeCount();
        for (int i = 0; i < attrCount; i++) {
            QName attrName = reader.getAttributeName(i);
            String prefix = nullIfEmpty(attrName.getPrefix());
            String localPart = attrName.getLocalPart();
            if (prefix != null) {
                localPart = prefix + ":" + localPart;
            }
            if (ATTR_SRC.equals(localPart) || TTR_INITIAL.equals(localPart) || 
ATTR_ID.equals(localPart)) {
                continue;
            }
            state.setProperty(localPart, reader.getAttributeValue(i));
        }

  was:
I need to extend the state model to have a user-defined properties. For example:

<state id="xy" cs:type="myStateType"></state>

The solution is to easy. Add the following methods to the 
org.apache.commons.scxml2.model.State class:

/**
     * set a user-defined property with the given {@code name}
     * 
     * @param name
     *            the name of the user-defined propery
     * @param value
     *            the value of the property
     */
    public final synchronized void setProperty(String name, String value)
    {
        if (this.extendProperties == null) {
            this.extendProperties = new HashMap<String, String>();
        }
        this.extendProperties.put(name, value);
    }

    /**
     * 
     * @param name
     *            the name of the user-defined propery
     * @return the value of the property with the given {@code name}
     */
    public final String getProperty(String name)
    {
        return extendProperties == null ? null : extendProperties.get(name);
    }

    /**
     * 
     * @return a set of user-defined properties names
     */
    public final Set<String> getPropertyNames()
    {
        return extendProperties == null ? null : extendProperties.keySet();
    }

    /**
     * 
     * @return the count of the user-defined properties
     */
    public final int getPropertyCount()
    {
        return extendProperties == null ? 0 : extendProperties.size();
    }

and extend the readState method of the SCXMLReader to read this properties from 
xml:

// reading user-defined properties
        int attrCount = reader.getAttributeCount();
        for (int i = 0; i < attrCount; i++) {
            QName attrName = reader.getAttributeName(i);
            String prefix = nullIfEmpty(attrName.getPrefix());
            String localPart = attrName.getLocalPart();
            if (prefix != null) {
                localPart = prefix + ":" + localPart;
            }
            if (ATTR_SRC.equals(localPart) || TTR_INITIAL.equals(localPart) || 
ATTR_ID.equals(localPart)) {
                continue;
            }
            state.setProperty(localPart, reader.getAttributeValue(i));
        }


> adding user-defined properties to the state model
> -------------------------------------------------
>
>                 Key: SCXML-240
>                 URL: https://issues.apache.org/jira/browse/SCXML-240
>             Project: Commons SCXML
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Jacob Saoumi
>              Labels: patch
>             Fix For: 2.0
>
>
> I need to extend the state model to have user-defined properties. For example:
> <state id="xy" cs:type="myStateType"></state>
> The solution is to easy. Add the following methods to the 
> org.apache.commons.scxml2.model.State class:
> /**
>      * set a user-defined property with the given {@code name}
>      * 
>      * @param name
>      *            the name of the user-defined propery
>      * @param value
>      *            the value of the property
>      */
>     public final synchronized void setProperty(String name, String value)
>     {
>         if (this.extendProperties == null) {
>             this.extendProperties = new HashMap<String, String>();
>         }
>         this.extendProperties.put(name, value);
>     }
>     /**
>      * 
>      * @param name
>      *            the name of the user-defined propery
>      * @return the value of the property with the given {@code name}
>      */
>     public final String getProperty(String name)
>     {
>         return extendProperties == null ? null : extendProperties.get(name);
>     }
>     /**
>      * 
>      * @return a set of user-defined properties names
>      */
>     public final Set<String> getPropertyNames()
>     {
>         return extendProperties == null ? null : extendProperties.keySet();
>     }
>     /**
>      * 
>      * @return the count of the user-defined properties
>      */
>     public final int getPropertyCount()
>     {
>         return extendProperties == null ? 0 : extendProperties.size();
>     }
> and extend the readState method of the SCXMLReader to read this properties 
> from xml:
> // reading user-defined properties
>         int attrCount = reader.getAttributeCount();
>         for (int i = 0; i < attrCount; i++) {
>             QName attrName = reader.getAttributeName(i);
>             String prefix = nullIfEmpty(attrName.getPrefix());
>             String localPart = attrName.getLocalPart();
>             if (prefix != null) {
>                 localPart = prefix + ":" + localPart;
>             }
>             if (ATTR_SRC.equals(localPart) || TTR_INITIAL.equals(localPart) 
> || ATTR_ID.equals(localPart)) {
>                 continue;
>             }
>             state.setProperty(localPart, reader.getAttributeValue(i));
>         }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to