Xj3D VRML/X3D Code API

org.web3d.vrml.renderer
Class CRMainSceneBuilder

java.lang.Object
  extended byorg.web3d.vrml.renderer.CRMainSceneBuilder
All Implemented Interfaces:
BinaryContentHandler, ContentHandler, ProtoHandler, RouteHandler, ScriptHandler, StringContentHandler

public abstract class CRMainSceneBuilder
extends java.lang.Object
implements StringContentHandler, BinaryContentHandler, ProtoHandler, ScriptHandler, RouteHandler

A scene builder implementation for reading input from a SAV source and building a scenegraph with them.

This basic implementation does most of the hard work regardless of the individual renderer in use. The implementer of this class is only required to provide a single method - startNode(), although they are free to override any that they wish. It is strongly recommended that the overridden method be called on this class too to make sure state does not get out of alignment.

Version:
$Revision: 1.51 $
Author:
Justin Couch

Field Summary
protected static java.lang.String BAD_METHOD_MSG
          Message for the exceptions thrown for methods being called when they should not be (eg proto callbacks)
protected  boolean badFieldName
          Flag indicating that the last field we processed had an invalid name.
protected  VRMLNodeFactory baseNodeFactory
          The base node factory used to create individual factories
protected  int[] childIndexStack
          The stack of child indexes used during processing
protected  int currentFieldIndex
          Copy of the top child index for efficiency purposes
protected  VRMLNodeType currentNode
          Copy of the top node for efficiency purposes
protected  VRMLScriptNodeType currentScript
          Copy of the current working script definition
protected  java.util.Map defMap
          The mapping of def names (key) to node instances (value)
protected  HashSet dontLoadTypes
          Set of classes that we don't want to load
protected  ErrorReporter errorReporter
          The error handler used for reporting errors
protected  java.util.Map exportProxyMap
          The mapping of export node names (import foo.exportname AS bar) to their ImportProxyNode instance.
protected  java.util.Map externProtoMap
          The mapping of externproto names (key) to node instances (value)
protected  VRMLFieldReader fieldParser
          Field Parser for the current scene
protected  HashSet ignoreDefSet
          Set of DEF names to ignore when we come to USE decls
protected  int ignoreNodeCounter
          Counter when we ignore a node type we don't know about
protected  java.util.Map importProxyMap
          The mapping of imported node names (import foo.bar AS importname) to their ImportProxyNode instance.
protected  boolean init
          Flag to indicate that one time initialisation process has happened
protected  boolean inScript
          Flag to indicate we are inside a script at the moment
protected  boolean inStatic
          Flag to indicate we are currently under a static group
protected  boolean isVrml97
          Flag indicating what mode - VRML97 or VRML3.0 that we're using
protected  Locator locator
          The document locator to find error information
protected  int majorVersion
          The major version of the spec this file belongs to.
protected  WriteableSceneMetaData metaData
          The metadata for this scene
protected  int minorVersion
          The minor version of the spec this file belongs to.
protected  VRMLNodeFactory nodeFactory
          The node factory used to create real node instances
protected  VRMLNodeType[] nodeStack
          The stack of nodes used during processing the document
protected  CRProtoCreator protoCreator
          The creator used to instantiate protos
protected  java.util.Map protoMap
          The mapping of proto names (key) to node instances (value)
protected  VRMLWorldRootNodeType root
          The scene root node
protected  CRVRMLScene scene
          The scene that we are currently building
protected  SimpleStack scriptStack
          The working stack of currently building scripts.
protected static int STACK_INCREMENT
          The increment size of the stack if it get overflowed
protected static int STACK_START_SIZE
          The initial size of the stack for element processing
protected  FrameStateManager stateManager
          The state manager to currently use
protected  int staticDepthCounter
          Counter when we discover a static group node
protected  HashSet staticNodeSet
          Set of names under a StaticGroup so we can check for routes
protected  int topOfStack
          Counter to the top item in the stack array
protected static java.lang.String VRML_EXPORT_ERROR
          Error when an export statement is found in an VRML97 file
protected static java.lang.String VRML_IMPORT_ERROR
          Error when an import statement is found in an VRML97 file
