Package org.web3d.vrml.nodes.proto
Class ProtoInstancePlaceHolder
java.lang.Object
org.web3d.vrml.nodes.proto.AbstractProto
org.web3d.vrml.nodes.proto.ProtoInstancePlaceHolder
- All Implemented Interfaces:
VRMLExecutionSpace
,VRMLNode
,VRMLNodeTemplate
,FrameStateListener
,VRMLNodeType
,VRMLProtoInstance
A placeholder instance of a Prototype used when declaring and then using a
nested proto instance.
The idea of this class is to fake being a real prototype instance when the code stubs a nested proto instance. A nested proto instance is of the form
PROTO Outer [] { PROTO Inner [] { Box {} } Inner {} }In this case, when we are storing the definition of
Inner
then we
really don't want to expand the internal prototype definition at this point.
The expansion should only take place when we create an instance of
Outer
. This class is used as a placeholder in this definition
for this scenario. The idea is that when the code is traversing the
definition, it will be replaced by a real runtime version.- Version:
- $Revision: 1.45 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int[]
The list of layer IDs that reference this node.protected int[]
The current number of references to this node.Fields inherited from class org.web3d.vrml.nodes.proto.AbstractProto
BAD_NODE_MSG, errorReporter, FIELD_CLASH_MSG, fieldDeclList, fieldIndexMap, fieldLocalData, isVrml97, nodeName, protoCreator, VRML97_FIELD_MSG, vrmlMajorVersion, vrmlMinorVersion
-
Constructor Summary
ConstructorsConstructorDescriptionProtoInstancePlaceHolder
(VRMLNodeTemplate proto, int major, int minor, boolean staticNodes, NodeTemplateToInstanceCreator creator) Create a new instance place holder that represents the given proto declaration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Ignored by this implementation.void
Clear the current removed layer ID list.createNewInstance
(VRMLNode root, boolean isStatic) Create a new instance of a real node from this template.Get the list of all the body nodes in this proto instance.Get the contained scene graph that this instance has.getFieldValue
(int index) Get the value of a field.Get the first node declared in the proto as that defines just how we we can add this into the scene graph.int[]
Get a listing of the current layer IDs that are directly or indirectly referencing this node.Get the currently registered metadata object instance.int[]
Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).int
Get the primary type of this node.Get the PROTO/EXTERNPROTO definition used by this place holder.int
getRefCount
(int layer) Ask for the current number of references to this object in the given layer.int[]
Get the list of layer IDs that this node has just been removed from.int[]
Get the secondary type of this node.getUserData
(int index) Fetch the stored user data for a given field index.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
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
sendRoute
(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.void
setDEF()
Notify this node that is has been DEFd.void
Ignored by this implementation.void
Set the X3DMetadataObject that is associated with this node.void
Notification that the construction phase of this node has finished.void
setUserData
(int index, 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 booleaneger.void
setValue
(int index, boolean[] value, int numValid) Set the value of the field at the given index as an array of booleanegers.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 long.void
setValue
(int index, long[] value, int numValid) Set the value of the field at the given index as an array of longs.void
Set the value of the field at the given index as a string.void
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 org.web3d.vrml.nodes.proto.AbstractProto
addNodeListener, appendField, checkNodeType, deleteField, deleteField, fireFieldChanged, getAllFields, getFieldCount, getFieldDeclaration, getFieldIndex, getNumFields, getVRMLNodeName, isVRML97, removeNodeListener, setErrorReporter
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.VRMLNode
getFieldDeclaration, getFieldIndex, getNumFields, getVRMLNodeName, setErrorReporter
Methods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, removeNodeListener
Methods inherited from interface org.web3d.vrml.nodes.VRMLProtoInstance
getAllFields, getFieldCount
-
Field Details
-
refCounts
protected int[] refCountsThe current number of references to this node. This is for informational purposes only and should never be touched by derived classes. -
layerIds
protected int[] layerIdsThe list of layer IDs that reference this node. Should correspond 1:1 to the counts inrefCounts
. If none, this is null.
-
-
Constructor Details
-
ProtoInstancePlaceHolder
public ProtoInstancePlaceHolder(VRMLNodeTemplate proto, int major, int minor, boolean staticNodes, NodeTemplateToInstanceCreator creator) Create a new instance place holder that represents the given proto declaration.- Parameters:
proto
- The prototype declaration to base this placeholder onmajor
- The major version number of this sceneminor
- The minor version number of this scenestaticNodes
- Whether this node is will be modifiedcreator
- The node creator for generating instances of ourself
-
-
Method Details
-
createNewInstance
Create a new instance of a real node from this template. This will ensure that all the internals are created as needed, based on the current state of the node. Note that sometimes, creating an instance of this template may result in an invalid node construction. Cases where this could occur is when there's no node definition yet loaded or that the loaded definition does not match this template.- Specified by:
createNewInstance
in interfaceVRMLNodeTemplate
- Parameters:
root
- The node that represents the root node of the VRMLExecutionSpace that we're in.isStatic
- true if this is created within a StaticGroup- Returns:
- A new node instance from this template
- Throws:
InvalidNodeTypeException
- The root node is not a node capable of representing a root of a scene graph- See Also:
-
getImplementationNode
Get the first node declared in the proto as that defines just how we we can add this into the scene graph. 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 interfaceVRMLProtoInstance
- Returns:
- The node instance that represents the first node
-
getProtoDefinition
Get the PROTO/EXTERNPROTO definition used by this place holder.- Returns:
- The proto definition used by the node
-
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 bygetImplementationNode()
. 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 interfaceVRMLProtoInstance
- Returns:
- The list of nodes from the body
-
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 interfaceVRMLExecutionSpace
- Returns:
- The scene contained by this node instance
-
allEventsComplete
public void allEventsComplete()Ignored by this implementation.- Specified by:
allEventsComplete
in interfaceFrameStateListener
-
notifyExternProtoLoaded
Description copied from interface:VRMLNodeType
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 interfaceVRMLNodeType
- Parameters:
index
- The field indexnode
- The node resolved- Throws:
InvalidFieldValueException
- If the proto contains he wrong type
-
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 interfaceVRMLNodeType
- 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 throughgetLayerIds()
.- Specified by:
updateRefCount
in interfaceVRMLNodeType
- Parameters:
layer
- The id of the layer to modify the ref count onadd
- 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 interfaceVRMLNodeType
- 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 nextclearRemovedLayerIds()
call.- Specified by:
getRemovedLayerIds
in interfaceVRMLNodeType
- 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 interfaceVRMLNodeType
-
setFrameStateManager
Ignored by this implementation.- Specified by:
setFrameStateManager
in interfaceVRMLNodeType
- Parameters:
mgr
- The manager instance to use
-
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 interfaceVRMLNodeType
- Throws:
IllegalStateException
- The setup is finished.
-
isDEF
-
getPrimaryType
public int getPrimaryType()Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getPrimaryType
in interfaceVRMLNode
- Specified by:
getPrimaryType
in interfaceVRMLNodeTemplate
- Returns:
- The primary type
-
getSecondaryType
public int[] getSecondaryType()Get the secondary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getSecondaryType
in interfaceVRMLNode
- Returns:
- The secondary type
-
hasFieldChanged
public boolean hasFieldChanged(int index) Check to see if the given field has changed since we last checked. Always returns false as this is a placeholder node, not a runtime version.- Specified by:
hasFieldChanged
in interfaceVRMLNodeType
- Parameters:
index
- The index of the field to change.- Returns:
- true if the field has changed since last read
-
getNodeFieldIndices
public int[] getNodeFieldIndices()Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode). Empty for the proto body group node.- Specified by:
getNodeFieldIndices
in interfaceVRMLNode
- Returns:
- null
-
getFieldValue
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 interfaceVRMLNodeType
- Parameters:
index
- The index of the field to change.- Returns:
- The class representing the field value
- Throws:
InvalidFieldException
- The field index is not known
-
setMetadataObject
Set the X3DMetadataObject that is associated with this node. Ignored because proto body nodes don't take metadata.- Specified by:
setMetadataObject
in interfaceVRMLNodeType
- 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
Get the currently registered metadata object instance. If none is set then return null. Ignored because because proto body nodes don't take metadata.- Specified by:
getMetadataObject
in interfaceVRMLNodeType
- Returns:
- The current metadata object or null
-
sendRoute
Send a routed value from this node to the given destination node. This method always does nothing as it is a placeholder only, not a runtime class.- Specified by:
sendRoute
in interfaceVRMLNodeType
- 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 fromdestNode
- The node reference that we will be sending the value todestIndex
- The index of the field in the destination node that the value should be sent to.
-
setValue
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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 booleaneger. This would be used to set SFBool field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 booleanegers. This would be used to set MFBool field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 long. This would be used to set SFTime field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 longs. This would be used to set MFTime field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
setValue
public void setValue(int index, 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
setValue
public void setValue(int index, 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setchild
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- 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 interfaceVRMLNodeType
- Parameters:
index
- The index of destination field to setchildren
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The field index is not knownInvalidFieldValueException
- The value provided is out of range for the field type.
-
setUserData
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 interfaceVRMLNode
- Parameters:
index
- The index of destination field to setdata
- The item to store for the field- Throws:
InvalidFieldException
- The field index is not known
-
getUserData
Fetch the stored user data for a given field index. If nothing is registered, null is returned.- Specified by:
getUserData
in interfaceVRMLNode
- 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
-
isSetupFinished
public boolean isSetupFinished()Check to see if setupFinished() has already been called on this node.- Specified by:
isSetupFinished
in interfaceVRMLNodeType
- 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 interfaceVRMLNodeType
-
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 interfaceVRMLNode
- Parameters:
major
- The major version number of this sceneminor
- The minor version number of this sceneisStatic
- true if this node is under a StaticGroup and won't change after the setup is finished
-