Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer
Class CRProtoInstance

java.lang.Object
  extended by org.web3d.vrml.renderer.CRProtoInstance
All Implemented Interfaces:
VRMLExecutionSpace, VRMLNode, FrameStateListener, VRMLNodeType, VRMLProtoInstance

public class CRProtoInstance
extends java.lang.Object
implements VRMLProtoInstance, VRMLNodeType

A concrete instance of a Prototype that is common for all renderers.

This class cannot be instantiated directly. The only way to get an instance of this is to ask for one from a proto implementation - either external or normal. As a node that does not form part of the scenegraph, the fields that are those of the root node's definition. If you ask for the normal implementation node, you will also get this first node.

IS Implementation

This implementation handles IS values as a sort of route with a few missing bits. When a value is set in the interface declaration, we look up all the IS related nodes and fields. For each of these we then call sendRoute() on them to update their value.

For the reverse case, when a value changes inside the proto body, we just mark the field as being changed in that node. Then, when someone checks the proto interface field, it will go through the list of related IS nodes and ask their field if it has been updated. If it has, then this value is copied to the interface declaration field and, using setValue() call on the interface field, makes sure it gets propogated to the other users.

Note: The upshot of this implementation is that is does not correctly deal with IS values where the end user has not connected a ROUTE to one of the proto declaration fields. In order to send values to items where there is an IS, we rely on having the user call hasFieldChanged() or setValue() to update all the internal users of the field. In the case where fields are not routed, this means that hasFieldChanged() is never called and hence the other users of IS are never informed.

DEF/USE Handling

Because you can DEF an instance of a Proto, we run into all sorts of interesting problems. As we have to put in Java3D shared groups and stuff we really need access to the root node before it is created. The problem there is that we don't have that access, and even when we do it is too late to deal with the DEF work. In an ideal world, when you ask for the implementation node the J3D node it returns and the node this instance returns are going to be the same thing. DEF completely stuffs with that idea.

The solution implemented here is to take the root node and apply any wrapping that may be needed to get it to work in a shared environment. In order to use a ProtoInstance within the J3D scene you first check for the type being correct by asking for the Implementation node and checking the interface corresponds to one that you are allowed to accept. If that passes then you check for the DEF with isDEF() just like any other node. Then, to add the real object to the scenegraph you call either getSharedObject() or getSceneGraphObject() as appropriate. Note that they must be called on this class instance, not on the implementation node. If you call them on the implementation instance, the results are undefined and will probably lead to a lot of errors generated by the Java3D internals.

Version:
$Revision: 1.75 $
Author:
Justin Couch

Field Summary
protected static java.lang.String BAD_NODE_MSG
          A standard message for when the supplied node is wrong.
protected  int bodyNodeCount
          A counter for the number of body nodes
protected  VRMLNodeType[] bodyNodes
          The nodes that form the body group
protected  boolean completeBody
          Whether the protoBody is complete
protected  ErrorReporter errorReporter
          Reporter instance for handing out errors
protected static java.lang.String FIELD_CLASH_MSG
          When the same field is defined twice, but with different types
protected  int FIELD_METADATA
          Index of the metadata field
protected  IntHashMap fieldChangedMap
          Map of whether the field index has been changed since last check
protected  VRMLFieldData fieldData
          Scratch class var for returning field data
protected  java.util.List fieldDeclList
          List of the field maps registered in order for their definitions.
protected  java.util.Map fieldIndexMap
          Data mapping holding the field name -> index (Integer) mapping
protected  IntHashMap fieldSizeMap
          A map of the field indexes (Integer) to the size of the data provided at that field.
protected  IntHashMap fieldValueMap
          A map of the field indexes (Integer) to their values (object).
protected  boolean inSetup
          Flag indicating we are in setup mode currently
protected  boolean isDEF
          Flag indicating this is a DEF node
protected  int[] isListEntry
          IsList entry to use for sendRoute, the one that triggered the event
protected  IntHashMap isMap
          The mapping that holds is field index (key) to the list of destination node information.
protected  boolean isStatic
          Flag for the node being static