protected static java.lang.String VRML97_PROFILE_STRING
          Name of the profile used for VRML97 compatibility
protected  java.lang.String worldURL
          The current world's root URL
 
Constructor Summary
protected CRMainSceneBuilder(VRMLNodeFactory fac)
          Create a scene builder with the given node factory.
 
Method Summary
 void componentDecl(java.lang.String componentInfo)
          A component declaration has been found in the code.
 void endDocument()
          Declaration of the end of the document.
 void endExternProtoDecl()
          Notification of the end of an EXTERNPROTO declaration.
 void endField()
          Notification of the end of a field declaration.
 void endNode()
          Notification of the end of a node declaration.
 void endProtoBody()
          Notification of the end of an ordinary proto body.
 void endProtoDecl()
          Notification of the end of an ordinary proto declaration statement.
 void endScriptDecl()
          Notification of the end of a script declaration.
 void exportDecl(java.lang.String defName, java.lang.String exported)
          An EXPORT declaration has been found in the document.
 void externProtoURI(java.lang.String[] values)
          Notification of the URI list for an EXTERNPROTO.
 void fieldValue(boolean value)
          Set the value of the field at the given index as an boolean.
 void fieldValue(boolean[] value, int len)
          Set the value of the field at the given index as an array of boolean.
 void fieldValue(double value)
          Set the value of the field at the given index as an double.
 void fieldValue(double[] value, int len)
          Set the value of the field at the given index as an array of doubles.
 void fieldValue(float value)
          Set the value of the field at the given index as a float.
 void fieldValue(float[] value, int len)
          Set the value of the field at the given index as an array of floats.
 void fieldValue(int value)
          Set the value of the field at the given index as an integer.
 void fieldValue(int[] value, int len)
          Set the value of the field at the given index as an array of integers.
 void fieldValue(long value)
          Set the value of the field at the given index as an long.
 void fieldValue(long[] value, int len)
          Set the value of the field at the given index as an array of longs.
 void fieldValue(java.lang.String value)
          The value of a normal field.
 void fieldValue(java.lang.String[] values)
          The value of an MFField where the underlying parser knows about how the values are broken up.
 void fieldValue(java.lang.String[] value, int len)
          Set the value of the field at the given index as an array of strings.
protected abstract  void generateProtoCreator()
          Generate a protoCreator instance now because one has not been set yet.
 NodeTemplateToInstanceCreator getProtoCreator()
          Grab the proto creator instance in use by this builder.
 CRVRMLScene getScene()
          Get the scene that was last built by this scene handler.
 void importDecl(java.lang.String inline, java.lang.String exported, java.lang.String imported)
          An IMPORT declaration has been found in the document.
 void metaDecl(java.lang.String key, java.lang.String value)
          A META declaration has been found in the code.
 void profileDecl(java.lang.String profileName)
          A profile declaration has been found in the code.
 void protoFieldDecl(int access, java.lang.String type, java.lang.String name, java.lang.Object value)
          Notification of a proto's field declaration.
 void protoIsDecl(java.lang.String fieldName)
          Notification of a field value uses an IS statement.
 void reset()
          Reset the builder.
protected  void resizeStack()
          Resize the stack if needed.
 void routeDecl(java.lang.String srcNodeName, java.lang.String srcFieldName, java.lang.String destNodeName, java.lang.String destFieldName)
          Notification of a ROUTE declaration in the file.
 void scriptFieldDecl(int access, java.lang.String type, java.lang.String name, java.lang.Object value)
          Notification of a script's field declaration.
 void setDocumentLocator(Locator loc)
          Set the document locator that can be used by the implementing code to find out information about the current line information.
 void setErrorReporter(ErrorReporter reporter)
          Set the error handler instance used by this instance of the builder.
 void setFrameStateManager(FrameStateManager fsm)
          Set the frame state manager to use for the builder after this point.
 void setGlobals(java.util.Map defs, java.util.Map protos, java.util.Map externProtos)
          Set the global DEF map to be used within fields.
 void setLoadRequirements(boolean useVrml97, boolean useBackgrounds, boolean useFogs, boolean useLights, boolean useAudio, boolean useViewpoints, boolean useExternals)
          Set the flags about what to load.
 void startDocument(java.lang.String uri, java.lang.String url, java.lang.String encoding, java.lang.String type, java.lang.String version, java.lang.String comment)
          Declaration of the start of the document.
 void startExternProtoDecl(java.lang.String name)
          Notification of the start of an EXTERNPROTO declaration of the given name.
 void startField(java.lang.String name)
          Notification of a field declaration.
