org.fosstrak.llrp.commander.util
Class LLRPTreeMaintainer

java.lang.Object
  extended by java.util.Observable
      extended by org.fosstrak.llrp.commander.util.LLRPTreeMaintainer

public class LLRPTreeMaintainer
extends java.util.Observable

This class constitutes the interface to llrp message objects. All modifications to llrp message objects are performed through this class. Users of this class can register to be notified when changes to the llrp message occur. This class has a reference to the LLRPMessage object and is not implemented as a static class, because the implementation of the getParent(...) method requires to know the root of the object tree.

Author:
Ulrich Etter, ETHZ

Constructor Summary
LLRPTreeMaintainer(org.llrp.ltk.types.LLRPMessage root)
           
 
Method Summary
 void addChild(java.util.List<org.llrp.ltk.types.LLRPParameter> list, org.llrp.ltk.types.LLRPParameter child)
          Adds the given parameter to the given parameter list.
 java.lang.Object getChild(java.lang.Object messageOrParameter, java.lang.String childName)
          Returns the child with the given name of the given message/parameter.
 java.lang.Object getDefinition(java.lang.Object messageOrParameter)
          Returns the definition of the given message or parameter.
 org.llrp.ltk.types.LLRPType getField(java.lang.Object messageOrParameter, java.lang.String fieldName)
          Returns the field with the given name of the given message/parameter
 java.util.List<org.llrp.ltk.types.LLRPType> getFields(java.lang.Object messageOrParameter)
          Returns all fields of the given message/parameter.
 java.lang.String getName(java.lang.Object treeElement)
          Returns the name of the given tree element.
 java.util.List<java.lang.Object> getNonNullChildren(java.lang.Object treeElement)
          Returns all children of the given tree element that are not null.
 java.util.List<java.lang.Object> getNonRecursivelyInvalidMessageOrParameterDescendants(java.lang.Object treeElement)
          Returns all message/parameter descendants of the given tree element which are (non-recursively) invalid (including the tree element itself).
 java.lang.Object getParent(java.lang.Object treeElement)
          Returns the parent of the given tree element.
 org.llrp.ltk.types.LLRPMessage getRoot()
          Returns the llrp message associated with this LLRPTreeMaintainer.
 boolean isNonRecursivelyValid(java.lang.Object treeElement)
          Returns true if the given tree element is valid (ignoring the validity of its descendants), and false otherwise.
 boolean isValid(java.lang.Object treeElement)
          Returns true if the given tree element is valid (including all its descendants), and false otherwise.
 void removeChild(java.util.List<org.llrp.ltk.types.LLRPParameter> list, org.llrp.ltk.types.LLRPParameter child)
          Removes the given parameter from the given parameter list.
 void setChild(java.lang.Object messageOrParameter, java.lang.String childName, org.llrp.ltk.types.LLRPParameter child)
          Sets the given parameter as child of the given message/parameter.
 void setField(java.lang.Object messageOrParameter, java.lang.String fieldName, org.llrp.ltk.types.LLRPType fieldValue)
          Sets the field with the given name of the given message/parameter to the given value.
 void setRoot(org.llrp.ltk.types.LLRPMessage root)
          Sets the llrp message this LLRPTreeMaintainer shall maintain.
 java.lang.String validateChildPresence(java.lang.Object messageOrParameter, java.lang.String childName)
          Checks whether the child is present when it has to be present.
 java.lang.String validateEmptiness(java.util.List<org.llrp.ltk.types.LLRPParameter> list)
          Checks whether the list is non-empty when it has to be non-empty.
 java.lang.String validateField(java.lang.Object messageOrParameter, java.lang.String fieldName)
          Checks whether the field with the given name of the given message/parameter is valid.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LLRPTreeMaintainer

public LLRPTreeMaintainer(org.llrp.ltk.types.LLRPMessage root)
Method Detail

setRoot

public void setRoot(org.llrp.ltk.types.LLRPMessage root)
Sets the llrp message this LLRPTreeMaintainer shall maintain.

Parameters:
root - the llrp message LLRPTreeMaintainer shall maintain

getRoot

public org.llrp.ltk.types.LLRPMessage getRoot()
Returns the llrp message associated with this LLRPTreeMaintainer.

Returns:
the llrp message associated with this LLRPTreeMaintainer.

setChild

public void setChild(java.lang.Object messageOrParameter,
                     java.lang.String childName,
                     org.llrp.ltk.types.LLRPParameter child)
