public class ScanWriteUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ScanWriteUtils.ClassInfo<C> |
Modifier and Type | Field and Description |
---|---|
static boolean |
connectAfterScanning |
Constructor and Description |
---|
ScanWriteUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getClassTag(Scannable comp) |
static java.lang.String |
getParameterizedClassTag(Scannable comp,
java.lang.Class<?> typeParam) |
static boolean |
getTokenPrinting()
Returns
true if token printing is enabled in the
scanfull() method. |
static <C> C |
newComponent(ReaderTokenizer rtok,
ScanWriteUtils.ClassInfo<C> cinfo,
boolean warnOnly)
Used for scanning: calls createComponent() and throws an appropriate
IOException if anything goes wrong.
|
static boolean |
postscanAttributeName(java.util.Deque<ScanToken> tokens,
java.lang.String name)
Checks if the next token in the queue is a StringToken
containing the specified name.
|
static void |
postscanBeginToken(java.util.Deque<ScanToken> tokens,
java.lang.Object comp)
Checks if the next token in the queue is a BEGIN token,
and if so, consumes it.
|
static <C> C |
postscanComponent(java.util.Deque<ScanToken> tokens,
java.lang.Class<C> clazz,
CompositeComponent ancestor)
Calls
postscan() for an component stored in the token queue. |
static boolean |
postscanComponent(java.util.Deque<ScanToken> tokens,
CompositeComponent ancestor)
Checks if the next token on the queue is an ObjectToken
holding a component reference.
|
static boolean |
postscanComponent(java.util.Deque<ScanToken> tokens,
java.lang.String name,
CompositeComponent ancestor)
Checks if the next token on the queue is a StringToken matching a
specific attribute name.
|
static ScanToken |
postscanComponentToken(java.util.Deque<ScanToken> tokens)
Checks if the next token on the queue is an ObjectToken
holding a component reference.
|
static void |
postscanEndToken(java.util.Deque<ScanToken> tokens,
java.lang.Object comp)
Checks if the next token in the queue is an END token,
and if so, consumes it.
|
static java.util.ArrayList<Property> |
postscanProperties(java.util.Deque<ScanToken> tokens,
CompositeComponent ancestor)
Checks that the next set of tokens in the stream consist of
a BEGIN token, a set of property paths, and an END token.
|
static Property |
postscanProperty(java.util.Deque<ScanToken> tokens,
CompositeComponent ancestor)
Removes the next token from the queue, checks that it is a StringToken
containing a property path relative to
ancestor , and locates
and returns the property. |
static boolean |
postscanPropertyValue(java.util.Deque<ScanToken> tokens,
CompositeComponent ancestor)
Checks if the next token in the queue is a PropertyToken
containing a property and value.
|
static <C> C |
postscanReference(java.util.Deque<ScanToken> tokens,
java.lang.Class<C> clazz,
CompositeComponent ancestor)
Removes the next token from the queue, checks that it is a StringToken
containing a reference path relative to
ancestor , locates
the referenced component, verifies that it is an instance of
clazz , and returns it. |
static <C> C |
postscanReference(StringToken strtok,
java.lang.Class<C> clazz,
CompositeComponent ancestor) |
static <C> C[] |
postscanReferences(java.util.Deque<ScanToken> tokens,
java.lang.Class<C> clazz,
CompositeComponent ancestor)
Checks that the next set of tokens in the stream consist of
a BEGIN token, a set of reference path names, and an END token.
|
static <C> void |
postscanReferences(java.util.Deque<ScanToken> tokens,
java.util.Collection<C> refs,
java.lang.Class<C> clazz,
CompositeComponent ancestor)
Checks that the next set of tokens in the stream consist of
a BEGIN token, a set of reference path names, and an END token.
|
static void |
printTokens(java.util.Deque<ScanToken> tokens)
Diagnostic method to print a token queue to the standard
output stream.
|
static void |
printTokens(java.io.PrintWriter pw,
java.util.Deque<ScanToken> tokens)
Diagnostic method to print a token queue to a print writer.
|
static void |
recursivelyConnectComponents(ModelComponent comp) |
static void |
scanAndDiscard(ReaderTokenizer rtok)
Scans and discards the input associated with a component, which is
assumed to be enclosed within square brackets.
|
static boolean |
scanAndStoreComponent(ReaderTokenizer rtok,
java.lang.String name,
java.util.Deque<ScanToken> tokens)
Attempts to scan a class-qualified component associated with a given
attribute name.
|
static void |
scanAndStorePropertyPath(ReaderTokenizer rtok,
java.util.Deque<ScanToken> tokens)
If the next input token is a quoted string or word, then assume that
it corresponds to property path, store its value
in the token queue as a
StringToken , and return
true . |
static boolean |
scanAndStorePropertyPath(ReaderTokenizer rtok,
java.lang.String name,
java.util.Deque<ScanToken> tokens)
Attempts to scan a property path associated with a given attribute name.
|
static int |
scanAndStorePropertyPaths(ReaderTokenizer rtok,
java.util.Deque<ScanToken> tokens)
Assumes that the next set of input tokens are a set of property
paths enclosed between square brackets.
|
static int |
scanAndStorePropertyPaths(ReaderTokenizer rtok,
java.lang.String name,
java.util.Deque<ScanToken> tokens)
Attempts to scan a set of property paths associated with a given attribute
name.
|
static boolean |
scanAndStorePropertyValue(ReaderTokenizer rtok,
HasProperties host,
java.lang.String propName,
java.util.Deque<ScanToken> tokens)
Attempts to scan and store a specific property value for a specified
host.
|
static boolean |
scanAndStorePropertyValues(ReaderTokenizer rtok,
HasProperties host,
java.lang.String[] propNames,
java.util.Deque<ScanToken> tokens)
Attempts to scan and store a specific set of property values
for a specified host.
|
static boolean |
scanAndStoreReference(ReaderTokenizer rtok,
java.util.Deque<ScanToken> tokens)
If the next input token is a quoted string or word, then assume that
it corresponds to component reference path, store its value
in the token queue as a
StringToken , and return
true . |
static boolean |
scanAndStoreReference(ReaderTokenizer rtok,
java.lang.String name,
java.util.Deque<ScanToken> tokens)
Attempts to scan a reference path associated with a given attribute name.
|
static int |
scanAndStoreReferences(ReaderTokenizer rtok,
java.util.Deque<ScanToken> tokens)
Assumes that the next set of input tokens are a set of component
reference paths enclosed between square brackets.
|
static int |
scanAndStoreReferences(ReaderTokenizer rtok,
java.lang.String name,
java.util.Deque<ScanToken> tokens)
Attempts to scan a set of reference paths associated with a given
attribute name.
|
static boolean |
scanAttributeName(ReaderTokenizer rtok,
java.lang.String name) |
static <C> ScanWriteUtils.ClassInfo<C> |
scanClassInfo(ReaderTokenizer rtok,
java.lang.Class<C> baseClass)
Scans a class tag that either consists of a simple class
name or alias, such as
ModelComponent , or a parameterized
class name, such as ModelList<FemModel3d> , and returns
the associated class information. |
static void |
scanComponentsAndWeights(ReaderTokenizer rtok,
java.util.Deque<ScanToken> tokens) |
static void |
scanfull(ReaderTokenizer rtok,
ModelComponent comp,
CompositeComponent ancestor)
Performs both a scan and a postscan for a specific component.
|
static boolean |
scanProperty(ReaderTokenizer rtok,
HasProperties host,
java.util.Deque<ScanToken> tokens)
Attempts to scan and set a property value for a specified host.
|
static PropertyToken |
scanPropertyToken(ReaderTokenizer rtok,
HasProperties host,
java.lang.String propName)
Scans a specific property value for a host, ecapsulated inside a
PropertyToken, assuming that the property name has already been scanned
and matched.
|
static Vector3d[] |
scanVector3dList(ReaderTokenizer rtok) |
static void |
setTokenPrinting(boolean enable)
Debugging hook to enable printing of the token queue produced
in the
scanfull() method, before postscan()
is called. |
static void |
writeBracketedReferences(java.io.PrintWriter pw,
java.util.Collection<? extends ModelComponent> comps,
CompositeComponent ancestor)
Writes the reference paths for a set of components to a
print writer, enclosed by square brackets.
|
static void |
writeComponent(java.io.PrintWriter pw,
NumberFormat fmt,
Scannable obj,
java.lang.Object ref)
Writes a class-qualified component to a print writer.
|
static void |
writeComponentsAndWeights(java.io.PrintWriter pw,
NumberFormat fmt,
ModelComponent[] comps,
double[] weights,
java.lang.Object ref) |
static void |
writeReferences(java.io.PrintWriter pw,
java.lang.Iterable<ModelComponent> comps,
CompositeComponent ancestor)
Writes the reference paths for a set of components to a
print writer.
|
static void |
writeVector3dList(java.io.PrintWriter pw,
NumberFormat fmt,
Vector3d[] list) |
public static void setTokenPrinting(boolean enable)
scanfull()
method, before postscan()
is called.enable
- if true
, enables token printing.public static boolean getTokenPrinting()
true
if token printing is enabled in the
scanfull()
method.true
if token printing is enabled in
scan()
public static boolean scanAndStoreReference(ReaderTokenizer rtok, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StringToken
, and return
true
.rtok
- input token streamtokens
- token queue for postscantrue
if reference path is scanned and stored
in the queue as a StringToken
java.io.IOException
- if an I/O or syntax error occurredpublic static int scanAndStoreReferences(ReaderTokenizer rtok, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StringTokens
, and return the number
of reference paths found.rtok
- input token streamtokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean scanAttributeName(ReaderTokenizer rtok, java.lang.String name) throws java.io.IOException
java.io.IOException
public static void scanAndStorePropertyPath(ReaderTokenizer rtok, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StringToken
, and return
true
.rtok
- input token streamtokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static int scanAndStorePropertyPaths(ReaderTokenizer rtok, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StringTokens
, and return the number
of paths found.rtok
- input token streamtokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean scanAndStoreReference(ReaderTokenizer rtok, java.lang.String name, java.util.Deque<ScanToken> tokens) throws java.io.IOException
true
.
Otherwise, returns false
.rtok
- input token streamname
- attribute nametokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static int scanAndStoreReferences(ReaderTokenizer rtok, java.lang.String name, java.util.Deque<ScanToken> tokens) throws java.io.IOException
rtok
- input token streamname
- attribute nametokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean scanAndStorePropertyPath(ReaderTokenizer rtok, java.lang.String name, java.util.Deque<ScanToken> tokens) throws java.io.IOException
true
.
Otherwise, return false
.rtok
- input token streamname
- attribute nametokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static int scanAndStorePropertyPaths(ReaderTokenizer rtok, java.lang.String name, java.util.Deque<ScanToken> tokens) throws java.io.IOException
true
.
Otherwise, return false
.rtok
- input token streamname
- attribute nametokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean postscanAttributeName(java.util.Deque<ScanToken> tokens, java.lang.String name)
true
. Otherwise, returns false
.tokens
- queue of stored tokensname
- name to check on the token queuetrue
if the next token is a StringToken containing
name
.public static void postscanBeginToken(java.util.Deque<ScanToken> tokens, java.lang.Object comp) throws java.io.IOException
tokens
- queue of stored tokenscomp
- object or component associated with the BEGINjava.io.IOException
- if an I/O or syntax error occurredpublic static void postscanEndToken(java.util.Deque<ScanToken> tokens, java.lang.Object comp) throws java.io.IOException
tokens
- queue of stored tokenscomp
- object or component associated with the ENDjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean postscanComponent(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor) throws java.io.IOException
true
.
Otherwise, returns false
.tokens
- queue of stored tokensancestor
- ancestor for evaluating reference pathsjava.io.IOException
- if unexpected token input was encounteredpublic static boolean postscanComponent(java.util.Deque<ScanToken> tokens, java.lang.String name, CompositeComponent ancestor) throws java.io.IOException
tokens
- queue of stored tokensname
- attribute nameancestor
- ancestor for evaluating reference pathsjava.io.IOException
- if unexpected token input was encounteredpublic static ScanToken postscanComponentToken(java.util.Deque<ScanToken> tokens) throws java.io.IOException
null
.tokens
- queue of stored tokensnull
.java.io.IOException
- if unexpected token input was encounteredpublic static <C> C postscanReference(StringToken strtok, java.lang.Class<C> clazz, CompositeComponent ancestor) throws java.io.IOException
java.io.IOException
public static <C> C postscanReference(java.util.Deque<ScanToken> tokens, java.lang.Class<C> clazz, CompositeComponent ancestor) throws java.io.IOException
ancestor
, locates
the referenced component, verifies that it is an instance of
clazz
, and returns it.tokens
- queue of stored tokensclazz
- class that the referenced component must be an instance ofancestor
- ancestor for the reference pathjava.io.IOException
- if the next token is not a StringToken or
if the reference cannot be foundpublic static <C> C[] postscanReferences(java.util.Deque<ScanToken> tokens, java.lang.Class<C> clazz, CompositeComponent ancestor) throws java.io.IOException
ancestor
, type checked to ensure that they are
instances of clazz
, and then returned as an array.tokens
- queue of stored tokensclazz
- class that each referenced component must be an instance ofancestor
- ancestor for the reference pathjava.io.IOException
- if the token structure is incorrect or if
the referenced components cannot be found.public static <C> void postscanReferences(java.util.Deque<ScanToken> tokens, java.util.Collection<C> refs, java.lang.Class<C> clazz, CompositeComponent ancestor) throws java.io.IOException
ancestor
, type checked to ensure that they are
instances of clazz
, and then returned in
the collection refs
.tokens
- queue of stored tokensrefs
- returns the component referencesclazz
- class that each referenced component must be an instance ofancestor
- ancestor for the reference pathjava.io.IOException
- if the token structure is incorrect or if
the referenced components cannot be found.public static Property postscanProperty(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor) throws java.io.IOException
ancestor
, and locates
and returns the property.tokens
- queue of stored tokensancestor
- ancestor for the property pathjava.io.IOException
- if the next token is not a StringToken or
if the property cannot be foundpublic static java.util.ArrayList<Property> postscanProperties(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor) throws java.io.IOException
ancestor
and returned in an ArrayList.tokens
- queue of stored tokensancestor
- ancestor for the reference pathjava.io.IOException
- if the token structure is incorrect or if
the properties cannot be foundpublic static void scanfull(ReaderTokenizer rtok, ModelComponent comp, CompositeComponent ancestor) throws java.io.IOException
rtok
- input token streamcomp
- component to scanancestor
- ancestor component for resolving referencesjava.io.IOException
- if an I/O or syntax error occurredpublic static void recursivelyConnectComponents(ModelComponent comp) throws java.io.IOException
java.io.IOException
public static void scanAndDiscard(ReaderTokenizer rtok) throws java.io.IOException
rtok
- input token streamjava.io.IOException
public static void printTokens(java.util.Deque<ScanToken> tokens)
tokens
- token queue to be printedpublic static void printTokens(java.io.PrintWriter pw, java.util.Deque<ScanToken> tokens)
pw
- print writer for printing the token queuetokens
- token queue to be printedpublic static boolean scanProperty(ReaderTokenizer rtok, HasProperties host, java.util.Deque<ScanToken> tokens) throws java.io.IOException
true
.
Otherwise, return false
.rtok
- input token streamhost
- host containing the propertytokens
- token deque for postscanningtrue
if a property was matched and scannedjava.io.IOException
- if an I/O or syntax error occurredpublic static PropertyToken scanPropertyToken(ReaderTokenizer rtok, HasProperties host, java.lang.String propName) throws java.io.IOException
rtok
- input token streamhost
- host containing the propertypropName
- property to try and scanjava.io.IOException
- if an I/O or syntax error occurredpublic static boolean scanAndStorePropertyValues(ReaderTokenizer rtok, HasProperties host, java.lang.String[] propNames, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StrinToken
and an ObjectToken
,
and return true
.
Otherwise, return false
.
This method is intended for handling property values which must be set in the post-scan stage after references have been set.
rtok
- input token streamhost
- host containing the propertiespropNames
- names of properties to matchtokens
- token queue for postscantrue
if a property value was scanned
and stored.java.io.IOException
- if an I/O or syntax error occurredpublic static boolean scanAndStorePropertyValue(ReaderTokenizer rtok, HasProperties host, java.lang.String propName, java.util.Deque<ScanToken> tokens) throws java.io.IOException
StringToken
and an ObjectToken
, and return
true
. Otherwise, return false
.
This method is intended for handling property values which must be set in the post-scan stage after references have been set.
rtok
- input token streamhost
- host containing the propertiespropName
- name of the property to matchtokens
- token queue for postscantrue
if z roperty value was scanned
and stored.java.io.IOException
- if an I/O or syntax error occurredpublic static boolean postscanPropertyValue(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor) throws java.io.IOException
true
.
Otherwise, returns false
.tokens
- queue of stored tokensancestor
- ancestor component with respect to which reference
paths should be generatedtrue
if a property token was foundjava.io.IOException
- if an I/O or syntax error occurredpublic static void writeBracketedReferences(java.io.PrintWriter pw, java.util.Collection<? extends ModelComponent> comps, CompositeComponent ancestor) throws java.io.IOException
pw
- PrintWriter to write the references tocomps
- components providing the reference pathsancestor
- ancestor component with respect to which reference
paths should be generatedjava.io.IOException
public static void writeReferences(java.io.PrintWriter pw, java.lang.Iterable<ModelComponent> comps, CompositeComponent ancestor) throws java.io.IOException
writeBracketedReferences()
, the paths are not enclosed
within square brackets.pw
- PrintWriter to write the references tocomps
- components providing the reference pathsancestor
- ancestor component with respect to which reference
paths should be generatedjava.io.IOException
public static boolean scanAndStoreComponent(ReaderTokenizer rtok, java.lang.String name, java.util.Deque<ScanToken> tokens) throws java.io.IOException
true
. Otherwise, returns false
.rtok
- input token streamname
- attribute nametokens
- token storage queue for postscanjava.io.IOException
- if an I/O or syntax error occurredpublic static <C> C postscanComponent(java.util.Deque<ScanToken> tokens, java.lang.Class<C> clazz, CompositeComponent ancestor) throws java.io.IOException
postscan()
for an component stored in the token queue.
Removes the next token from the queue, checks that it is an ObjectToken
containing an component, verifies that the component it is an instance of
clazz
, calls postscan()
for the component and
returns it.tokens
- queue of stored tokensclazz
- class that the component must be an instance ofancestor
- ancestor uses for post-scanning the componentjava.io.IOException
- if the next token is not an ObjectToken, the component
is not an instance of clazz
, or an error occured within the
component's postscan()
call.public static void writeComponent(java.io.PrintWriter pw, NumberFormat fmt, Scannable obj, java.lang.Object ref) throws java.io.IOException
pw
- PrintWriter to write the component tofmt
- numeric format for writing the componentobj
- component to be writtenref
- reference object used for writing the componentjava.io.IOException
public static void writeVector3dList(java.io.PrintWriter pw, NumberFormat fmt, Vector3d[] list) throws java.io.IOException
java.io.IOException
public static Vector3d[] scanVector3dList(ReaderTokenizer rtok) throws java.io.IOException
java.io.IOException
public static void scanComponentsAndWeights(ReaderTokenizer rtok, java.util.Deque<ScanToken> tokens) throws java.io.IOException
java.io.IOException
public static void writeComponentsAndWeights(java.io.PrintWriter pw, NumberFormat fmt, ModelComponent[] comps, double[] weights, java.lang.Object ref) throws java.io.IOException
java.io.IOException
public static <C> ScanWriteUtils.ClassInfo<C> scanClassInfo(ReaderTokenizer rtok, java.lang.Class<C> baseClass) throws java.io.IOException
ModelComponent
, or a parameterized
class name, such as ModelList<FemModel3d>
, and returns
the associated class information. The scanned class must be
an instance of the specified baseClass.java.io.IOException
public static java.lang.String getClassTag(Scannable comp)
public static java.lang.String getParameterizedClassTag(Scannable comp, java.lang.Class<?> typeParam)
public static <C> C newComponent(ReaderTokenizer rtok, ScanWriteUtils.ClassInfo<C> cinfo, boolean warnOnly) throws java.io.IOException
warnOnly
is
true
and classInfo
is non-null
,
then if the class can't be instantiated, the method prints a warning
and returns null
.java.io.IOException