Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer
Class CRProtoCreator

java.lang.Object
  extended by org.web3d.vrml.renderer.CRProtoCreator
All Implemented Interfaces:
NodeTemplateToInstanceCreator, SceneGraphTraversalSimpleObserver
Direct Known Subclasses:
NRProtoCreator, OGLProtoCreator

public abstract class CRProtoCreator
extends java.lang.Object
implements NodeTemplateToInstanceCreator, SceneGraphTraversalSimpleObserver

A class that is used to create real instances of protos from their definitions.

The creator strips the definition apart and builds a runtime node based on the details and the node factory provided. The creator can handle one instance at a time, athough it will correctly parse and build nested proto declarations without extra effort.

We have a small conundrum to deal with - if the proto definition contains SF/MFNode fields, we don't know whether the values should be also generated as real runtime nodes too. Maybe the usage of this node will provide values that are dealt with after this class has finished. Other times, these defaul values must be used. For this implementation, we have gone with the safety-first approach: Always parse the definition of any SF or MFNode field and turn those into runtime instances. Although this may create extra garbage, there seems to be no nice way of dealing with this issue without a completely different architecture for the library.

Note: Under the current implementation, EXTERNPROTOs are not yet catered for.

Version:
$Revision: 1.33 $
Author:
Justin Couch

Field Summary
protected  SceneGraphTraversalSimpleObserver currentObserver
          The current observer.
protected  ErrorReporter errorReporter
          Reporter instance for handing out errors
protected  VRMLNodeFactory factory
          The factory that is used to generate the runtime version
protected  java.util.HashMap importMap
          Mapping of import names to the copy proxy instance
protected  boolean isVRML97
          Flag to say if the current proto instance is VRML97 capable
protected  int majorVersion
          The major version of the spec this instance belongs to.
protected  int minorVersion
          The minor version of the spec this instance belongs to.
protected  NodeCopier nodeCopier
          Class used to copy SF/MFNode field instances
protected  java.util.HashMap nodeMap
          Mapping of declaration node to the J3D version
protected  ProtoCopier protoCopier
          Class used to create the proto body nodes
protected  CRProtoInstance protoInstance
          The proto instance we're building up
protected  VRMLExecutionSpace rootSpace
          The parent executionSpace used when working with instances of nodes inside the field declarations.
protected  ProtoScene scene
          The scene as we are building it up during traversal
protected  FrameStateManager stateManager
          The state manager to currently use
protected  SceneGraphTraverser traverser
          Traverser used to examine SF/MFNode fields and the proto body
protected  java.lang.String worldURL
          The current world's root URL
 
Constructor Summary
protected CRProtoCreator(VRMLNodeFactory fac, java.lang.String worldURL, int major, int minor)
          Create a new instance of a generic proto creator.
 
Method Summary
 void fillinInstance(VRMLNodeTemplate template, VRMLNode nodeInstance, VRMLExecutionSpace space)
          Given a stubbed instance, fill in the rest of the details.
protected  void finishCreate(PrototypeDecl proto)
          Internal method to group code together for finishing proto creation
 void observedNode(VRMLNodeType parent, VRMLNodeType child, int field, boolean used)
          Notification of a child node.
protected abstract  void protoNode(VRMLNodeType parent, VRMLProtoInstance proto, int field, boolean used)
          Separate handler for the proto node, which needs to be renderer-specific
 void setErrorReporter(ErrorReporter reporter)
          Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion.
 void setFrameStateManager(FrameStateManager fsm)
          Set the frame state manager to use for the builder after this point.
protected  void setProtoField(VRMLNodeType node, int field, int fieldSize, VRMLFieldData data)
          Process a single field of a contained, nested proto.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.web3d.vrml.lang.NodeTemplateToInstanceCreator
newInstance
 

Field Detail

factory

protected VRMLNodeFactory factory
The factory that is used to generate the runtime version


traverser

protected SceneGraphTraverser traverser
Traverser used to examine SF/MFNode fields and the proto body


scene

protected ProtoScene scene
The scene as we are building it up during traversal


stateManager

protected FrameStateManager stateManager
The state manager to currently use


nodeMap

protected java.util.HashMap nodeMap
Mapping of declaration node to the J3D version


importMap

protected java.util.HashMap importMap
Mapping of import names to the copy proxy instance


protoInstance

protected CRProtoInstance protoInstance
The proto instance we're building up


rootSpace

protected VRMLExecutionSpace rootSpace
The parent executionSpace used when working with instances of nodes inside the field declarations.


nodeCopier

protected NodeCopier nodeCopier
Class used to copy SF/MFNode field instances


protoCopier

protected ProtoCopier protoCopier
Class used to create the proto body nodes


currentObserver

protected SceneGraphTraversalSimpleObserver currentObserver
The current observer. May be node or proto copier instance


errorReporter

protected ErrorReporter errorReporter
Reporter instance for handing out errors


isVRML97

protected boolean isVRML97
Flag to say if the current proto instance is VRML97 capable


majorVersion

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


minorVersion

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


worldURL

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

Constructor Detail

CRProtoCreator

protected CRProtoCreator(VRMLNodeFactory fac,
                         java.lang.String worldURL,
                         int major,
                         int minor)
Create a new instance of a generic proto creator.

Parameters:
fac - The factory to use (Must generate VRMLNodeType instances)
worldURL - the current world's root URL
major - The major version number of this scene
minor - The minor version number of this scene
Method Detail

setErrorReporter

public void setErrorReporter(ErrorReporter reporter)
Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old.

Specified by:
setErrorReporter in interface NodeTemplateToInstanceCreator
Parameters:
reporter - The instance to use or null

fillinInstance

public void fillinInstance(VRMLNodeTemplate template,
                           VRMLNode nodeInstance,
                           VRMLExecutionSpace space)
Given a stubbed instance, fill in the rest of the details. This is used for extern protos who create a light instance for the scenegraph and then after the EP is loaded they fill in the details.

Specified by:
fillinInstance in interface NodeTemplateToInstanceCreator
Parameters:
template - The proto definition loaded from the EP
space - The execution space this node belongs in
nodeInstance - The instance to fill out

observedNode

public void observedNode(VRMLNodeType parent,
                         VRMLNodeType child,
                         int field,
                         boolean used)
Notification of a child node.

Specified by:
observedNode in interface SceneGraphTraversalSimpleObserver
Parameters:
parent - The parent node of this node
child - The child node that is being observed
field - The index of the child field in its parent node
used - true if the node reference is actually a USE

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

protoNode

protected abstract void protoNode(VRMLNodeType parent,
                                  VRMLProtoInstance proto,
                                  int field,
                                  boolean used)
Separate handler for the proto node, which needs to be renderer-specific

Parameters:
parent - The parent node of this node
proto - The proto node that has been found
field - The index of the child field in its parent node
used - true if the node reference is actually a USE

finishCreate

protected void finishCreate(PrototypeDecl proto)
Internal method to group code together for finishing proto creation

Parameters:
proto - The decl of the proto

setProtoField

protected void setProtoField(VRMLNodeType node,
                             int field,
                             int fieldSize,
                             VRMLFieldData data)
                      throws FieldException
Process a single field of a contained, nested proto.

Parameters:
node - The node reference we are sending the value to
field - The index of the field to set the data for
fieldSize - The size of field to set the data for
data - The source data used to set the field
Throws:
FieldException - Any one of the normal field exceptions

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium