artisynth.core.modelbase
Class ScanWriteUtils

java.lang.Object
  extended by artisynth.core.modelbase.ScanWriteUtils

public class ScanWriteUtils
extends java.lang.Object


Constructor Summary
ScanWriteUtils()
           
 
Method Summary
static boolean getTokenPrinting()
          Returns true if token printing is enabled in the scanfull() method.
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 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 void postscanComponentBegin(java.util.Deque<ScanToken> tokens, ModelComponent comp)
          Checks if the next token in the queue is a BEGIN token for a component, and if so, consumes it.
static ScanToken postscanComponentToken(java.util.Deque<ScanToken> tokens)
          Checks if the next token on the queue is an ObjectToken holding a component reference.
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 postscanPropertyValues(java.util.Deque<ScanToken> tokens, HasProperties host, java.lang.String[] propNames)
          Checks if the next token in the queue is a StringToken containing one of a specified set of property names.
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[]
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 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 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 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)
          Attempts to scan and set a property value for a specified host.
static java.lang.Object scanPropertyValue(ReaderTokenizer rtok, HasProperties host, java.lang.String propName)
          Scans a specific property value for a host, assuming that the property name has already been scanned and matched.
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 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScanWriteUtils

public ScanWriteUtils()
Method Detail

setTokenPrinting

public static void setTokenPrinting(boolean enable)
Debugging hook to enable printing of the token queue produced in the scanfull() method, before postscan() is called.

Parameters:
enable - if true, enables token printing.

getTokenPrinting

public static boolean getTokenPrinting()
Returns true if token printing is enabled in the scanfull() method.

Returns:
true if token printing is enabled in scan()

scanAndStoreReference

public static boolean scanAndStoreReference(ReaderTokenizer rtok,
                                            java.util.Deque<ScanToken> tokens)
                                     throws java.io.IOException
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.

Parameters:
rtok - input token stream
tokens - token queue for postscan
Returns:
true if reference path is scanned and stored in the queue as a StringToken
Throws:
java.io.IOException

scanAndStoreReferences

public static int scanAndStoreReferences(ReaderTokenizer rtok,
                                         java.util.Deque<ScanToken> tokens)
                                  throws java.io.IOException
Assumes that the next set of input tokens are a set of component reference paths enclosed between square brackets. Read these reference paths, stored their values in the token queue as a set of StringTokens, and return the number of reference paths found.

Parameters:
rtok - input token stream
tokens - token storage queue for postscan
Returns:
number of reference paths read
Throws:
java.io.IOException

scanAndStorePropertyPath

public static void scanAndStorePropertyPath(ReaderTokenizer rtok,
                                            java.util.Deque<ScanToken> tokens)
                                     throws java.io.IOException
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.

Parameters:
rtok - input token stream
tokens - token storage queue for postscan
Throws:
java.io.IOException

scanAndStorePropertyPaths

public static int scanAndStorePropertyPaths(ReaderTokenizer rtok,
                                            java.util.Deque<ScanToken> tokens)
                                     throws java.io.IOException
Assumes that the next set of input tokens are a set of property paths enclosed between square brackets. Read these reference paths, store their values in the token queue as a set of StringTokens, and return the number of paths found.

Parameters:
rtok - input token stream
tokens - token storage queue for postscan
Returns:
number of paths read
Throws:
java.io.IOException

scanAndStoreReference

public static boolean scanAndStoreReference(ReaderTokenizer rtok,
                                            java.lang.String name,
                                            java.util.Deque<ScanToken> tokens)
                                     throws java.io.IOException
Attempts to scan a reference path associated with a given attribute name. Checks if the current token is a word matching the attribute name. If so, scan '=' and the reference path, store the reference path in the token queue, and return true. Otherwise, return false.

Parameters:
rtok - input token stream
name - attribute name
tokens - token storage queue for postscan
Returns:
true if the attribute name was matched
Throws:
java.io.IOException

scanAndStoreReferences

public static int scanAndStoreReferences(ReaderTokenizer rtok,
                                         java.lang.String name,
                                         java.util.Deque<ScanToken> tokens)
                                  throws java.io.IOException
Attempts to scan a set of reference paths associated with a given attribute name. Checks if the current token is a word matching the attribute name. If so, scan '=' and the reference paths ( assumed to be enclosed by square brackets), store the paths in the token queue, and return the number of paths found. Otherwise, return -1.

Parameters:
rtok - input token stream
name - attribute name
tokens - token storage queue for postscan
Returns:
number of paths found, or -1 if the attribute name did not match
Throws:
java.io.IOException

scanAndStorePropertyPath

public static boolean scanAndStorePropertyPath(ReaderTokenizer rtok,
                                               java.lang.String name,
                                               java.util.Deque<ScanToken> tokens)
                                        throws java.io.IOException
