dk.opi.io
Class DefaultIOItemBrowseTreeNode

java.lang.Object
  extended bydk.opi.io.DefaultIOItemBrowseTreeNode
All Implemented Interfaces:
IOItemBrowseTreeNode

public class DefaultIOItemBrowseTreeNode
extends Object
implements IOItemBrowseTreeNode

This class represents browse information about items (leafs) and groups (branches) on an communication server, ie. an OPC server, being capable of presenting available items in a tree-like format.

Please refer to OpcClientApi.getServerItemsInfo() for more detailed information on how to obtain instances of this class

Since:
JOPCClient v1.200

Field Summary
protected  boolean allowsChildren
          true if the node is able to have children
protected  Vector children
          array of children, may be null if this node has no children
static Enumeration EMPTY_ENUMERATION
          An enumeration that is always empty.
protected  IOItemBrowseTreeNode parent
          this node's parent, or null if this node has no parent
protected  Object userObject
          optional user object
 
Constructor Summary
DefaultIOItemBrowseTreeNode(String shortName, String longName)
          Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
DefaultIOItemBrowseTreeNode(String shortName, String longName, boolean allowsChildren)
          Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.
 
Method Summary
 void add(IOItemBrowseTreeNode aNode)
          Append the specified node to the end of this nodes children list
 Enumeration children()
          Creates and returns a forward-order enumeration of this node's children.
 boolean getAllowsChildren()
          Returns true if this node is allowed to have children.
 IOItemBrowseTreeNode getChildAt(int index)
          Returns the child at the specified index in this node's child array.
 int getChildCount()
          Returns the number of children of this node.
 int getIndex(IOItemBrowseTreeNode aChild)
          Returns the index of the specified child in this node's child array.
 String getLongName()
          Returns the long representation of this item
 IOItemBrowseTreeNode getParent()
          Returns this node's parent or null if this node has no parent.
 String getShortName()
          Returns the short representation of this item
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isNodeChild(IOItemBrowseTreeNode aNode)
          Returns true if aNode is a child of this node.
 void setParent(IOItemBrowseTreeNode newParent)
          Sets this node's parent to newParent but does not change the parent's child array.
 String toString()
          Returns the short name for this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_ENUMERATION

public static final Enumeration EMPTY_ENUMERATION
An enumeration that is always empty. This is used when an enumeration of a leaf node's children is requested.


parent

protected IOItemBrowseTreeNode parent
this node's parent, or null if this node has no parent


children

protected Vector children
array of children, may be null if this node has no children


userObject

protected transient Object userObject
optional user object


allowsChildren

protected boolean allowsChildren
true if the node is able to have children

Constructor Detail

DefaultIOItemBrowseTreeNode

public DefaultIOItemBrowseTreeNode(String shortName,
                                   String longName)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Parameters:
shortName - a String value
longName - a String value

DefaultIOItemBrowseTreeNode

public DefaultIOItemBrowseTreeNode(String shortName,
                                   String longName,
                                   boolean allowsChildren)
Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Parameters:
shortName - a String value
longName - a String value
allowsChildren - if true, the node is allowed to have child nodes - otherwise, it is always a leaf node
Method Detail

getShortName

public String getShortName()
Returns the short representation of this item

Specified by:
getShortName in interface IOItemBrowseTreeNode

getLongName

public String getLongName()
Returns the long representation of this item

Specified by:
getLongName in interface IOItemBrowseTreeNode

add

public void add(IOItemBrowseTreeNode aNode)
Append the specified node to the end of this nodes children list

Parameters:
aNode - an IOItemBrowseTreeNode value

getChildAt

public IOItemBrowseTreeNode getChildAt(int index)
Returns the child at the specified index in this node's child array.

Specified by:
getChildAt in interface IOItemBrowseTreeNode
Parameters:
index - an index into this node's child array
Returns:
the IOItemBrowseTreeNode in this node's child array at the specified index
Throws:
ArrayIndexOutOfBoundsException - if index is out of bounds

getChildCount

public int getChildCount()
Returns the number of children of this node.

Specified by:
getChildCount in interface IOItemBrowseTreeNode
Returns:
an int giving the number of children of this node

setParent

public void setParent(IOItemBrowseTreeNode newParent)
Sets this node's parent to newParent but does not change the parent's child array. This method is called from insert() and remove() to reassign a child's parent, it should not be messaged from anywhere else.

Parameters:
newParent - this node's new parent

getParent

public IOItemBrowseTreeNode getParent()
Returns this node's parent or null if this node has no parent.

Specified by:
getParent in interface IOItemBrowseTreeNode
Returns:
this node's parent IOItemBrowseTreeNode, or null if this node has no parent

getIndex

public int getIndex(IOItemBrowseTreeNode aChild)
Returns the index of the specified child in this node's child array. If the specified node is not a child of this node, returns -1. This method performs a linear search and is O(n) where n is the number of children.

Specified by:
getIndex in interface IOItemBrowseTreeNode
Parameters:
aChild - the IOItemBrowseTreeNode to search for among this node's children
Returns:
an int giving the index of the node in this node's child array, or -1 if the specified node is a not a child of this node
Throws:
IllegalArgumentException - if aChild is null

isNodeChild

public boolean isNodeChild(IOItemBrowseTreeNode aNode)
Returns true if aNode is a child of this node. If aNode is null, this method returns false.

Returns:
true if aNode is a child of this node; false if aNode is null

getAllowsChildren

public boolean getAllowsChildren()
Returns true if this node is allowed to have children.

Specified by:
getAllowsChildren in interface IOItemBrowseTreeNode
Returns:
true if this node allows children, else false

isLeaf

public boolean isLeaf()
Returns true if this node has no children. To distinguish between nodes that have no children and nodes that cannot have children (e.g. to distinguish files from empty directories), use this method in conjunction with getAllowsChildren

Specified by:
isLeaf in interface IOItemBrowseTreeNode
Returns:
true if this node has no children
See Also:
getAllowsChildren()

children

public Enumeration children()
Creates and returns a forward-order enumeration of this node's children. Modifying this node's child array invalidates any child enumerations created before the modification.

Specified by:
children in interface IOItemBrowseTreeNode
Returns:
an Enumeration of this node's children

toString

public String toString()
Returns the short name for this object