protected  boolean isVrml97
          Flag indicating VRML97 lookup semantics for IS behaviour
protected  int lastFieldIndex
          The last field index.
protected  int[] layerIds
          The list of layer IDs that reference this node.
protected static java.lang.String METADATA_NODE_MSG
          Message for when the node in setValue() is not a Metadata
protected static java.lang.String METADATA_PROTO_MSG
          Message for when the proto is not a Metadata
protected  java.lang.String nodeName
          The name of this node type
protected  VRMLProtoInstance pMetadata
          proto representation of the metadata node
protected  java.util.HashMap proxyNodeMap
          Mapping of an external imported name to the ImportNodeProxy instance
protected  int[] refCounts
          The current number of references to this node.
protected  int[] removedLayerIds
          The list of IDs that have been marked as being removed.
protected  VRMLNodeType rootNode
          The node that describes the type of proto
protected  ProtoScene sceneInfo
          Contained scene information
protected  FrameStateManager stateManager
          Frame state manager for this event model instance
protected  java.util.Map uniqueFieldIndexMap
          Unique version of fieldIndexMap with no exposedField expansions
protected  VRMLNodeType vfMetadata
          SFNode metadata NULL
protected static java.lang.String VRML97_FIELD_MSG
          Message when the field type is not valid in VRML97
protected  int vrmlMajorVersion
          The major version of the spec this instance belongs to.
protected  int vrmlMinorVersion
          The minor version of the spec this instance belongs to.
 
Constructor Summary
protected CRProtoInstance(java.lang.String name, boolean vrml97, VRMLFieldDeclaration[] fields, int numBodyNodes)
          Create an instance for the proto with the number of fields.
 
Method Summary
 void addNodeListener(VRMLNodeListener l)
          Add a listener to this node instance.
 void allEventsComplete()
          Ignored by this implementation.
protected  int appendField(VRMLFieldDeclaration field)
          Append a field declaration to this node.
 void clearRemovedLayerIds()
          Clear the current removed layer ID list.
protected  void fireFieldChanged(int index)
          Send a notification to the registered listeners that a field has been changed.
 java.util.List getAllFields()
          Make a listing of all fields that are currently registered in this node.
 VRMLNodeType[] getBodyNodes()
          Get the list of all the body nodes in this proto instance.
 boolean getComplete()
          Find out whether this proto is complete and ready to use.
 BasicScene getContainedScene()
          Get the contained scene graph that this instance has.
 int getFieldCount()
          Get the count of the number of fields currently registered.
 VRMLFieldDeclaration getFieldDeclaration(int index)
          Get the declaration of the field at the given index.
 int getFieldIndex(java.lang.String fieldName)
          Get the index of the given field name.
 VRMLFieldData getFieldValue(int index)
          Get the value of a field.
 VRMLNodeType getImplementationNode()
          Get the first node declared in the proto as that defines just how we we can add this into the scenegraph.
 int[] getLayerIds()
          Get a listing of the current layer IDs that are directly or indirectly referencing this node.
 VRMLNodeType getMetadataObject()
          Get the currently registered metadata object instance.
 int[] getNodeFieldIndices()
          Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).
 int getNumFields()
          Get the number of fields defined for this node.
 int getPrimaryType()
          Get the primary type of this node.
 int getRefCount(int layer)
          Ask for the current number of references to this object in the given layer.
 int[] getRemovedLayerIds()
          Get the list of layer IDs that this node has just been removed from.
 int[] getSecondaryType()
          Get the secondary type of this node.
 java.lang.Object getUserData(int index)
          Fetch the stored user data for a given field index.
 java.lang.String getVRMLNodeName()
          Get the name of this node as a string.
 boolean hasFieldChanged(int index)
          Check to see if the given field has changed since we last checked.
 boolean isDEF()
          Check to see if this node has been DEFd.
 boolean isDefaultValue(int index)
          Determine whether the field is a default value or has been set by the proto resolving.
 boolean isSetupFinished()
          Check to see if setupFinished() has already been called on this node.
 void notifyExternProtoLoaded(int index, VRMLNodeType node)
          Notify a node that an ExternProto has resolved.
 void removeNodeListener(VRMLNodeListener l)
          Remove a listener from this node instance.
 void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex)
          Send a routed value from this node to the given destination node.
 void setComplete()
          Denote that this proto is complete and ready to use.
 void setDEF()
          Notify this node that is has been DEFd.
 void setErrorReporter(ErrorReporter reporter)
          Register an error reporter with the engine so that any errors generated by the node's internals can be reported in a nice, pretty fashion.
 void setFrameStateManager(FrameStateManager mgr)
          Set the frame state manager to be used by this proto instance.
 void setMetadataObject(VRMLNodeType data)
          Set the X3DMetadataObject that is associated with this node.
 void setupFinished()
          Notification that the construction phase of this node has finished.
 void setUserData(int index, java.lang.Object data)
          Set arbitrary data for a given field.
 void setValue(int index, boolean value)
          Set the value of the field at the given index as an boolean.
 void setValue(int index, boolean[] value, int numValid)
          Set the value of the field at the given index as an array of booleans.
 void setValue(int index, double value)
          Set the value of the field at the given index as an double.
 void setValue(int index, double[] value, int numValid)
          Set the value of the field at the given index as an array of doubles.
 void setValue(int index, float value)
          Set the value of the field at the given index as a float.
 void setValue(int index, float[] value, int numValid)
          Set the value of the field at the given index as an array of floats.
 void setValue(int index, int value)
          Set the value of the field at the given index as an integer.
 void setValue(int index, int[] value, int numValid)
          Set the value of the field at the given index as an array of integers.
 void setValue(int index, long value)
          Set the value of the field at the given index as an integer.
 void setValue(int index, long[] value, int numValid)
          Set the value of the field at the given index as an array of integers.
 void setValue(int index, java.lang.String value)
          Set the value of the field at the given index as a string.
 void setValue(int index, java.lang.String[] value, int numValid)
          Set the value of the field at the given index as an array of strings.
 void setValue(int index, VRMLNodeType child)
          Set the value of the field at the given index as a node.
 void setValue(int index, VRMLNodeType[] children, int numValid)
          Set the value of the field at the given index as an array of nodes.
 void setVersion(int major, int minor, boolean isStatic)
          Set the version of VRML that this node should represent.
 void updateRefCount(int layer, boolean add)
          Change the reference count up or down by one for a given layer ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BAD_NODE_MSG

protected static final java.lang.String BAD_NODE_MSG
A standard message for when the supplied node is wrong. Just add the node name of the wrong type to the end.

See Also:
Constant Field Values

METADATA_PROTO_MSG

protected static final java.lang.String METADATA_PROTO_MSG
Message for when the proto is not a Metadata

See Also:
Constant Field Values

METADATA_NODE_MSG

protected static final java.lang.String METADATA_NODE_MSG
Message for when the node in setValue() is not a Metadata

See Also:
Constant Field Values

VRML97_FIELD_MSG

protected static final java.lang.String VRML97_FIELD_MSG
Message when the field type is not valid in VRML97

See Also:
Constant Field Values

FIELD_CLASH_MSG

protected static final java.lang.String FIELD_CLASH_MSG
When the same field is defined twice, but with different types

See Also:
Constant Field Values

errorReporter

protected ErrorReporter errorReporter
Reporter instance for handing out errors


isStatic

protected boolean isStatic
Flag for the node being static


vrmlMajorVersion

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


vrmlMinorVersion

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


fieldIndexMap

protected java.util.Map fieldIndexMap
Data mapping holding the field name -> index (Integer) mapping


uniqueFieldIndexMap

protected java.util.Map uniqueFieldIndexMap
Unique version of fieldIndexMap with no exposedField expansions


fieldDeclList

protected java.util.List fieldDeclList
List of the field maps registered in order for their definitions. When created, this list will have a null value in each index position for the size of the number of declared fields. This allows a user to set(int, object) the value if they want.


nodeName

