Class CipPath
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<PathSegment>
-
- com.automation_pros.odva.cip.path.CipPath
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<CipPath>,java.lang.Iterable<PathSegment>,java.util.Collection<PathSegment>,java.util.List<PathSegment>,java.util.RandomAccess
public class CipPath extends java.util.ArrayList<PathSegment> implements java.io.Externalizable, java.lang.Comparable<CipPath>
An ordered list of
Path Segmentsto be used as a locator for CIP objects, data elements, and/or network nodes in the various services in the CIP specification. Instances may be constructed from individual items, collections of items, or string representations of items. UsePathSegment.decodeAll()to construct an instance from encoded bytes.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCipPath.CompositeParserA parser factory for keywords that call multiple other parsers to produces a segment list.protected classCipPath.LockedIteratorprotected classCipPath.LockedListIteratorprotected classCipPath.LockedSpliteratorstatic classCipPath.StaticParserA parser factory for keywords that will simply return a constant path segment.static classCipPath.StaticTypeParserA parser factory for keywords that will return a constant data definition segment.
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatternalignPatternstatic CipPathemptyPathstatic java.lang.StringidentifierCharsstatic java.util.regex.PatternidentifierPatternstatic java.util.Map<java.lang.String,PathTokenParser>keywordsprotected booleanlockedstatic java.util.regex.PatternnonIdentifierCharsstatic org.slf4j.LoggersLoggerstatic java.util.regex.PatterntokenModeIncompatiblestatic java.util.Map<java.lang.String,TypeTokenParser>typewords
-
Constructor Summary
Constructors Constructor Description CipPath()CipPath(int initialCapacity)Construct an empty instance.CipPath(PathSegment... segments)Construct an instance from individual path segments.CipPath(java.util.Collection<? extends PathSegment> segments)Construct an instance from a collection of path segments, in the collection's natural order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, PathSegment element)booleanadd(PathSegment pathSegment)booleanaddAll(int index, java.util.Collection<? extends PathSegment> c)booleanaddAll(java.util.Collection<? extends PathSegment> c)CipPathappend(PathSegment pathSegment)voidclear()static intcompare(java.util.List<PathSegment> path0, java.util.List<PathSegment> path1)Helper function to compare lists of Path Segments, even when not instantiated as a CipPath object.intcompareTo(CipPath path1)static java.nio.ByteBufferdecodeHex(java.lang.String source)static voiddescribe(CipPath p)voidencodeAll(boolean padded, java.nio.ByteBuffer dest)Construct the encoded form of all of the items in this path.static java.lang.StringencodeHex(java.nio.ByteBuffer b)static CipPathfragmentTest(java.lang.String sample)intgetBytes()Compute the total number of bytes in the packed encoding of this path.static PathTokenParsergetKeyword(java.lang.String key)java.util.List<java.lang.String>getTokens()Compute the string tokens that would be needed to regenerate this instance withparse(tokenList).static TypeTokenParsergetTypeword(java.lang.String key)intgetWords()Compute the total number of 16-bit words in the padded encoding of this path.java.lang.StringhexString(boolean padded)Obtain the encoded form of this path as hexadecimal digits, with a single space delimiting segments.java.util.Iterator<PathSegment>iterator()java.util.ListIterator<PathSegment>listIterator()java.util.ListIterator<PathSegment>listIterator(int index)CipPathlock()static voidmain(java.lang.String[] args)static CipPathparse(java.lang.String path)Parse a path string in one of three forms:static CipPathparse(java.util.List<java.lang.String> tokens)Construct a complete path from a list of string tokens and arguments.static CipPathparseTag(java.io.StreamTokenizer st)static CipPathparseTag(java.lang.String path)Decode a string containing a complete human-readable object path.static CipPathparseTest(java.lang.String sample)static DataDefinitionSegparseType(java.lang.String first, java.util.List<java.lang.String> tokens, boolean typeOnly)voidreadExternal(java.io.ObjectInput in)CIP paths are deserialized by retrieving the byte array and decoding it directly.CipPathreDecode(boolean padded)static PathTokenParserregisterKeyword(java.lang.String key, PathTokenParser handler)Register a string parser for a given path keyword.static TypeTokenParserregisterTypeword(java.lang.String key, TypeTokenParser handler)PathSegmentremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveIf(java.util.function.Predicate<? super PathSegment> filter)protected voidremoveRange(int fromIndex, int toIndex)voidreplaceAll(java.util.function.UnaryOperator<PathSegment> operator)static CipPathroute(java.util.List<java.lang.String> tokens)Construct a route path from a list of port & address token pairs.PathSegmentset(int index, PathSegment element)voidsort(java.util.Comparator<? super PathSegment> c)java.util.Spliterator<PathSegment>spliterator()java.lang.StringtokenString()Convenience method to display this instance in token form, possibly not reversibly.java.lang.StringtoString()State machine based encoding of this segment list into a parseable output string.voidwriteExternal(java.io.ObjectOutput out)CIP paths are serialized in padded byte encoded form.-
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, lastIndexOf, retainAll, size, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
keywords
public static final java.util.Map<java.lang.String,PathTokenParser> keywords
-
typewords
public static final java.util.Map<java.lang.String,TypeTokenParser> typewords
-
sLogger
public static final org.slf4j.Logger sLogger
-
emptyPath
public static final CipPath emptyPath
-
identifierPattern
public static final java.util.regex.Pattern identifierPattern
-
alignPattern
public static final java.util.regex.Pattern alignPattern
-
nonIdentifierChars
public static final java.util.regex.Pattern nonIdentifierChars
-
identifierChars
public static final java.lang.String identifierChars
- See Also:
- Constant Field Values
-
tokenModeIncompatible
public static final java.util.regex.Pattern tokenModeIncompatible
-
locked
protected boolean locked
-
-
Constructor Detail
-
CipPath
public CipPath()
-
CipPath
public CipPath(PathSegment... segments)
Construct an instance from individual path segments.- Parameters:
segments- Items to assemble, in order, into the new instance.
-
CipPath
public CipPath(int initialCapacity)
Construct an empty instance.- Parameters:
initialCapacity- The @{link java.util.ArrayList ArrayList} capacity to pass to the superclass.
-
CipPath
public CipPath(java.util.Collection<? extends PathSegment> segments)
Construct an instance from a collection of path segments, in the collection's natural order.- Parameters:
segments- Items to assemble into the new instance.
-
-
Method Detail
-
compare
public static int compare(java.util.List<PathSegment> path0, java.util.List<PathSegment> path1)
Helper function to compare lists of Path Segments, even when not instantiated as a CipPath object.- Parameters:
path0-path1-- Returns:
-
registerKeyword
public static PathTokenParser registerKeyword(java.lang.String key, PathTokenParser handler)
Register a string parser for a given path keyword.
When the path string parser encounters parentheses, square brackets, or curly braces, it switches to keyword mode. All of the text inside the parentheses is tokenized, then passed to successive keyword handlers until all tokens are consumed.
The List<> passed to the handler will be modifiable, and the handler must remove the tokens it consumes. The keyword itself is popped before the handler is called.
- Parameters:
key- The lowercase keyword that triggers this handlerhandler- Object that will process this keyword- Returns:
- The handler previously registered for this keyword, or null.
-
registerTypeword
public static TypeTokenParser registerTypeword(java.lang.String key, TypeTokenParser handler)
-
getKeyword
public static PathTokenParser getKeyword(java.lang.String key)
-
getTypeword
public static TypeTokenParser getTypeword(java.lang.String key)
-
parseType
public static DataDefinitionSeg parseType(java.lang.String first, java.util.List<java.lang.String> tokens, boolean typeOnly)
-
parse
public static CipPath parse(java.util.List<java.lang.String> tokens)
Construct a complete path from a list of string tokens and arguments. Parentheses surround a nested data type definition. Otherwise, a series of data type keywords will be combined into an anonymous structure. Keywords followed by an equals sign become the member name for the data type following the equals.- Parameters:
tokens- String tokens followed by the string arguments they will need. Parentheses, brackets, braces, and equals should be passed as individual tokens.- Returns:
- The path instance.
-
route
public static CipPath route(java.util.List<java.lang.String> tokens)
Construct a route path from a list of port & address token pairs.- Parameters:
tokens- A list of individual tokens containing pairs of arguments for thePort Segmenttoken parser. Basically the same format documented for use in Allen-Bradley Logix Message Instructions' "Connection Path" elements.- Returns:
- A path instance contain only Port Segments.
-
parseTag
public static CipPath parseTag(java.lang.String path)
Decode a string containing a complete human-readable object path.The string must have the following explicit format:
(keyword args... keyword ...)tagpath
The keyword section and the tagpath section are both optional and may be repeated. Any keyword section may include data type definition segments. Data type definitions may include tokens of the form keyname=keyword, which will be interpreted as named members of an implicit, anonymous CIP structure. Nested open parentheses introduce an explicit anonymous CIP structure. Data type definitions may be followed by square-bracketed dimensions, delimited by commas or whitespace.
An empty string yields an empty list of path segments. Whitespace or commas may separate token in a keyword section. Whitespace is not allowed in a tagpath section. In a tagpath section, commas are only allowed separating multiple array subscripts.
The tagpath must follow normal syntax rules for Logix Tag names including structure member names and array subscripts. Tag and structure member names will produce Ansi Symbol segments. Array subscripts will generate Member Logical segments. Trailing bit reference will generate an Extended Logical segment. A nested tagpath may be used as an array subscript and will be wrapped in the appropriate Extended Logical segment.
- Parameters:
path- String containing a generic CIP Path and/or Logix Tag Path- Returns:
- The corresponding path segment objects.
-
parseTag
public static CipPath parseTag(java.io.StreamTokenizer st)
-
decodeHex
public static java.nio.ByteBuffer decodeHex(java.lang.String source)
-
encodeHex
public static java.lang.String encodeHex(java.nio.ByteBuffer b)
-
parse
public static CipPath parse(java.lang.String path)
Parse a path string in one of three forms:
- A tagpath with optional braced/bracketed/parenthesized token string as described for parseTag(),
- A token string, or
- A packed or padded hexadecimal byte string, as found in electronic data sheets. If a hex string but not decodable, the problem will be reported from the padded encoding perspective.
- Parameters:
path- The string to parse for a path- Returns:
-
lock
public CipPath lock()
-
set
public PathSegment set(int index, PathSegment element)
- Specified by:
setin interfacejava.util.List<PathSegment>- Overrides:
setin classjava.util.ArrayList<PathSegment>
-
add
public boolean add(PathSegment pathSegment)
- Specified by:
addin interfacejava.util.Collection<PathSegment>- Specified by:
addin interfacejava.util.List<PathSegment>- Overrides:
addin classjava.util.ArrayList<PathSegment>
-
append
public CipPath append(PathSegment pathSegment)
-
add
public void add(int index, PathSegment element)- Specified by:
addin interfacejava.util.List<PathSegment>- Overrides:
addin classjava.util.ArrayList<PathSegment>
-
remove
public PathSegment remove(int index)
- Specified by:
removein interfacejava.util.List<PathSegment>- Overrides:
removein classjava.util.ArrayList<PathSegment>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<PathSegment>- Specified by:
removein interfacejava.util.List<PathSegment>- Overrides:
removein classjava.util.ArrayList<PathSegment>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<PathSegment>- Specified by:
clearin interfacejava.util.List<PathSegment>- Overrides:
clearin classjava.util.ArrayList<PathSegment>
-
addAll
public boolean addAll(java.util.Collection<? extends PathSegment> c)
- Specified by:
addAllin interfacejava.util.Collection<PathSegment>- Specified by:
addAllin interfacejava.util.List<PathSegment>- Overrides:
addAllin classjava.util.ArrayList<PathSegment>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends PathSegment> c)- Specified by:
addAllin interfacejava.util.List<PathSegment>- Overrides:
addAllin classjava.util.ArrayList<PathSegment>
-
removeRange
protected void removeRange(int fromIndex, int toIndex)- Overrides:
removeRangein classjava.util.ArrayList<PathSegment>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<PathSegment>- Specified by:
removeAllin interfacejava.util.List<PathSegment>- Overrides:
removeAllin classjava.util.ArrayList<PathSegment>
-
listIterator
public java.util.ListIterator<PathSegment> listIterator(int index)
- Specified by:
listIteratorin interfacejava.util.List<PathSegment>- Overrides:
listIteratorin classjava.util.ArrayList<PathSegment>
-
listIterator
public java.util.ListIterator<PathSegment> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<PathSegment>- Overrides:
listIteratorin classjava.util.ArrayList<PathSegment>
-
iterator
public java.util.Iterator<PathSegment> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<PathSegment>- Specified by:
iteratorin interfacejava.lang.Iterable<PathSegment>- Specified by:
iteratorin interfacejava.util.List<PathSegment>- Overrides:
iteratorin classjava.util.ArrayList<PathSegment>
-
spliterator
public java.util.Spliterator<PathSegment> spliterator()
- Specified by:
spliteratorin interfacejava.util.Collection<PathSegment>- Specified by:
spliteratorin interfacejava.lang.Iterable<PathSegment>- Specified by:
spliteratorin interfacejava.util.List<PathSegment>- Overrides:
spliteratorin classjava.util.ArrayList<PathSegment>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super PathSegment> filter)
- Specified by:
removeIfin interfacejava.util.Collection<PathSegment>- Overrides:
removeIfin classjava.util.ArrayList<PathSegment>
-
replaceAll
public void replaceAll(java.util.function.UnaryOperator<PathSegment> operator)
- Specified by:
replaceAllin interfacejava.util.List<PathSegment>- Overrides:
replaceAllin classjava.util.ArrayList<PathSegment>
-
sort
public void sort(java.util.Comparator<? super PathSegment> c)
- Specified by:
sortin interfacejava.util.List<PathSegment>- Overrides:
sortin classjava.util.ArrayList<PathSegment>
-
getBytes
public int getBytes()
Compute the total number of bytes in the packed encoding of this path.- Returns:
- Number of bytes.
-
getWords
public int getWords()
Compute the total number of 16-bit words in the padded encoding of this path. Multiply by two for the byte length.- Returns:
-
encodeAll
public void encodeAll(boolean padded, java.nio.ByteBuffer dest)Construct the encoded form of all of the items in this path. Does not include any length element.- Parameters:
padded- Format flag, true for padded, false for packed.dest- Buffer to receive the encoded form.
-
reDecode
public CipPath reDecode(boolean padded)
-
getTokens
public java.util.List<java.lang.String> getTokens()
Compute the string tokens that would be needed to regenerate this instance withparse(tokenList).- Returns:
- A list of string tokens.
-
tokenString
public java.lang.String tokenString()
Convenience method to display this instance in token form, possibly not reversibly. Tokens are joined with spaces when- either token is quoted, or
- to prevent identifier merging, or
- to delimit an identifier character from an open parenthesis.
- Returns:
- A human-readable version of the path's items.
-
hexString
public java.lang.String hexString(boolean padded)
Obtain the encoded form of this path as hexadecimal digits, with a single space delimiting segments.- Parameters:
padded- Whether to encode the path into bytes in padded form.- Returns:
- The hexadecimal string form of the selected encoding.
-
toString
public java.lang.String toString()
State machine based encoding of this segment list into a parseable output string.A symbol segment always switches out of token mode.
State 0 = prior was tokens State 1 = prior was symbol State 2 = prior was subscript State 3 = prior was bit
- Overrides:
toStringin classjava.util.AbstractCollection<PathSegment>
-
compareTo
public int compareTo(CipPath path1)
- Specified by:
compareToin interfacejava.lang.Comparable<CipPath>
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionCIP paths are deserialized by retrieving the byte array and decoding it directly.- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionCIP paths are serialized in padded byte encoded form.- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
describe
public static void describe(CipPath p)
-
fragmentTest
public static CipPath fragmentTest(java.lang.String sample)
-
parseTest
public static CipPath parseTest(java.lang.String sample)
-
main
public static void main(java.lang.String[] args)
-
-