abstract  void startNode(java.lang.String name, java.lang.String defName)
          Notification of the start of a node.
 void startProtoBody()
          Notification of the start of an ordinary proto body.
 void startProtoDecl(java.lang.String name)
          Notification of the start of an ordinary (inline) proto declaration.
 void startScriptDecl()
          Notification of the start of a script declaration.
 void useDecl(java.lang.String defName)
          The field value is a USE for the given node name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BAD_METHOD_MSG

protected static final java.lang.String BAD_METHOD_MSG
Message for the exceptions thrown for methods being called when they should not be (eg proto callbacks)

See Also:
Constant Field Values

STACK_START_SIZE

protected static final int STACK_START_SIZE
The initial size of the stack for element processing

See Also:
Constant Field Values

STACK_INCREMENT

protected static final int STACK_INCREMENT
The increment size of the stack if it get overflowed

See Also:
Constant Field Values

VRML97_PROFILE_STRING

protected static final java.lang.String VRML97_PROFILE_STRING
Name of the profile used for VRML97 compatibility

See Also:
Constant Field Values

VRML_IMPORT_ERROR

protected static final java.lang.String VRML_IMPORT_ERROR
Error when an import statement is found in an VRML97 file

See Also:
Constant Field Values

VRML_EXPORT_ERROR

protected static final java.lang.String VRML_EXPORT_ERROR
Error when an export statement is found in an VRML97 file

See Also:
Constant Field Values

protoCreator

protected CRProtoCreator protoCreator
The creator used to instantiate protos


init

protected boolean init
Flag to indicate that one time initialisation process has happened


errorReporter

protected ErrorReporter errorReporter
The error handler used for reporting errors


locator

protected Locator locator
The document locator to find error information


fieldParser

protected VRMLFieldReader fieldParser
Field Parser for the current scene


inScript

protected boolean inScript
Flag to indicate we are inside a script at the moment


ignoreNodeCounter

protected int ignoreNodeCounter
Counter when we ignore a node type we don't know about


inStatic

protected boolean inStatic
Flag to indicate we are currently under a static group


staticDepthCounter

protected int staticDepthCounter
Counter when we discover a static group node


badFieldName

protected boolean badFieldName
Flag indicating that the last field we processed had an invalid name. fieldValue and startNode() calls then have to deal with this flag


currentFieldIndex

protected int currentFieldIndex
Copy of the top child index for efficiency purposes


currentNode

protected VRMLNodeType currentNode
Copy of the top node for efficiency purposes


currentScript

protected VRMLScriptNodeType currentScript
Copy of the current working script definition


scene

protected CRVRMLScene scene
The scene that we are currently building


metaData

protected WriteableSceneMetaData metaData
The metadata for this scene


root

protected VRMLWorldRootNodeType root
The scene root node


nodeStack

protected VRMLNodeType[] nodeStack
The stack of nodes used during processing the document


childIndexStack

protected int[] childIndexStack
The stack of child indexes used during processing


topOfStack

protected int topOfStack
Counter to the top item in the stack array


defMap

protected java.util.Map defMap
The mapping of def names (key) to node instances (value)


protoMap

protected java.util.Map protoMap
The mapping of proto names (key) to node instances (value)


externProtoMap

protected java.util.Map externProtoMap
The mapping of externproto names (key) to node instances (value)


importProxyMap

protected java.util.Map importProxyMap
The mapping of imported node names (import foo.bar AS importname) to their ImportProxyNode instance.


exportProxyMap

protected java.util.Map exportProxyMap
The mapping of export node names (import foo.exportname AS bar) to their ImportProxyNode instance. Two level deep map. First level is by the DEF name of the appropriate Inline. This resolves to another Map that is keyed by the export name to the ImportProxyNode instance.


scriptStack

protected SimpleStack scriptStack
The working stack of currently building scripts.


baseNodeFactory