protected final java.lang.String nodeName
The name of this node type


FIELD_METADATA

protected final int FIELD_METADATA
Index of the metadata field


fieldData

protected final VRMLFieldData fieldData
Scratch class var for returning field data


bodyNodes

protected VRMLNodeType[] bodyNodes
The nodes that form the body group


bodyNodeCount

protected int bodyNodeCount
A counter for the number of body nodes


rootNode

protected VRMLNodeType rootNode
The node that describes the type of proto


sceneInfo

protected ProtoScene sceneInfo
Contained scene information


stateManager

protected FrameStateManager stateManager
Frame state manager for this event model instance


proxyNodeMap

protected java.util.HashMap proxyNodeMap
Mapping of an external imported name to the ImportNodeProxy instance


isMap

protected final IntHashMap isMap
The mapping that holds is field index (key) to the list of destination node information. (ProtoFieldInfo - value).


fieldValueMap

protected final IntHashMap fieldValueMap
A map of the field indexes (Integer) to their values (object). Fields using primitive types have these converted to the equivalent Class.


fieldSizeMap

protected final IntHashMap fieldSizeMap
A map of the field indexes (Integer) to the size of the data provided at that field. Used for multi-value fields and represents the number of elements, not the number of raw values.


fieldChangedMap

protected final IntHashMap fieldChangedMap
Map of whether the field index has been changed since last check


isDEF

protected boolean isDEF
Flag indicating this is a DEF node


inSetup

protected boolean inSetup
Flag indicating we are in setup mode currently


isVrml97

protected boolean isVrml97
Flag indicating VRML97 lookup semantics for IS behaviour


lastFieldIndex

protected int lastFieldIndex
The last field index. Used for extern protos that append fields


isListEntry

protected int[] isListEntry
IsList entry to use for sendRoute, the one that triggered the event


refCounts

protected int[] refCounts
The current number of references to this node. This is for informational purposes only and should never be touched by derived classes.


layerIds

protected int[] layerIds
The list of layer IDs that reference this node. Should correspond 1:1 to the counts in refCounts. If none, this is null.


removedLayerIds

protected int[] removedLayerIds
The list of IDs that have been marked as being removed.


completeBody

protected boolean completeBody
Whether the protoBody is complete


vfMetadata

protected VRMLNodeType vfMetadata
SFNode metadata NULL


pMetadata

protected VRMLProtoInstance pMetadata
proto representation of the metadata node

Constructor Detail

CRProtoInstance

protected CRProtoInstance(java.lang.String name,
                          boolean vrml97,
                          VRMLFieldDeclaration[] fields,
                          int numBodyNodes)
Create an instance for the proto with the number of fields. To set the values of these fields, use the normal setValue methods. The fields are list does not care if it contains null values.

Parameters:
name - The node name of the proto
vrml97 - true if this is a VRML97 issue proto
fields - The fields that need to be set here
numBodyNodes - The number of nodes in the body of the proto
Method Detail

getImplementationNode

public VRMLNodeType getImplementationNode()
Get the first node declared in the proto as that defines just how we we can add this into the scenegraph. If this is an empty prototype implementation, or represents an Extern proto that has not been loaded yet then this will return null.

Specified by:
getImplementationNode in interface VRMLProtoInstance
Returns:
The node instance that represents the first node

getBodyNodes

public VRMLNodeType[] getBodyNodes()
Get the list of all the body nodes in this proto instance. Nodes are defined in declaration order. Index 0 is always the same value as that returned by getImplementationNode(). This should be called sparingly. It is really only of use to something that needs to traverse the entire scene graph or for scripting to provide access to the root of the scene.

Specified by:
getBodyNodes in interface VRMLProtoInstance
Returns:
The list of nodes from the body

getFieldCount

public int getFieldCount()
Get the count of the number of fields currently registered.

Specified by:
getFieldCount in interface VRMLProtoInstance
Returns:
The number of fields available

getAllFields

public java.util.List getAllFields()
Make a listing of all fields that are currently registered in this node. The list contains instances of VRMLFieldDeclaration.