Attempts to scan a property path associated with a given attribute name. Checks if the current token is a word matching the attribute name. If so, scan '=' and the property path, store the path in the token queue, and return true. Otherwise, return false.

Parameters:
rtok - input token stream
name - attribute name
tokens - token storage queue for postscan
Returns:
true if the attribute name was matched
Throws:
java.io.IOException

scanAndStorePropertyPaths

public static int scanAndStorePropertyPaths(ReaderTokenizer rtok,
                                            java.lang.String name,
                                            java.util.Deque<ScanToken> tokens)
                                     throws java.io.IOException
Attempts to scan a set of property paths associated with a given attribute name. Checks if the current token is a word matching the attribute name. If so, scan '=' and the property paths (assumed to be enclosed in square brackets), store the paths in the token queue, and return true. Otherwise, return false.

Parameters:
rtok - input token stream
name - attribute name
tokens - token storage queue for postscan
Returns:
number of paths found, or -1 if the attribute name did not match
Throws:
java.io.IOException

postscanAttributeName

public 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. If so, consumes that token and returns true. Otherwise, returns false.

Parameters:
tokens - queue of stored tokens
name - name to check on the token queue
Returns:
true if the next token is a StringToken containing name.

postscanComponentBegin

public static void postscanComponentBegin(java.util.Deque<ScanToken> tokens,
                                          ModelComponent comp)
                                   throws java.io.IOException
Checks if the next token in the queue is a BEGIN token for a component, and if so, consumes it. Otherwise, throws an exception.

Parameters:
tokens - queue of stored tokens
comp - component associated with the BEGIN
Throws:
java.io.IOException

postscanComponent

public static boolean postscanComponent(java.util.Deque<ScanToken> tokens,
                                        CompositeComponent ancestor)
                                 throws java.io.IOException
Checks if the next token on the queue is an ObjectToken holding a component reference. If so, consumes the token, postscans the component, and returns true. Otherwise, returns false.

Parameters:
tokens - queue of stored tokens
ancestor - ancestor for evaluating reference paths
Returns:
true if the next token is an ObjectToken holding a component reference
Throws:
java.io.IOException - if unexpected token input was encountered

postscanComponent

public static boolean postscanComponent(java.util.Deque<ScanToken> tokens,
                                        java.lang.String name,
                                        CompositeComponent ancestor)
                                 throws java.io.IOException
Checks if the next token on the queue is a StringToken matching a specific attribute name. If so, consumes the token, looks for an ObjectToken holding a component and postscans that component.

Parameters:
tokens - queue of stored tokens
name - attribute name
ancestor - ancestor for evaluating reference paths
Returns:
true if the attribute name was matched and the component scanned
Throws:
java.io.IOException - if unexpected token input was encountered

postscanComponentToken

public static ScanToken postscanComponentToken(java.util.Deque<ScanToken> tokens)
                                        throws java.io.IOException
Checks if the next token on the queue is an ObjectToken holding a component reference. If so, consumes the token and returns it. Otherwise, returns null.

Parameters:
tokens - queue of stored tokens
Returns:
ObjectToken holding a component reference, or null.
Throws:
java.io.IOException - if unexpected token input was encountered

postscanReference

public static <C> C postscanReference(java.util.Deque<ScanToken> tokens,
                                      java.lang.Class<C> clazz,
                                      CompositeComponent ancestor)
                           throws java.io.IOException
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.

Parameters:
tokens - queue of stored tokens
clazz - class that the referenced component must be an instance of
ancestor - ancestor for the reference path
Returns:
referenced component
Throws:
java.io.IOException - if the next token is not a StringToken or if the reference cannot be found

postscanReferences

public static <C> C[] postscanReferences(java.util.Deque<ScanToken> tokens,
                                         java.lang.Class<C> clazz,
                                         CompositeComponent ancestor)
                              throws java.io.IOException
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. The corresponding components are then located with respect to ancestor, type checked to ensure that they are instances of clazz, and then returned as an array.

Parameters:
tokens - queue of stored tokens
clazz - class that each referenced component must be an instance of
ancestor - ancestor for the reference path
Returns:
array of component references
Throws:
java.io.IOException - if the token structure is incorrect or if the referenced components cannot be found.

postscanReferences

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
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. The corresponding components are then located with respect to ancestor, type checked to ensure that they are instances of clazz, and then returned in the collection refs.

Parameters:
tokens - queue of stored tokens
refs - returns the component references
clazz - class that each referenced component must be an instance of
ancestor - ancestor for the reference path
Throws:
java.io.IOException - if the token structure is incorrect or if the referenced components cannot be found.

postscanProperty

public static Property postscanProperty(java.util.Deque<ScanToken> tokens,
                                        CompositeComponent ancestor)
                                 throws java.io.IOException
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.

