|
Xj3D VRML/X3D Code API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.web3d.vrml.renderer.CRProtoInstance
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.
| 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 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 |
refCount
The current number of references to this node. |
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. |
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. |
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. |
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()
Ask for the current number of references to this object. |
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 |
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. |
int |
updateRefCount(boolean add)
Change the reference count up or down by one. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final java.lang.String BAD_NODE_MSG
protected static final java.lang.String METADATA_PROTO_MSG
protected static final java.lang.String METADATA_NODE_MSG
protected static final java.lang.String VRML97_FIELD_MSG
protected static final java.lang.String FIELD_CLASH_MSG
protected ErrorReporter errorReporter
protected boolean isStatic
protected int vrmlMajorVersion
protected int vrmlMinorVersion
protected java.util.Map fieldIndexMap
protected java.util.Map uniqueFieldIndexMap
protected java.util.List fieldDeclList
protected final java.lang.String nodeName
protected final int FIELD_METADATA
protected final VRMLFieldData fieldData
protected VRMLNodeType[] bodyNodes
protected int bodyNodeCount
protected VRMLNodeType rootNode
protected ProtoScene sceneInfo
protected FrameStateManager stateManager
protected java.util.HashMap proxyNodeMap
protected final IntHashMap isMap
protected final IntHashMap fieldValueMap
protected final IntHashMap fieldSizeMap
protected final IntHashMap fieldChangedMap
protected boolean isDEF
protected boolean inSetup
protected boolean isVrml97
protected int lastFieldIndex
protected int[] isListEntry
protected int refCount
protected boolean completeBody
protected VRMLNodeType vfMetadata
protected VRMLProtoInstance pMetadata
| Constructor Detail |
protected CRProtoInstance(java.lang.String name,
boolean vrml97,
VRMLFieldDeclaration[] fields,
int numBodyNodes)
name - The node name of the protovrml97 - true if this is a VRML97 issue protofields - The fields that need to be set herenumBodyNodes - The number of nodes in the body of the proto| Method Detail |
public VRMLNodeType getImplementationNode()
getImplementationNode in interface VRMLProtoInstancepublic int getFieldCount()
getFieldCount in interface VRMLProtoInstancepublic java.util.List getAllFields()
VRMLFieldDeclaration.
getAllFields in interface VRMLProtoInstancepublic int getRefCount()
getRefCount in interface VRMLNodeTypepublic int updateRefCount(boolean add)
updateRefCount in interface VRMLNodeTypeadd - true to increment the reference count, false to decrement
public void setMetadataObject(VRMLNodeType data)
throws InvalidFieldValueException
setMetadataObject in interface VRMLNodeTypedata - The node to register as the metadata
InvalidFieldValueException - The object instance provided
does not implment VRMLMetadataNodeType or is not a proto instance
that encapsulates it as it's primary typepublic VRMLNodeType getMetadataObject()
getMetadataObject in interface VRMLNodeTypepublic boolean isSetupFinished()
isSetupFinished in interface VRMLNodeTypepublic void setupFinished()
setupFinished in interface VRMLNodeTypepublic void setFrameStateManager(FrameStateManager mgr)
setFrameStateManager in interface VRMLNodeTypemgr - The manager instance to usepublic void allEventsComplete()
allEventsComplete in interface FrameStateListenerpublic void setErrorReporter(ErrorReporter reporter)
setErrorReporter in interface VRMLNodereporter - The instance to use or nullpublic java.lang.String getVRMLNodeName()
getVRMLNodeName in interface VRMLNode
public void setVersion(int major,
int minor,
boolean isStatic)
setVersion in interface VRMLNodemajor - The major version number of this sceneminor - The minor version number of this sceneisStatic - true if this node is under a static group and won't
change after the setup is finishedpublic void setDEF()
setDEF in interface VRMLNodeTypejava.lang.IllegalStateException - The setup is finished.public boolean isDEF()
isDEF in interface VRMLNodepublic int getFieldIndex(java.lang.String fieldName)
getFieldIndex in interface VRMLNodefieldName - The name of the field we want the index from
public int[] getNodeFieldIndices()
getNodeFieldIndices in interface VRMLNodepublic VRMLFieldDeclaration getFieldDeclaration(int index)
getFieldDeclaration in interface VRMLNodeindex - The index of the field to get information
public int getNumFields()
getNumFields in interface VRMLNodepublic void addNodeListener(VRMLNodeListener l)
addNodeListener in interface VRMLNodeTypel - The listener instance to addpublic void removeNodeListener(VRMLNodeListener l)
removeNodeListener in interface VRMLNodeTypel - The listener to be removedpublic boolean hasFieldChanged(int index)
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.
hasFieldChanged in interface VRMLNodeTypeindex - The index of the field to change.
public VRMLFieldData getFieldValue(int index)
throws InvalidFieldException
getFieldValue in interface VRMLNodeTypeindex - The index of the field to change.
InvalidFieldException - The field index is not knownpublic int getPrimaryType()
getPrimaryType in interface VRMLNodepublic int[] getSecondaryType()
getSecondaryType in interface VRMLNode
public void notifyExternProtoLoaded(int index,
VRMLNodeType node)
throws InvalidFieldValueException
notifyExternProtoLoaded in interface VRMLNodeTypeindex - The field indexnode - The node resolved
InvalidFieldValueException - If the proto contains he wrong type
public void sendRoute(double time,
int srcIndex,
VRMLNodeType destNode,
int destIndex)
sendRoute in interface VRMLNodeTypetime - 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.
public void setValue(int index,
int value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
int[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
long value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
long[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
boolean value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The field index is not know
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
boolean[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The field index is not know
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
float value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
float[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
double value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
double[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
java.lang.String value)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setvalue - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
java.lang.String[] value,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
VRMLNodeType child)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - The index of destination field to setchild - The new value to use for the node
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.
public void setValue(int index,
VRMLNodeType[] children,
int numValid)
throws InvalidFieldException,
InvalidFieldValueException
setValue in interface VRMLNodeTypeindex - 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
InvalidFieldException - The index does not match a known field
InvalidFieldValueException - The value provided is out of range
for the field type.public BasicScene getContainedScene()
getContainedScene in interface VRMLExecutionSpace
protected int appendField(VRMLFieldDeclaration field)
throws FieldExistsException
field - The new field to add
FieldExistsException - A conflicting field of the same name
already exists for this nodepublic void setComplete()
public boolean getComplete()
public void setUserData(int index,
java.lang.Object data)
throws InvalidFieldException
setUserData in interface VRMLNodeindex - The index of destination field to setdata - The item to store for the field
InvalidFieldException - The field index is not known
public java.lang.Object getUserData(int index)
throws InvalidFieldException
getUserData in interface VRMLNodeindex - The index of destination field to set
InvalidFieldException - The field index is not knownprotected void fireFieldChanged(int index)
index - The index of the field that changed
|
Xj3D VRML/X3D Code API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||