Specified by:
getAllFields in interface VRMLProtoInstance
Returns:
A list of the current field declarations

getRefCount

public int getRefCount(int layer)
Ask for the current number of references to this object in the given layer. If this node represents a layer node itself, then the value returned for that ID should always be one. If the layer requested does not have a reference to this node, return zero.

Specified by:
getRefCount in interface VRMLNodeType
Parameters:
layer - The id of the layer to get the ref count for
Returns:
The number of references to this node

updateRefCount

public void updateRefCount(int layer,
                           boolean add)
Change the reference count up or down by one for a given layer ID. If there is no reference to the given layer ID previously, add one now. A listing of the layer IDs that reference this node can be retrieved through getLayerIds().

Specified by:
updateRefCount in interface VRMLNodeType
Parameters:
layer - The id of the layer to modify the ref count on
add - true to increment the reference count, false to decrement

getLayerIds

public int[] getLayerIds()
Get a listing of the current layer IDs that are directly or indirectly referencing this node. If this layer is not part of a live scene graph (eg held by a script code, but not by the script itself) then this will will return a null value. The array will always be exactly equal in length to the number of IDs that reference this node.

Specified by:
getLayerIds in interface VRMLNodeType
Returns:
An array of all the IDs referencing this node or null if none

getRemovedLayerIds

public int[] getRemovedLayerIds()
Get the list of layer IDs that this node has just been removed from. If it currently has not been removed from anything, this will return null. This will remain updated until the next clearRemovedLayerIds() call.

Specified by:
getRemovedLayerIds in interface VRMLNodeType
Returns:
An array of all the IDs this is delete from or null if none

clearRemovedLayerIds

public void clearRemovedLayerIds()
Clear the current removed layer ID list. If there is nothing removed, this method does nothing.

Specified by:
clearRemovedLayerIds in interface VRMLNodeType

setMetadataObject

public void setMetadataObject(VRMLNodeType data)
                       throws InvalidFieldValueException
Set the X3DMetadataObject that is associated with this node.

Specified by:
setMetadataObject in interface VRMLNodeType
Parameters:
data - The node to register as the metadata
Throws:
InvalidFieldValueException - The object instance provided does not implment VRMLMetadataNodeType or is not a proto instance that encapsulates it as it's primary type

getMetadataObject

public VRMLNodeType getMetadataObject()
Get the currently registered metadata object instance. If none is set then return null.

Specified by:
getMetadataObject in interface VRMLNodeType
Returns:
The current metadata object or null

isSetupFinished

public boolean isSetupFinished()
Check to see if setupFinished() has already been called on this node.

Specified by:
isSetupFinished in interface VRMLNodeType
Returns:
true if setupFinished() has been called

setupFinished

public void setupFinished()
Notification that the construction phase of this node has finished. If the node would like to do any internal processing, such as setting up geometry, then go for it now.

Specified by:
setupFinished in interface VRMLNodeType

setFrameStateManager

public void setFrameStateManager(FrameStateManager mgr)
Set the frame state manager to be used by this proto instance. used to pass in information about the contained scene for extern proto handler.

Specified by:
setFrameStateManager in interface VRMLNodeType
Parameters:
mgr - The manager instance to use

allEventsComplete

public void allEventsComplete()
Ignored by this implementation.

Specified by:
allEventsComplete in interface FrameStateListener

setErrorReporter

public void setErrorReporter(ErrorReporter reporter)
Register an error reporter with the engine so that any errors generated by the node's internals 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 VRMLNode
Parameters:
reporter - The instance to use or null

getVRMLNodeName

public java.lang.String getVRMLNodeName()
Get the name of this node as a string.

Specified by:
getVRMLNodeName in interface VRMLNode
Returns:
The name of the node

setVersion

public void setVersion(int major,
                       int minor,
                       boolean isStatic)
Set the version of VRML that this node should represent. Different versions have different capabilities, even within the same node.

Specified by:
setVersion in interface VRMLNode
Parameters:
major - The major version number of this scene
minor - The minor version number of this scene
isStatic - true if this node is under a static group and won't change after the setup is finished