protected VRMLNodeFactory baseNodeFactory
The base node factory used to create individual factories


nodeFactory

protected VRMLNodeFactory nodeFactory
The node factory used to create real node instances


isVrml97

protected boolean isVrml97
Flag indicating what mode - VRML97 or VRML3.0 that we're using


dontLoadTypes

protected HashSet dontLoadTypes
Set of classes that we don't want to load


ignoreDefSet

protected HashSet ignoreDefSet
Set of DEF names to ignore when we come to USE decls


staticNodeSet

protected HashSet staticNodeSet
Set of names under a StaticGroup so we can check for routes


worldURL

protected java.lang.String worldURL
The current world's root URL


majorVersion

protected int majorVersion
The major version of the spec this file belongs to.


minorVersion

protected int minorVersion
The minor version of the spec this file belongs to.


stateManager

protected FrameStateManager stateManager
The state manager to currently use

Constructor Detail

CRMainSceneBuilder

protected CRMainSceneBuilder(VRMLNodeFactory fac)
Create a scene builder with the given node factory. If the factory reference is null then the default factory will be used.

Parameters:
fac - The factory instance to use.
Throws:
java.lang.NullPointerException - The factory reference is null
Method Detail

setDocumentLocator

public void setDocumentLocator(Locator loc)
Set the document locator that can be used by the implementing code to find out information about the current line information. This method is called by the parser to your code to give you a locator to work with. If this has not been set by the time startDocument() has been called, you can assume that you will not have one available.

Specified by:
setDocumentLocator in interface ContentHandler
Parameters:
loc - The locator instance to use

startDocument

public void startDocument(java.lang.String uri,
                          java.lang.String url,
                          java.lang.String encoding,
                          java.lang.String type,
                          java.lang.String version,
                          java.lang.String comment)
                   throws SAVException,
                          VRMLException
Declaration of the start of the document. The parameters are all of the values that are declared on the header line of the file after the # start. The type string contains the representation of the first few characters of the file after the #. This allows us to work out if it is VRML97 or the later X3D spec.

Version numbers change from VRML97 to X3D and aren't logical. In the first, it is #VRML V2.0 and the second is #X3D V1.0 even though this second header represents a later spec.

Specified by:
startDocument in interface ContentHandler
Parameters:
uri - The URI of the file.
url - The base URL of the file for resolving relative URIs contained in the file
encoding - The encoding of this document - utf8 or binary
type - The bytes of the first part of the file header
version - The VRML version of this document
comment - Any trailing text on this line. If there is none, this is null.
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

profileDecl

public void profileDecl(java.lang.String profileName)
                 throws SAVException,
                        VRMLException
A profile declaration has been found in the code. IAW the X3D specification, this method will only ever be called once in the lifetime of the parser for this document. The name is the name of the profile for the document to use.

Specified by:
profileDecl in interface ContentHandler
Parameters:
profileName - The name of the profile to use
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

componentDecl

public void componentDecl(java.lang.String componentInfo)
                   throws SAVException,
                          VRMLException
A component declaration has been found in the code. There may be zero or more component declarations in the file, appearing just after the profile declaration. The textual information after the COMPONENT keyword is left unparsed and presented through this call. It is up to the user application to parse the component information.

Specified by:
componentDecl in interface ContentHandler
Parameters:
componentInfo - The name of the component to use
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

metaDecl

public void metaDecl(java.lang.String key,
                     java.lang.String value)
              throws SAVException,
                     VRMLException
A META declaration has been found in the code. There may be zero or more meta declarations in the file, appearing just after the component declaration. Each meta declaration has a key and value strings. No information is to be implied from this. It is for extra data only.

Specified by:
metaDecl in interface ContentHandler
Parameters:
key - The value of the key string
value - The value of the value string
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

importDecl

public void importDecl(java.lang.String inline,
                       java.lang.String exported,
                       java.lang.String imported)
                throws SAVException,
                       VRMLException
An IMPORT declaration has been found in the document. All three parameters will always be provided, regardless of whether the AS keyword has been used or not. The parser implementation will automatically set the local import name as needed.