Sets the given parameter as child of the given message/parameter. The message/parameter will know the parameter under the given name.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
childName - the name of the child
child - the parameter that should be set as a child

addChild

public void addChild(java.util.List<org.llrp.ltk.types.LLRPParameter> list,
                     org.llrp.ltk.types.LLRPParameter child)
Adds the given parameter to the given parameter list.

Parameters:
list - the parameter list to which the child shall be added
child - the parameter to add to the parameter list

removeChild

public void removeChild(java.util.List<org.llrp.ltk.types.LLRPParameter> list,
                        org.llrp.ltk.types.LLRPParameter child)
Removes the given parameter from the given parameter list.

Parameters:
list - the parameter list from which the child shall be removed
child - the

getChild

public java.lang.Object getChild(java.lang.Object messageOrParameter,
                                 java.lang.String childName)
Returns the child with the given name of the given message/parameter.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
childName - the name of the child.
Returns:
the child to the given name, null if not existing.

getNonNullChildren

public java.util.List<java.lang.Object> getNonNullChildren(java.lang.Object treeElement)
Returns all children of the given tree element that are not null.

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
a list of children to a given tree element.

getParent

public java.lang.Object getParent(java.lang.Object treeElement)
Returns the parent of the given tree element. If the given element is the root of the tree, Null is returned. This implementation searches the whole message object tree for the given tree element (starting at the root). This is done, because LTKJava does not provide references from children to their parents (i.e. from sub-parameters to parameters).

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
the parent of a given element in the tree, null if it is the root.

getField

public org.llrp.ltk.types.LLRPType getField(java.lang.Object messageOrParameter,
                                            java.lang.String fieldName)
Returns the field with the given name of the given message/parameter

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
fieldName -
Returns:
the field with the given name of the given message/parameter.

setField

public void setField(java.lang.Object messageOrParameter,
                     java.lang.String fieldName,
                     org.llrp.ltk.types.LLRPType fieldValue)
Sets the field with the given name of the given message/parameter to the given value.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
fieldName -
fieldValue -

getFields

public java.util.List<org.llrp.ltk.types.LLRPType> getFields(java.lang.Object messageOrParameter)
Returns all fields of the given message/parameter.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
Returns:
a list of llrp fields to a given parameter or message.

isValid

public boolean isValid(java.lang.Object treeElement)
Returns true if the given tree element is valid (including all its descendants), and false otherwise.

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
true if the given tree element is valid, false otherwise.

isNonRecursivelyValid

public boolean isNonRecursivelyValid(java.lang.Object treeElement)
Returns true if the given tree element is valid (ignoring the validity of its descendants), and false otherwise.

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
true if the given tree element is valid, false otherwise.

getNonRecursivelyInvalidMessageOrParameterDescendants

public java.util.List<java.lang.Object> getNonRecursivelyInvalidMessageOrParameterDescendants(java.lang.Object treeElement)
Returns all message/parameter descendants of the given tree element which are (non-recursively) invalid (including the tree element itself).

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
a list of invalid LLRPMessages and LLRPParameters

validateField

public java.lang.String validateField(java.lang.Object messageOrParameter,
                                      java.lang.String fieldName)
Checks whether the field with the given name of the given message/parameter is valid.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
fieldName -
Returns:
an error message if the field is not valid, and an empty string otherwise

validateChildPresence

public java.lang.String validateChildPresence(java.lang.Object messageOrParameter,
                                              java.lang.String childName)
Checks whether the child is present when it has to be present.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
childName -
Returns:
an error message if the child is not present illegally, and an empty string otherwise

validateEmptiness

public java.lang.String validateEmptiness(java.util.List<org.llrp.ltk.types.LLRPParameter> list)
Checks whether the list is non-empty when it has to be non-empty.

Parameters:
list -
Returns:
an error message if the list is empty illegally, and an empty string otherwise

getName

public java.lang.String getName(java.lang.Object treeElement)
Returns the name of the given tree element.

Parameters:
treeElement - either a LLRPMessage or a LLRPParameter or a List<LLRPParameter>
Returns:
the name of a given tree element.

getDefinition

public java.lang.Object getDefinition(java.lang.Object messageOrParameter)
Returns the definition of the given message or parameter.

Parameters:
messageOrParameter - either a LLRPMessage or a LLRPParameter
Returns:
either a MessageDefinition or a ParameterDefinition


Copyright © 2009. All Rights Reserved.