setDEF

public void setDEF()
Notify this node that is has been DEFd. This method shall only be called before setupFinished(). It is an error to call it any other time. It is also guaranteed that this call will be made after construction, but before any of the setValue() methods have been called.

Specified by:
setDEF in interface VRMLNodeType
Throws:
java.lang.IllegalStateException - The setup is finished.

isDEF

public boolean isDEF()
Check to see if this node has been DEFd. Returns true if it has and the user should ask for the shared representation rather than the normal one.

Specified by:
isDEF in interface VRMLNode
Returns:
true if this node has been DEFd

getFieldIndex

public int getFieldIndex(java.lang.String fieldName)
Get the index of the given field name. If the name does not exist for this node then return a value of -1.

Specified by:
getFieldIndex in interface VRMLNode
Parameters:
fieldName - The name of the field we want the index from
Returns:
The index of the field name or -1

getNodeFieldIndices

public int[] getNodeFieldIndices()
Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode). Used for blind scene graph traversal without needing to spend time querying for all fields etc. If a node does not have any fields that contain nodes, this shall return null. The field list covers all field types, regardless of whether they are readable or not at the VRML-level.

Specified by:
getNodeFieldIndices in interface VRMLNode
Returns:
The list of field indices that correspond to SF/MFnode fields or null if none

getFieldDeclaration

public VRMLFieldDeclaration getFieldDeclaration(int index)
Get the declaration of the field at the given index. This allows for reverse lookup if needed. If the field does not exist, this will give a value of null.

Specified by:
getFieldDeclaration in interface VRMLNode
Parameters:
index - The index of the field to get information
Returns:
A representation of this field's information

getNumFields

public int getNumFields()
Get the number of fields defined for this node.

Specified by:
getNumFields in interface VRMLNode
Returns:
The number of fields.

addNodeListener

public void addNodeListener(VRMLNodeListener l)
Add a listener to this node instance. If the listener is already added or null the request is silently ignored.

Specified by:
addNodeListener in interface VRMLNodeType
Parameters:
l - The listener instance to add

removeNodeListener

public void removeNodeListener(VRMLNodeListener l)
Remove a listener from this node instance. If the listener is null or not registered, the request is silently ignored.

Specified by:
removeNodeListener in interface VRMLNodeType
Parameters:
l - The listener to be removed

hasFieldChanged

public boolean hasFieldChanged(int index)
Check to see if the given field has changed since we last checked. Calling this method will set the flag back to "not changed" so that two consective reads after a changed value would result in a true and then false being returned. If the field number is not recognized for this node then this returns false.

For a proto instance, we have to check the IS values and so look at every output node that has output mapped back to this field. We never keep a local flag of the fields stored here.

Specified by:
hasFieldChanged in interface VRMLNodeType
Parameters:
index - The index of the field to change.
Returns:
true if the field has changed since last read

getFieldValue

public VRMLFieldData getFieldValue(int index)
                            throws InvalidFieldException
Get the value of a field. If the field is a primitive type, it will return a class representing the value. For arrays or nodes it will return the instance directly.

Specified by:
getFieldValue in interface VRMLNodeType
Parameters:
index - The index of the field to change.
Returns:
The class representing the field value
Throws:
InvalidFieldException - The field index is not known

getPrimaryType

public int getPrimaryType()
Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.

Specified by:
getPrimaryType in interface VRMLNode
Returns:
The primary type

getSecondaryType

public int[] getSecondaryType()
Get the secondary type of this node. Replaces the instanceof mechanism for use in switch statements. For protos, the secondary type is described as the primary type of the defining node type.

Specified by:
getSecondaryType in interface VRMLNode
Returns:
The secondary type

notifyExternProtoLoaded

public void notifyExternProtoLoaded(int index,
                                    VRMLNodeType node)
                             throws InvalidFieldValueException
Notify a node that an ExternProto has resolved. This will verify the objects type and add it to the render sceneGraph.

