java.lang.Object
org.cybergarage.upnp.xml.NodeData
org.cybergarage.upnp.StateVariable
Holds a UPnP state variable definition and the value currently set on it.
Field Summary
Modifier and TypeFieldDescriptionprivate static final String/////////////////////////////////////////////private static final StringTag naming a variable's default value in the XML.static final StringXML element name of a state variable definition.private static final String/////////////////////////////////////////////private static final String/////////////////////////////////////////////private static final StringValue of the send-events flag that turns events off.private static final StringValue of the send-events flag that turns events on.private NodeThe XML node the variable was read from.private Node/////////////////////////////////////////////private UPnPStatus/////////////////////////////////////////////private Object/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescriptionCreates a new StateVariable with default initialization.StateVariable(Node serviceNode, Node stateVarNode) Creates a StateVariable with specified service and state variable nodes.Method Summary
Modifier and TypeMethodDescriptionGets the allowed value list of this state variable, wrapped from the allowedValueList child node.Gets the allowed value range of this state variable, wrapped from the allowedValueRange child node.Gets the dataType of this state variable.Gives the declared default value of this state variable.getName()Gets the name of this state variable.Gets the listener notified when a query for this state variable arrives.Gets the response from the most recent query posted for this variable.Gets the UPnP error carried by the most recent query response.Gets the service that owns this state variable.Gets the service node this state variable belongs to.Gets the user data attached to the state variable node, creating it on first use.Gets the state variable node containing variable definition.Gets the UPnP status currently held for this state variable.Gets the application private data retained by this variable.getValue()Gets the current value of this state variable.booleanReports whether this state variable carries an allowedValueList node.booleanReports whether this state variable carries an allowedValueRange node.booleanReports whether this state variable notifies subscribers on change.static booleanisStateVariableNode(Node node) Tests whether a node names a state variable element.booleanperformQueryListener(QueryRequest queryReq) Runs the query listener against a copy of this variable and posts the listener's outcome back to the requesting peer.booleanPosts a query for this state variable and stores the reply as both the query response and the variable's value.voidset(StateVariable stateVar) Copies the name, value, dataType and sendEvents flag from another state variable into this one.voidThis method override the value of the AllowedValueList Node
of this object.voidThis method override the value of the AllowedValueRange Node
of this object.voidsetDataType(String value) Sets the dataType of this state variable.voidsetDefaultValue(String value) This method override the value of the DefaultValue of this object.voidSets name of this state variable.voidsetQueryListener(QueryListener listener) Sets the listener notified when a query for this state variable arrives.private voidRecords the answer to a query on this variable.voidsetSendEvents(boolean state) Sets the sendEvents attribute of this state variable.(package private) voidSets service node this state variable belongs to.voidsetStatus(int code) Sets the UPnP status code, deriving the description text from the code.voidSets the UPnP status reported alongside this state variable.voidsetUserData(Object data) Sets the object this variable keeps as application private data, separate from the UPnP value and query response.voidsetValue(int value) Sets the value of this state variable from its decimal string form.voidsetValue(long value) Sets the value of this state variable from its decimal string form.voidSets the value of this state variable and, when the variable has an owning service and event notification is enabled, notifies subscribers.
Field Details
ELEM_NAME
XML element name of a state variable definition.- See Also:
stateVariableNode
/////////////////////////////////////////////serviceNode
The XML node the variable was read from.NAME
/////////////////////////////////////////////- See Also:
DATATYPE
/////////////////////////////////////////////- See Also:
SENDEVENTS
/////////////////////////////////////////////- See Also:
SENDEVENTS_YES
Value of the send-events flag that turns events on.- See Also:
SENDEVENTS_NO
Value of the send-events flag that turns events off.- See Also:
upnpStatus
/////////////////////////////////////////////DEFAULT_VALUE
Tag naming a variable's default value in the XML.- See Also:
userData
/////////////////////////////////////////////
Constructor Details
StateVariable
public StateVariable()Creates a new StateVariable with default initialization.StateVariable
Method Details
getServiceNode
Gets the service node this state variable belongs to.- Returns:
- the enclosing service node, or null if none has been set
setServiceNode
Sets service node this state variable belongs to.- Parameters:
n- the node to record as the enclosing service
getService
Gets the service that owns this state variable.- Returns:
- the owning service, or null if no service node is set
getStateVariableNode
Gets the state variable node containing variable definition.- Returns:
- state variable node
isStateVariableNode
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
getName
setDataType
Sets the dataType of this state variable.- Parameters:
value- the UPnP data type name, for example "string" or "i4"
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
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
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
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
Gets the current value of this state variable.- Returns:
- the value stored in the attached user data, or null if none is set
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
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
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
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
Gets the listener notified when a query for this state variable arrives.- Returns:
- the registered query listener, or null if none is set
setQueryListener
Sets the listener notified when a query for this state variable arrives.- Parameters:
listener- the listener to invoke, or null to clear it
performQueryListener
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
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
Records the answer to a query on this variable.- Parameters:
res- the response to store
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
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
Gets the UPnP status currently held for this state variable.- Returns:
- the status, which is never null but starts out unset
getDefaultValue
Gives the declared default value of this state variable.- Returns:
- the declared default, or null if none is set
setDefaultValue
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
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
Gets the application private data retained by this variable.- Returns:
- the retained object, or null if none has been set