Specified by:
importDecl in interface ContentHandler
Parameters:
inline - The name of the inline DEF nodes
exported - The exported name from the inlined file
imported - The local name to use for the exported name
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

exportDecl

public void exportDecl(java.lang.String defName,
                       java.lang.String exported)
                throws SAVException,
                       VRMLException
An EXPORT declaration has been found in the document. Both paramters will always be provided regardless of whether the AS keyword has been used. The parser implementation will automatically set the exported name as needed.

Specified by:
exportDecl in interface ContentHandler
Parameters:
defName - The DEF name of the nodes to be exported
exported - The name to be exported as
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

endDocument

public void endDocument()
                 throws SAVException,
                        VRMLException
Declaration of the end of the document. There will be no further parsing and hence events after this.

Specified by:
endDocument in interface ContentHandler
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

startNode

public abstract void startNode(java.lang.String name,
                               java.lang.String defName)
                        throws SAVException,
                               VRMLException
Notification of the start of a node. This is the opening statement of a node and it's DEF name. USE declarations are handled in a separate method.

Specified by:
startNode in interface ContentHandler
Parameters:
name - The name of the node that we are about to parse
defName - The string associated with the DEF name. Null if not given for this node.
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

endNode

public void endNode()
             throws SAVException,
                    VRMLException
Notification of the end of a node declaration.

Specified by:
endNode in interface ContentHandler
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

startField

public void startField(java.lang.String name)
                throws SAVException,
                       VRMLException
Notification of a field declaration. This notification is only called if it is a standard node. If the node is a script or PROTO declaration then the ScriptHandler or ProtoHandler methods are used.

Specified by:
startField in interface ContentHandler
Parameters:
name - The name of the field declared
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

fieldValue

public void fieldValue(java.lang.String value)
                throws SAVException,
                       VRMLException
The value of a normal field. This is a string that represents the entire value of the field. MFStrings will have to be parsed. This is a terminating call for startField as well. The next call will either be another startField() or endNode().

If this field is an SFNode with a USE declaration you will have the useDecl(String) method called rather than this method.

Specified by:
fieldValue in interface StringContentHandler
Parameters:
value - The value of this field
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

fieldValue

public void fieldValue(java.lang.String[] values)
                throws SAVException,
                       VRMLException
The value of an MFField where the underlying parser knows about how the values are broken up. The parser is not required to support this callback, but implementors of this interface should understand it. The most likely time we will have this method called is for MFString or URL lists. If called, it is guaranteed to split the strings along the SF node type boundaries.

Specified by:
fieldValue in interface StringContentHandler
Parameters:
values - The list of string representing the values
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

useDecl

public void useDecl(java.lang.String defName)
             throws SAVException,
                    VRMLException
The field value is a USE for the given node name. This is a terminating call for startField as well. The next call will either be another startField() or endNode().

Specified by:
useDecl in interface ContentHandler
Parameters:
defName - The name of the DEF string to use
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

endField

public void endField()
              throws SAVException,
                     VRMLException
Notification of the end of a field declaration. This is called only at the end of an MFNode declaration. All other fields are terminated by either useDecl(String) or fieldValue(String).

Specified by:
endField in interface ContentHandler
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

fieldValue