Specified by:
notifyExternProtoLoaded in interface VRMLNodeType
Parameters:
index - The field index
node - The node resolved
Throws:
InvalidFieldValueException - If the proto contains he wrong type

sendRoute

public void sendRoute(double time,
                      int srcIndex,
                      VRMLNodeType destNode,
                      int destIndex)
Send a routed value from this node to the given destination node. The route should use the appropriate setValue() method of the destination node. It should not attempt to cast the node up to a higher level. Routing should also follow the standard rules for the loop breaking and other appropriate rules for the specification.

Specified by:
sendRoute in interface VRMLNodeType
Parameters:
time - The time that this route occurred (not necessarily epoch time. Should be treated as a relative value only)
srcIndex - The index of the field in this node that the value should be sent from
destNode - The node reference that we will be sending the value to
destIndex - The index of the field in the destination node that the value should be sent to.

setValue

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

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     int[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
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:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     long value)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an integer. This would be used to set SFLong field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     long[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an array of integers. This would be used to set MFLong field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     boolean value)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an boolean. This would be used to set SFBool field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The field index is not know
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     boolean[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an array of booleans. This would be used to set MFBool field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The field index is not know
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     float value)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as a float. This would be used to set SFFloat field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     float[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
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:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     double value)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an double. This would be used to set SFDouble field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     double[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
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:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     java.lang.String value)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as a string. This would be used to set SFString field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     java.lang.String[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
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:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     VRMLNodeType child)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as a node. This would be used to set SFNode field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
child - The new value to use for the node
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

setValue

public void setValue(int index,
                     VRMLNodeType[] children,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException
Set the value of the field at the given index as an array of nodes. This would be used to set MFNode field types.

Specified by:
setValue in interface VRMLNodeType
Parameters:
index - The index of destination field to set
children - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range for the field type.

getContainedScene

public BasicScene getContainedScene()
Get the contained scene graph that this instance has. This represents everything about the internal scene that the node declaration wraps. This is a real-time representation so that if it the nodes contains a script that changes the internal representation then this instance will be updated to reflect and changes made.

Specified by:
getContainedScene in interface VRMLExecutionSpace
Returns:
The scene contained by this node instance

appendField

protected int appendField(VRMLFieldDeclaration field)
                   throws FieldExistsException
Append a field declaration to this node. This is added to the current list on the end. If the field already exists with the given name but different values exception will be generated. If the field has exactly the same signature it will silently ignore the request.

Parameters:
field - The new field to add
Returns:
The index that this field was added at
Throws:
FieldExistsException - A conflicting field of the same name already exists for this node

setComplete

public void setComplete()
Denote that this proto is complete and ready to use. Extern protos and local protos resolve completeness differently so this cannot be in the finishCreate method.


getComplete

public boolean getComplete()
Find out whether this proto is complete and ready to use.

Returns:
Is the proto ready to use?

setUserData

public void setUserData(int index,
                        java.lang.Object data)
                 throws InvalidFieldException
Set arbitrary data for a given field. Provided primarily to help the EAI fullfil its requirements, but may be useful elsewhere.

Specified by:
setUserData in interface VRMLNode
Parameters:
index - The index of destination field to set
data - The item to store for the field
Throws:
InvalidFieldException - The field index is not known

getUserData

public java.lang.Object getUserData(int index)
                             throws InvalidFieldException
Fetch the stored user data for a given field index. If nothing is registered, null is returned.

Specified by:
getUserData in interface VRMLNode
Parameters:
index - The index of destination field to set
Returns:
The item stored for the field or null
Throws:
InvalidFieldException - The field index is not known

isDefaultValue

public boolean isDefaultValue(int index)
                       throws InvalidFieldException
Determine whether the field is a default value or has been set by the proto resolving.

Parameters:
index - The index of the field to change.
Returns:
Is it a default value
Throws:
InvalidFieldException - The field index is not known

fireFieldChanged

protected void fireFieldChanged(int index)
Send a notification to the registered listeners that a field has been changed. If no listeners have been registered, then this does nothing, so always call it regardless.

Parameters:
index - The index of the field that changed

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium