Class CipTree
- java.lang.Object
-
- com.automation_pros.odva.cip.types.CipTree
-
- Direct Known Subclasses:
CipTreeCtx
public class CipTree extends java.lang.Object
Implement a Hierarchy of objects where children know their parent and children are "named" by a single CIP Path Segment. Access to children is thread-safe without synchronization.Subclasses, like CipObject, provide all other functionality.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
CipTree.ChildMap
Children of each element of the hierarchy can have complex life cycles where removal from the tree requires a cleanup action.
-
Field Summary
Fields Modifier and Type Field Description protected CipTree.ChildMap
children
protected CipPath
objEPath
protected CipTree
parent
protected PathSegment
segment
-
Constructor Summary
Constructors Constructor Description CipTree()
CipTree(PathSegment seg)
CipTree(PathSegment seg, CipTree parent)
CipTree(CipTree parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cleanup(CipTree oldParent, CipTree replacement)
When an element is removed from a parent's map of children, the element is notified by this method, which is given the prior parent element, and the replacement element (if known).java.util.Set<java.util.Map.Entry<PathSegment,CipTree>>
entrySet()
CipTree
follow(java.util.List<PathSegment> path)
Follow a path to the given descendant.CipTree
getChild(PathSegment seg)
Lookup a child for a particular segment.java.util.List<CipTree>
getChildren()
CipPath
getEPath()
Retrieve the application path that leads to this object starting at the device.protected CipPath
getEPathImpl()
Retrieve the application path that leads to this object starting at the root (no parent).CipTree
getParent()
PathSegment
getSegment()
java.util.Set<PathSegment>
keySet()
boolean
removeChild(CipTree child, PathSegment seg)
Conditionally remove a particular Segment from the children map if it currently points to the given child.CipTree
setChild(CipTree child, PathSegment seg)
Assign a given CipTree as a child of this CipTree identified by a specific PathSegment.CipTree
setParent(CipTree parent)
Set or remove the parent of this CipTree, possibly removing this object from a previous parent before assigning to the new parent.CipTree
setSegment(PathSegment segment)
java.lang.String
toString()
-
-
-
Field Detail
-
parent
protected CipTree parent
-
segment
protected PathSegment segment
-
children
protected CipTree.ChildMap children
-
objEPath
protected CipPath objEPath
-
-
Constructor Detail
-
CipTree
public CipTree()
-
CipTree
public CipTree(PathSegment seg)
-
CipTree
public CipTree(CipTree parent)
-
CipTree
public CipTree(PathSegment seg, CipTree parent)
-
-
Method Detail
-
getEPathImpl
protected CipPath getEPathImpl()
Retrieve the application path that leads to this object starting at the root (no parent). Will be called by getEPath() and the result cached by default.Root elements must override this to return an empty CipPath.
- Returns:
-
getEPath
public CipPath getEPath()
Retrieve the application path that leads to this object starting at the device.- Returns:
-
cleanup
protected void cleanup(CipTree oldParent, CipTree replacement)
When an element is removed from a parent's map of children, the element is notified by this method, which is given the prior parent element, and the replacement element (if known).- Parameters:
oldParent
-replacement
-
-
setChild
public CipTree setChild(CipTree child, PathSegment seg)
Assign a given CipTree as a child of this CipTree identified by a specific PathSegment. If that path segment is already registered to a different child CipTree, replace it and return that old child.- Parameters:
child
- The CipTree to register.seg
- The Path Segment that identifies this child.- Returns:
- The replaced CipTree, if any.
-
removeChild
public boolean removeChild(CipTree child, PathSegment seg)
Conditionally remove a particular Segment from the children map if it currently points to the given child.- Parameters:
child
- The CipTree to remove.seg
- The segment that identifies the child.
-
getChild
public CipTree getChild(PathSegment seg)
Lookup a child for a particular segment.- Parameters:
seg
-- Returns:
-
getChildren
public java.util.List<CipTree> getChildren()
-
entrySet
public java.util.Set<java.util.Map.Entry<PathSegment,CipTree>> entrySet()
-
keySet
public java.util.Set<PathSegment> keySet()
-
follow
public CipTree follow(java.util.List<PathSegment> path)
Follow a path to the given descendant. If the path cannot be completely followed, throw an exception containing the last CipTree found and the remaining path.
-
getParent
public CipTree getParent()
-
setParent
public CipTree setParent(CipTree parent)
Set or remove the parent of this CipTree, possibly removing this object from a previous parent before assigning to the new parent. Override this method if additional housekeeping is required when assigning or removing parents.- Parameters:
parent
- The new parent of this object.- Returns:
- The object replaced by this object in the parent, if any.
-
getSegment
public PathSegment getSegment()
-
setSegment
public CipTree setSegment(PathSegment segment)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-