public void fieldValue(int value)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an integer. This would be used to set SFInt32 field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(int[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of integers. This would be used to set MFInt32 field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(boolean value)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an boolean. This would be used to set SFBool field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(boolean[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of boolean. This would be used to set MFBool field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(float value)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as a float. This would be used to set SFFloat field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(float[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec2f, SFVec3f and SFRotation field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(long value)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an long. This would be used to set SFTime field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(long[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of longs. This would be used to set MFTime field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(double value)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an double. This would be used to set SFDouble field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(double[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of doubles. This would be used to set MFDouble, SFVec2d and SFVec3d field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

fieldValue

public void fieldValue(java.lang.String[] value,
                       int len)
                throws SAVException,
                       VRMLException
Set the value of the field at the given index as an array of strings. This would be used to set MFString field types.

Specified by:
fieldValue in interface BinaryContentHandler
Parameters:
value - The new value to use for the node
len - The number of valid entries in the value array
Throws:
SAVException - This call is taken at the wrong time in the structure of the document.
VRMLException - This call is taken at the wrong time in the structure of the document.

startProtoDecl

public void startProtoDecl(java.lang.String name)
                    throws SAVException,
                           VRMLException
Notification of the start of an ordinary (inline) proto declaration. The proto has the given node name.

Specified by:
startProtoDecl in interface ProtoHandler
Parameters:
name - The name of the proto
Throws:
SAVException - Always thrown
VRMLException - Never thrown

endProtoDecl

public void endProtoDecl()
                  throws SAVException,
                         VRMLException
Notification of the end of an ordinary proto declaration statement.

Specified by:
endProtoDecl in interface ProtoHandler
Throws:
SAVException - Always thrown
VRMLException - Never thrown

protoFieldDecl

public void protoFieldDecl(int access,
                           java.lang.String type,
                           java.lang.String name,
                           java.lang.Object value)
                    throws SAVException,
                           VRMLException
Notification of a proto's field declaration. This is used for both external and ordinary protos. Externprotos don't allow the declaration of a value for the field. In this case, the parameter value will be null.

Specified by:
protoFieldDecl in interface ProtoHandler
Parameters:
access - The access type (eg exposedField, field etc)
type - The field type (eg SFInt32, MFVec3d etc)
name - The name of the field
value - The default value of the field. Null if not allowed.
Throws:
SAVException - Always thrown
VRMLException - Never thrown

protoIsDecl

public void protoIsDecl(java.lang.String fieldName)
                 throws SAVException,
                        VRMLException
Notification of a field value uses an IS statement. If we are running in VRML97 mode, this will throw an exception if the field access types do not match.

Specified by:
protoIsDecl in interface ProtoHandler
Parameters:
fieldName - The name of the field that is being IS'd
Throws:
SAVException - Always thrown
VRMLException - Never thrown

startProtoBody

public void startProtoBody()
                    throws SAVException,
                           VRMLException
Notification of the start of an ordinary proto body. All nodes contained between here and the corresponding endProtoBody() statement form the body and not the normal scenegraph information.

Specified by:
startProtoBody in interface ProtoHandler
Throws:
SAVException - Always thrown
VRMLException - Never thrown

endProtoBody

public void endProtoBody()
                  throws SAVException,
                         VRMLException
Notification of the end of an ordinary proto body. Parsing now returns to ordinary node declarations.

Specified by:
endProtoBody in interface ProtoHandler
Throws:
SAVException - Always thrown
VRMLException - Never thrown

startExternProtoDecl

public void startExternProtoDecl(java.lang.String name)
                          throws SAVException,
                                 VRMLException
Notification of the start of an EXTERNPROTO declaration of the given name. Between here and the matching endExternProtoDecl() call you should only receive protoFieldDecl(int, java.lang.String, java.lang.String, java.lang.Object) calls.

Specified by:
startExternProtoDecl in interface ProtoHandler
Parameters:
name - The node name of the extern proto
Throws:
SAVException - Always thrown
VRMLException - Never thrown

endExternProtoDecl

public void endExternProtoDecl()
                        throws SAVException,
                               VRMLException
Notification of the end of an EXTERNPROTO declaration.

Specified by:
endExternProtoDecl in interface ProtoHandler
Throws:
SAVException - Always thrown
VRMLException - Never thrown

externProtoURI

public void externProtoURI(java.lang.String[] values)
                    throws SAVException,
                           VRMLException
Notification of the URI list for an EXTERNPROTO. This is a complete list of URIs. The calling application is required to interpet the incoming strings. Even if the externproto has no URIs registered, this method shall be called. If there are none available, this will be called with a zero length list of values.

Specified by:
externProtoURI in interface ProtoHandler
Parameters:
values - A list of strings representing all of the URI values
Throws:
SAVException - Always thrown
VRMLException - Never thrown

startScriptDecl

public void startScriptDecl()
                     throws SAVException,
                            VRMLException
Notification of the start of a script declaration. All calls between now and the corresponding endScriptDecl() call belong to this script node. This method will be called after the ContentHandler startNode() method call. All DEF information is contained in that method call and this just signifies the start of script processing so that we know to treat the field parsing callbacks a little differently.

Specified by:
startScriptDecl in interface ScriptHandler
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

endScriptDecl

public void endScriptDecl()
                   throws SAVException,
                          VRMLException
Notification of the end of a script declaration. This is guaranteed to be called before the ContentHandler endNode() callback.

Specified by:
endScriptDecl in interface ScriptHandler
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

scriptFieldDecl

public void scriptFieldDecl(int access,
                            java.lang.String type,
                            java.lang.String name,
                            java.lang.Object value)
                     throws SAVException,
                            VRMLException
Notification of a script's field declaration. This is used for all fields except url, mustEvaluate and directOutput fields. These fields use the normal field callbacks of ContentHandler.

Specified by:
scriptFieldDecl in interface ScriptHandler
Parameters:
access - The access type (eg exposedField, field etc)
type - The field type (eg SFInt32, MFVec3d etc)
name - The name of the field
value - The default value of the field
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

routeDecl

public void routeDecl(java.lang.String srcNodeName,
                      java.lang.String srcFieldName,
                      java.lang.String destNodeName,
                      java.lang.String destFieldName)
               throws SAVException,
                      VRMLException
Notification of a ROUTE declaration in the file. The context of this route should be assumed from the surrounding calls to start and end of proto and node bodies.

Specified by:
routeDecl in interface RouteHandler
Parameters:
srcNodeName - The name of the DEF of the source node
srcFieldName - The name of the field to route values from
destNodeName - The name of the DEF of the destination node
destFieldName - The name of the field to route values to
Throws:
SAVException - This call is taken at the wrong time in the structure of the document
VRMLException - The content provided is invalid for this part of the document or can't be parsed

generateProtoCreator

protected abstract void generateProtoCreator()
Generate a protoCreator instance now because one has not been set yet.


getProtoCreator

public NodeTemplateToInstanceCreator getProtoCreator()
Grab the proto creator instance in use by this builder.

Returns:
An instance of the current creator

setErrorReporter

public void setErrorReporter(ErrorReporter reporter)
Set the error handler instance used by this instance of the builder. The handler is used to report errors at the higher level. A value of null will clear the current instance and return to the default handling.

Parameters:
reporter - The instance to use or null to clear

getScene

public CRVRMLScene getScene()
Get the scene that was last built by this scene handler. If none of the methods have been called yet, this will return a null reference. The scene instance returned by this builder will not have had any external references resolved. Externprotos, scripts, Inlines and all other nodes that reference part of their data as a URL will need to be loaded separately.

Returns:
The last built scene

reset

public void reset()
Reset the builder. This is used to make sure that the builder has been reset after a parsing run just in case the last parsing run exited abnormally and left us in an odd state. Sometimes this can prevent us from parsing again. This method should be called just before the VRMLReader.parse() method is called.

The flags set about what to load are not reset by this method.


setGlobals

public void setGlobals(java.util.Map defs,
                       java.util.Map protos,
                       java.util.Map externProtos)
Set the global DEF map to be used within fields. This is maintained between resets so it should be cleared when necessary.

Parameters:
defs - The new DEF map to use
protos - The new proto map to use
externProtos - The new externproto map to use

setLoadRequirements

public void setLoadRequirements(boolean useVrml97,
                                boolean useBackgrounds,
                                boolean useFogs,
                                boolean useLights,
                                boolean useAudio,
                                boolean useViewpoints,
                                boolean useExternals)
Set the flags about what to load. Nodes defined as externals are inlines and extern protos.

Parameters:
useVrml97 - true if the semantics should be VRML97 capable rather than the looser VRML 3.0.
useBackgrounds - true if BackgroundNodeTypes should be loaded
useFogs - true if FogNodeTypes should be loaded
useLights - true if LightNodeTypes should be loaded
useAudio - true if AudioClipNodeTypes should be loaded
useViewpoints - true if ViewpointNodeTypes should loaded
useExternals - true if ExternalNodeTypes should be loaded

setFrameStateManager

public void setFrameStateManager(FrameStateManager fsm)
Set the frame state manager to use for the builder after this point. Set a value of null it will clear the currently set items.

Parameters:
fsm - The state manager to use

resizeStack

protected final void resizeStack()
Resize the stack if needed. Marked as final in order to encourage the compiler to inline the code for faster execution