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 Segments
to 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 class
CipPath.CompositeParser
A parser factory for keywords that call multiple other parsers to produces a segment list.protected class
CipPath.LockedIterator
protected class
CipPath.LockedListIterator
protected class
CipPath.LockedSpliterator
static class
CipPath.StaticParser
A parser factory for keywords that will simply return a constant path segment.static class
CipPath.StaticTypeParser
A parser factory for keywords that will return a constant data definition segment.
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
alignPattern
static CipPath
emptyPath
static java.lang.String
identifierChars
static java.util.regex.Pattern
identifierPattern
static java.util.Map<java.lang.String,PathTokenParser>
keywords
protected boolean
locked
static java.util.regex.Pattern
nonIdentifierChars
static org.slf4j.Logger
sLogger
static java.util.regex.Pattern
tokenModeIncompatible
static 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 void
add(int index, PathSegment element)
boolean
add(PathSegment pathSegment)
boolean
addAll(int index, java.util.Collection<? extends PathSegment> c)
boolean
addAll(java.util.Collection<? extends PathSegment> c)
CipPath
append(PathSegment pathSegment)
void
clear()
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.int
compareTo(CipPath path1)
static java.nio.ByteBuffer
decodeHex(java.lang.String source)
static void
describe(CipPath p)
void
encodeAll(boolean padded, java.nio.ByteBuffer dest)
Construct the encoded form of all of the items in this path.static java.lang.String
encodeHex(java.nio.ByteBuffer b)
static CipPath
fragmentTest(java.lang.String sample)
int
getBytes()
Compute the total number of bytes in the packed encoding of this path.static PathTokenParser
getKeyword(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 TypeTokenParser
getTypeword(java.lang.String key)
int
getWords()
Compute the total number of 16-bit words in the padded encoding of this path.java.lang.String
hexString(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)
CipPath
lock()
static void
main(java.lang.String[] args)
static CipPath
parse(java.lang.String path)
Parse a path string in one of three forms:static CipPath
parse(java.util.List<java.lang.String> tokens)
Construct a complete path from a list of string tokens and arguments.static CipPath
parseTag(java.io.StreamTokenizer st)
static CipPath
parseTag(java.lang.String path)
Decode a string containing a complete human-readable object path.static CipPath
parseTest(java.lang.String sample)
static DataDefinitionSeg
parseType(java.lang.String first, java.util.List<java.lang.String> tokens, boolean typeOnly)
void
readExternal(java.io.ObjectInput in)
CIP paths are deserialized by retrieving the byte array and decoding it directly.CipPath
reDecode(boolean padded)
static PathTokenParser
registerKeyword(java.lang.String key, PathTokenParser handler)
Register a string parser for a given path keyword.static TypeTokenParser
registerTypeword(java.lang.String key, TypeTokenParser handler)
PathSegment
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
removeIf(java.util.function.Predicate<? super PathSegment> filter)
protected void
removeRange(int fromIndex, int toIndex)
void
replaceAll(java.util.function.UnaryOperator<PathSegment> operator)
static CipPath
route(java.util.List<java.lang.String> tokens)
Construct a route path from a list of port & address token pairs.PathSegment
set(int index, PathSegment element)
void
sort(java.util.Comparator<? super PathSegment> c)
java.util.Spliterator<PathSegment>
spliterator()
java.lang.String
tokenString()
Convenience method to display this instance in token form, possibly not reversibly.java.lang.String
toString()
State machine based encoding of this segment list into a parseable output string.void
writeExternal(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 Segment
token 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:
set
in interfacejava.util.List<PathSegment>
- Overrides:
set
in classjava.util.ArrayList<PathSegment>
-
add
public boolean add(PathSegment pathSegment)
- Specified by:
add
in interfacejava.util.Collection<PathSegment>
- Specified by:
add
in interfacejava.util.List<PathSegment>
- Overrides:
add
in classjava.util.ArrayList<PathSegment>
-
append
public CipPath append(PathSegment pathSegment)
-
add
public void add(int index, PathSegment element)
- Specified by:
add
in interfacejava.util.List<PathSegment>
- Overrides:
add
in classjava.util.ArrayList<PathSegment>
-
remove
public PathSegment remove(int index)
- Specified by:
remove
in interfacejava.util.List<PathSegment>
- Overrides:
remove
in classjava.util.ArrayList<PathSegment>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<PathSegment>
- Specified by:
remove
in interfacejava.util.List<PathSegment>
- Overrides:
remove
in classjava.util.ArrayList<PathSegment>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<PathSegment>
- Specified by:
clear
in interfacejava.util.List<PathSegment>
- Overrides:
clear
in classjava.util.ArrayList<PathSegment>
-
addAll
public boolean addAll(java.util.Collection<? extends PathSegment> c)
- Specified by:
addAll
in interfacejava.util.Collection<PathSegment>
- Specified by:
addAll
in interfacejava.util.List<PathSegment>
- Overrides:
addAll
in classjava.util.ArrayList<PathSegment>
-
addAll
public boolean addAll(int index, java.util.Collection<? extends PathSegment> c)
- Specified by:
addAll
in interfacejava.util.List<PathSegment>
- Overrides:
addAll
in classjava.util.ArrayList<PathSegment>
-
removeRange
protected void removeRange(int fromIndex, int toIndex)
- Overrides:
removeRange
in classjava.util.ArrayList<PathSegment>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<PathSegment>
- Specified by:
removeAll
in interfacejava.util.List<PathSegment>
- Overrides:
removeAll
in classjava.util.ArrayList<PathSegment>
-
listIterator
public java.util.ListIterator<PathSegment> listIterator(int index)
- Specified by:
listIterator
in interfacejava.util.List<PathSegment>
- Overrides:
listIterator
in classjava.util.ArrayList<PathSegment>
-
listIterator
public java.util.ListIterator<PathSegment> listIterator()
- Specified by:
listIterator
in interfacejava.util.List<PathSegment>
- Overrides:
listIterator
in classjava.util.ArrayList<PathSegment>
-
iterator
public java.util.Iterator<PathSegment> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<PathSegment>
- Specified by:
iterator
in interfacejava.lang.Iterable<PathSegment>
- Specified by:
iterator
in interfacejava.util.List<PathSegment>
- Overrides:
iterator
in classjava.util.ArrayList<PathSegment>
-
spliterator
public java.util.Spliterator<PathSegment> spliterator()
- Specified by:
spliterator
in interfacejava.util.Collection<PathSegment>
- Specified by:
spliterator
in interfacejava.lang.Iterable<PathSegment>
- Specified by:
spliterator
in interfacejava.util.List<PathSegment>
- Overrides:
spliterator
in classjava.util.ArrayList<PathSegment>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super PathSegment> filter)
- Specified by:
removeIf
in interfacejava.util.Collection<PathSegment>
- Overrides:
removeIf
in classjava.util.ArrayList<PathSegment>
-
replaceAll
public void replaceAll(java.util.function.UnaryOperator<PathSegment> operator)
- Specified by:
replaceAll
in interfacejava.util.List<PathSegment>
- Overrides:
replaceAll
in classjava.util.ArrayList<PathSegment>
-
sort
public void sort(java.util.Comparator<? super PathSegment> c)
- Specified by:
sort
in interfacejava.util.List<PathSegment>
- Overrides:
sort
in 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:
toString
in classjava.util.AbstractCollection<PathSegment>
-
compareTo
public int compareTo(CipPath path1)
- Specified by:
compareTo
in interfacejava.lang.Comparable<CipPath>
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
CIP paths are deserialized by retrieving the byte array and decoding it directly.- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
CIP paths are serialized in padded byte encoded form.- Specified by:
writeExternal
in 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)
-
-