java.lang.Object
org.cybergarage.upnp.xml.NodeData
org.cybergarage.upnp.StateVariable

public class StateVariableextends NodeData
Holds a UPnP state variable definition and the value currently set on it.
  • Field Details

    • ELEM_NAME

      public static final String ELEM_NAME
      XML element name of a state variable definition.
      See Also:
    • stateVariableNode

      private Node stateVariableNode
      /////////////////////////////////////////////
    • serviceNode

      private Node serviceNode
      The XML node the variable was read from.
    • NAME

      private static final String NAME
      /////////////////////////////////////////////
      See Also:
    • DATATYPE

      private static final String DATATYPE
      /////////////////////////////////////////////
      See Also:
    • SENDEVENTS

      private static final String SENDEVENTS
      /////////////////////////////////////////////
      See Also:
    • SENDEVENTS_YES

      private static final String SENDEVENTS_YES
      Value of the send-events flag that turns events on.
      See Also:
    • SENDEVENTS_NO

      private static final String SENDEVENTS_NO
      Value of the send-events flag that turns events off.
      See Also:
    • upnpStatus

      private UPnPStatus upnpStatus
      /////////////////////////////////////////////
    • DEFAULT_VALUE

      private static final String DEFAULT_VALUE
      Tag naming a variable's default value in the XML.
      See Also:
    • userData

      private Object userData
      /////////////////////////////////////////////
  • Constructor Details

    • StateVariable

      public StateVariable()
      Creates a new StateVariable with default initialization.
    • StateVariable

      public StateVariable(Node serviceNode, Node stateVarNode)
      Creates a StateVariable with specified service and state variable nodes.
      Parameters:
      serviceNode - service node this variable belongs to
      stateVarNode - state variable node containing definition
  • Method Details

    • getServiceNode

      public Node getServiceNode()
      Gets the service node this state variable belongs to.
      Returns:
      the enclosing service node, or null if none has been set
    • setServiceNode

      void setServiceNode(Node n)
      Sets service node this state variable belongs to.
      Parameters:
      n - the node to record as the enclosing service
    • getService

      public Service getService()
      Gets the service that owns this state variable.
      Returns:
      the owning service, or null if no service node is set
    • getStateVariableNode

      public Node getStateVariableNode()
      Gets the state variable node containing variable definition.
      Returns:
      state variable node
    • isStateVariableNode

      public static boolean isStateVariableNode(Node node)
      Tests whether a node names a state variable element.
      Parameters:
      node - the XML node to test against the stateVariable element name
      Returns:
      true if the node is a stateVariable element, false otherwise
    • setName

      public void setName(String value)
      Sets name of this state variable.
      Parameters:
      value - name to set
    • getName

      public String getName()
      Gets the name of this state variable.
      Returns:
      state variable name
    • setDataType

      public void setDataType(String value)
      Sets the dataType of this state variable.
      Parameters:
      value - the UPnP data type name, for example "string" or "i4"
    • getDataType

      public String getDataType()
      Gets the dataType of this state variable.
      Returns:
      the UPnP data type name, or null if none is set
    • setSendEvents

      public void setSendEvents(boolean state)
      Sets the sendEvents attribute of this state variable.
      Parameters:
      state - true to notify subscribers when the value changes, false to suppress notification
    • isSendEvents

      public boolean isSendEvents()
      Reports whether this state variable notifies subscribers on change.
      Returns:
      true if the sendEvents attribute reads "yes", false if it reads "no" or is absent
    • set

      public void set(StateVariable stateVar)
      Copies the name, value, dataType and sendEvents flag from another state variable into this one.
      Parameters:
      stateVar - the state variable to copy the definition from
    • getStateVariableData

      public StateVariableData getStateVariableData()
      Gets the user data attached to the state variable node, creating it on first use.
      Returns:
      the StateVariableData attached to the node, never null
    • setValue

      public void setValue(String value)
      Sets the value of this state variable and, when the variable has an owning service and event notification is enabled, notifies subscribers.
      Parameters:
      value - the new value, or null to clear it
    • setValue

      public void setValue(int value)
      Sets the value of this state variable from its decimal string form.
      Parameters:
      value - the value to convert with Integer.toString()
    • setValue

      public void setValue(long value)
      Sets the value of this state variable from its decimal string form.
      Parameters:
      value - the value to convert with Long.toString()
    • getValue

      public String getValue()
      Gets the current value of this state variable.
      Returns:
      the value stored in the attached user data, or null if none is set
    • getAllowedValueList

      public AllowedValueList getAllowedValueList()
      Gets the allowed value list of this state variable, wrapped from the allowedValueList child node.
      Returns:
      the allowed values, or null if no allowedValueList node is present
    • setAllowedValueList

      public void setAllowedValueList(AllowedValueList avl)
      This method override the value of the AllowedValueList Node
      of this object.

      Note: This method should be used to create a dynamic
      Device without writing any XML that describe the device
      .
      Note2: The enforce the constraint of the SCPD rule the
      AllowedValueList and AllowedValueRange are mutual exclusive
      the last set will be the only present
      Parameters:
      avl - The new AllowedValueList
    • hasAllowedValueList

      public boolean hasAllowedValueList()
      Reports whether this state variable carries an allowedValueList node.
      Returns:
      true if an allowedValueList is present, false otherwise
    • getAllowedValueRange

      public AllowedValueRange getAllowedValueRange()
      Gets the allowed value range of this state variable, wrapped from the allowedValueRange child node.
      Returns:
      the allowed range, or null if no allowedValueRange node is present
    • setAllowedValueRange

      public void setAllowedValueRange(AllowedValueRange avr)
      This method override the value of the AllowedValueRange Node
      of this object.

      Note: This method should be used to create a dynamic
      Device without writing any XML that describe the device
      .
      Note2: The enforce the constraint of the SCPD rule the
      AllowedValueList and AllowedValueRange are mutual exclusive
      the last set will be the only present
      Parameters:
      avr - The new AllowedValueRange
    • hasAllowedValueRange

      public boolean hasAllowedValueRange()
      Reports whether this state variable carries an allowedValueRange node.
      Returns:
      true if an allowedValueRange is present, false otherwise
    • getQueryListener

      public QueryListener getQueryListener()
      Gets the listener notified when a query for this state variable arrives.
      Returns:
      the registered query listener, or null if none is set
    • setQueryListener

      public void setQueryListener(QueryListener listener)
      Sets the listener notified when a query for this state variable arrives.
      Parameters:
      listener - the listener to invoke, or null to clear it
    • performQueryListener

      public boolean performQueryListener(QueryRequest queryReq)
      Runs the query listener against a copy of this variable and posts the listener's outcome back to the requesting peer.
      Parameters:
      queryReq - the request the response is posted to
      Returns:
      true if a listener was registered, false if none was
    • getQueryResponse

      public QueryResponse getQueryResponse()
      Gets the response from the most recent query posted for this variable.
      Returns:
      the last query response, or null if no query has been made
    • setQueryResponse

      private void setQueryResponse(QueryResponse res)
      Records the answer to a query on this variable.
      Parameters:
      res - the response to store
    • getQueryStatus

      public UPnPStatus getQueryStatus()
      Gets the UPnP error carried by the most recent query response.
      Returns:
      the status of the last query response
    • postQuerylAction

      public boolean postQuerylAction()
      Posts a query for this state variable and stores the reply as both the query response and the variable's value.
      Returns:
      true if the query succeeded, false if it returned a UPnP error
    • setStatus

      public void setStatus(int code, String descr)
      Sets the UPnP status reported alongside this state variable.
      Parameters:
      code - the UPnP error code, for example UPnPStatus.INVALID_VAR (404)
      descr - the human readable text to report with the code
    • setStatus

      public void setStatus(int code)
      Sets the UPnP status code, deriving the description text from the code.
      Parameters:
      code - the UPnP error code, for example UPnPStatus.INVALID_VAR (404)
    • getStatus

      public UPnPStatus getStatus()
      Gets the UPnP status currently held for this state variable.
      Returns:
      the status, which is never null but starts out unset
    • getDefaultValue

      public String getDefaultValue()
      Gives the declared default value of this state variable.
      Returns:
      the declared default, or null if none is set
    • setDefaultValue

      public void setDefaultValue(String value)
      This method override the value of the DefaultValue of this object.

      Note: This method should be used to create a dynamic
      Device without writing any XML that describe the device
      .
      Parameters:
      value - The new String value
    • setUserData

      public void setUserData(Object data)
      Sets the object this variable keeps as application private data, separate from the UPnP value and query response.
      Parameters:
      data - the object to retain, or null to clear it
    • getUserData

      public Object getUserData()
      Gets the application private data retained by this variable.
      Returns:
      the retained object, or null if none has been set