Parameters:
tokens - queue of stored tokens
ancestor - ancestor for the property path
Returns:
property corresponding to the path
Throws:
java.io.IOException - if the next token is not a StringToken or if the property cannot be found

postscanProperties

public static java.util.ArrayList<Property> postscanProperties(java.util.Deque<ScanToken> tokens,
                                                               CompositeComponent ancestor)
                                                        throws java.io.IOException
Checks that the next set of tokens in the stream consist of a BEGIN token, a set of property paths, and an END token. The corresponding properties are then located with respect to ancestor and returned in an ArrayList.

Parameters:
tokens - queue of stored tokens
ancestor - ancestor for the reference path
Returns:
ArrayList of properties
Throws:
java.io.IOException - if the token structure is incorrect or if the properties cannot be found

scanfull

public static void scanfull(ReaderTokenizer rtok,
                            ModelComponent comp,
                            CompositeComponent ancestor)
                     throws java.io.IOException
Performs both a scan and a postscan for a specific component. This will include creating the token storage queue. If the component is the top node of the hierarchy, then the specified ancestor should be the component itself.

Parameters:
rtok - input token stream
comp - component to scan
ancestor - ancestor component for resolving references
Throws:
java.io.IOException

printTokens

public static void printTokens(java.util.Deque<ScanToken> tokens)
Diagnostic method to print a token queue to the standard output stream.

Parameters:
tokens - token queue to be printed

printTokens

public static void printTokens(java.io.PrintWriter pw,
                               java.util.Deque<ScanToken> tokens)
Diagnostic method to print a token queue to a print writer.

Parameters:
pw - print writer for printing the token queue
tokens - token queue to be printed

scanProperty

public static boolean scanProperty(ReaderTokenizer rtok,
                                   HasProperties host)
                            throws java.io.IOException
Attempts to scan and set a property value for a specified host. Checks if the current token is a word matching one of the host's property names. If so, scan either '=' or ':' and the following property value, set this value within the host, and return true. Otherwise, return false.

Parameters:
rtok - input token stream
host - host containing the property
Returns:
true if a property was matched and scanned
Throws:
java.io.IOException

scanPropertyValue

public static java.lang.Object scanPropertyValue(ReaderTokenizer rtok,
                                                 HasProperties host,
                                                 java.lang.String propName)
                                          throws java.io.IOException
Scans a specific property value for a host, assuming that the property name has already been scanned and matched. Scans either '=' or ':' and the following property value, and returns the value.

Parameters:
rtok - input token stream
host - host containing the property
propName - property to try and scan
Returns:
the scanning property value
Throws:
java.io.IOException

scanAndStorePropertyValues

public static boolean scanAndStorePropertyValues(ReaderTokenizer rtok,
                                                 HasProperties host,
                                                 java.lang.String[] propNames,
                                                 java.util.Deque<ScanToken> tokens)
                                          throws java.io.IOException
Attempts to scan and store a specific set of property values for a specified host. Checks if the current token is a word matching one of the specified property names. If so, scan either '=' or ':' and the following property value, store the property name and value in the token queue using a 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.

Parameters:
rtok - input token stream
host - host containing the properties
propNames - names of properties to match
tokens - token queue for postscan
Returns:
true if a property value was scanned and stored.
Throws:
java.io.IOException

postscanPropertyValues

public static boolean postscanPropertyValues(java.util.Deque<ScanToken> tokens,
                                             HasProperties host,
                                             java.lang.String[] propNames)
                                      throws java.io.IOException
Checks if the next token in the queue is a StringToken containing one of a specified set of property names. If so, consumes that token, along with a following token giving the property value, sets that property value within the host, and returns true. Otherwise, returns false.

Parameters:
tokens - queue of stored tokens
host - host containing the properties
propNames - names of the properties to match
Returns:
true if a property was matched and set
Throws:
java.io.IOException

writeBracketedReferences

public static void writeBracketedReferences(java.io.PrintWriter pw,
                                            java.util.Collection<? extends ModelComponent> comps,
                                            CompositeComponent ancestor)
                                     throws java.io.IOException
Writes the reference paths for a set of components to a print writer, enclosed by square brackets.

Parameters:
pw - PrintWriter to write the references to
comps - components providing the reference paths
ancestor - ancestor component with respect to which reference paths should be generated
Throws:
java.io.IOException

writeReferences

public static void writeReferences(java.io.PrintWriter pw,
                                   java.lang.Iterable<ModelComponent> comps,
                                   CompositeComponent ancestor)
                            throws java.io.IOException
Writes the reference paths for a set of components to a print writer. Unlike writeBracketedReferences(), the paths are not enclosed within square brackets.

Parameters:
pw - PrintWriter to write the references to
comps - components providing the reference paths
ancestor - ancestor component with respect to which reference paths should be generated
Throws:
java.io.IOException