Class BaseScript
java.lang.Object
org.web3d.vrml.renderer.common.nodes.AbstractDynamicFieldNode
org.web3d.vrml.renderer.common.nodes.scripting.BaseScript
- All Implemented Interfaces:
VRMLNode
,FrameStateListener
,VRMLChildNodeType
,VRMLExternalNodeType
,VRMLNodeType
,VRMLScriptNodeType
,VRMLSingleExternalNodeType
,VRMLWorldRootChildNodeType
Scene graph representation of a script node.
The script is different to all the other nodes. While it represents a script, it doesn't have the normal content of a Java3D node. It is also a bit different to the ordinary Abstract node implementation in that a script can have fields added and removed on demand.
- Version:
- $Revision: 1.52 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The major version of the spec this instance belongs to.protected int
The minor version of the spec this instance belongs to.Fields inherited from class org.web3d.vrml.renderer.common.nodes.AbstractDynamicFieldNode
BAD_NODE_MSG, errorReporter, FIELD_CLASH_MSG, fieldCount, fieldDeclList, fieldIndexMap, fieldLocalData, inSetup, isVrml97, layerIds, METADATA_NODE_MSG, METADATA_PROTO_MSG, nodeName, pMetadata, refCounts, removedLayerIds, stateManager, vfMetadata
Fields inherited from interface org.web3d.vrml.nodes.VRMLExternalNodeType
LOAD_COMPLETE, LOAD_FAILED, LOADING, NOT_LOADED
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Construct a default instance of the scriptprotected
BaseScript
(VRMLNodeType node) Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener to this node instance for the content state changes.void
Add a listener to this node instance.final int
appendField
(VRMLFieldDeclaration field) Append a field declaration to this node.boolean
checkValidContentType
(String mimetype) Check to see if the given MIME type is one that would be supported as content coming into this node.protected final void
copy
(BaseScript node) Copy this node into the given node.void
Notification by the route manager that an event cascade is complete.protected void
Send a notification to the registered listeners that the content state has been changed.protected void
Send a notification to the registered listeners that a field has been changed.Get the execution space that this script is operating under.getFieldValue
(int index) Get the value of a field.int
Ask the state of the load of this node.int
Get the primary type of this node.int[]
Get the secondary type of this node.String[]
getUrl()
Get the list of URLs requested by this node.getUserData
(int index) Fetch the stored user data for a given field index.Get the world URL so set for this node.boolean
hasFieldChanged
(int index) Check to see if the given field has changed since we last checked.void
initialize
(double timestamp) Notification that the script can now call the initialize() method on the user script code.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
prepareEvents
(double timestamp) Notification to call the prepare-events for scripts at the start of the timestamp.void
Notification by the route manager that an event cascade is complete.void
Remove a listener from this node instance for the content state changes.void
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
setContent
(String mimetype, Object content) Set the content of this node to the given object.void
setDEF()
Notify this node that is has been DEFd.void
Set the execution space to be this new value.void
setLoadedURI
(String uri) Notify the node which URL was used to load the content.void
setLoadState
(int state) Set the load state of the node.void
Notification that the construction phase of this node has finished.void
Replace the existing set of URLs with this new set.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 boolean.void
setValue
(int index, boolean[] value, int numValid) Set the value of the field at the given index as an array of boolean.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
setWorldUrl
(String url) Set the world URL so that any relative URLs may be corrected to the fully qualified version.void
shutdown()
Call shutdown on the user content now.void
Completely shutdown this script node.Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractDynamicFieldNode
addNodeListener, allEventsComplete, checkNodeType, clearRemovedLayerIds, deleteField, deleteField, fireFieldChanged, getAllFields, getFieldCount, getFieldDeclaration, getFieldIndex, getLayerIds, getMetadataObject, getNodeFieldIndices, getNumFields, getRefCount, getRemovedLayerIds, getVRMLNodeName, isVRML97, removeNodeListener, setErrorReporter, setFrameStateManager, setMetadataObject, updateRefCount
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.nodes.FrameStateListener
allEventsComplete
Methods inherited from interface org.web3d.vrml.lang.VRMLNode
getFieldDeclaration, getFieldIndex, getNodeFieldIndices, getNumFields, getVRMLNodeName, setErrorReporter
Methods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, clearRemovedLayerIds, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, removeNodeListener, setFrameStateManager, setMetadataObject, updateRefCount
Methods inherited from interface org.web3d.vrml.nodes.VRMLScriptNodeType
getAllFields, getFieldCount
-
Field Details
-
majorVersion
protected int majorVersionThe major version of the spec this instance belongs to. -
minorVersion
protected int minorVersionThe minor version of the spec this instance belongs to.
-
-
Constructor Details
-
BaseScript
protected BaseScript()Construct a default instance of the script -
BaseScript
Construct a new instance of this node based on the details from the given node. If the node is not a group node, an exception will be thrown. It does not copy the children nodes, just this node.- Parameters:
node
- The node to copy- Throws:
IllegalArgumentException
- The node is not a Group node
-
-
Method Details
-
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
-
setUrl
Replace the existing set of URLs with this new set. If the array is null or zero length, it will clear the existing values.- Specified by:
setUrl
in interfaceVRMLSingleExternalNodeType
- Parameters:
newUrl
- The list of new instances to usenumValid
- number of valid items to use from the size array
-
getUrl
Get the list of URLs requested by this node. If there are no URLs supplied in the text file then this will return a zero length array.- Specified by:
getUrl
in interfaceVRMLSingleExternalNodeType
- Returns:
- The list of URLs to attempt to load
-
getLoadState
public int getLoadState()Ask the state of the load of this node. The value will be one of the constants defined above.- Specified by:
getLoadState
in interfaceVRMLSingleExternalNodeType
- Returns:
- The current load state of the node
-
setLoadState
public void setLoadState(int state) Set the load state of the node. The value must be one of the constants defined above.- Specified by:
setLoadState
in interfaceVRMLSingleExternalNodeType
- Parameters:
state
- The new state of the node
-
setWorldUrl
Set the world URL so that any relative URLs may be corrected to the fully qualified version. Guaranteed to be non-null.- Specified by:
setWorldUrl
in interfaceVRMLExternalNodeType
- Parameters:
url
- The world URL.
-
getWorldUrl
Get the world URL so set for this node.- Specified by:
getWorldUrl
in interfaceVRMLExternalNodeType
- Returns:
- url The world URL.
-
setContent
Set the content of this node to the given object. The object is then cast by the internal representation to the form it needs. This assumes at least some amount of intelligence on the part of the caller, but we also know that we should not pass something dumb to it when we can check what sort of content types it likes to handle. We assume the loader thread is operating in the same context as the one that created the node in the first place and thus knows the general types of items to pass through.- Specified by:
setContent
in interfaceVRMLSingleExternalNodeType
- Parameters:
mimetype
- The mime type of this object if knowncontent
- The content of the object- Throws:
IllegalArgumentException
- The content object is not supported
-
setLoadedURI
Notify the node which URL was used to load the content. It will be the complete URI with path, query and references parts. This method will be called before setContent.- Specified by:
setLoadedURI
in interfaceVRMLSingleExternalNodeType
- Parameters:
uri
- The URI used to load this content
-
addUrlListener
Add a listener to this node instance. If the listener is already added or null the request is silently ignored.- Specified by:
addUrlListener
in interfaceVRMLExternalNodeType
- Parameters:
ul
- The listener instance to add
-
removeUrlListener
Remove a listener from this node instance. If the listener is null or not registered, the request is silently ignored.- Specified by:
removeUrlListener
in interfaceVRMLExternalNodeType
- Parameters:
ul
- The listener to be removed
-
addContentStateListener
Add a listener to this node instance for the content state changes. If the listener is already added or null the request is silently ignored.- Specified by:
addContentStateListener
in interfaceVRMLExternalNodeType
- Parameters:
l
- The listener instance to add
-
removeContentStateListener
Remove a listener from this node instance for the content state changes. If the listener is null or not registered, the request is silently ignored.- Specified by:
removeContentStateListener
in interfaceVRMLExternalNodeType
- Parameters:
l
- The listener to be removed
-
setExecutionSpace
Set the execution space to be this new value. Usually set at some time after the initial loading of the class, but before content is set. A value of null will clear the current space.- Specified by:
setExecutionSpace
in interfaceVRMLScriptNodeType
- Parameters:
space
- The space that this script is operating in
-
getExecutionSpace
Get the execution space that this script is operating under. If there is none, this will return null.- Specified by:
getExecutionSpace
in interfaceVRMLScriptNodeType
- Returns:
- The current execution space or null
-
initialize
public void initialize(double timestamp) Notification that the script can now call the initialize() method on the user script code. If this is called accidentally when there is no user code set, silently ignore the request.- Specified by:
initialize
in interfaceVRMLScriptNodeType
- Parameters:
timestamp
- The VRML time that the initialization occurred at
-
prepareEvents
public void prepareEvents(double timestamp) Notification to call the prepare-events for scripts at the start of the timestamp. For scripts that are in an X3D world, this will also call the prepareEvents SAI service. This method will be called every frame.- Specified by:
prepareEvents
in interfaceVRMLScriptNodeType
- Parameters:
timestamp
- The time of the current frame in VRML time
-
processEvents
public void processEvents()Notification by the route manager that an event cascade is complete. This should allow the underlying scripting engine to callprocessEvents()
(or equivalent) on the script code.- Specified by:
processEvents
in interfaceVRMLScriptNodeType
-
eventsProcessed
public void eventsProcessed()Notification by the route manager that an event cascade is complete. This should allow the underlying scripting engine to calleventsProcessed()
on the script code.- Specified by:
eventsProcessed
in interfaceVRMLScriptNodeType
-
shutdown
public void shutdown()Call shutdown on the user content now. It will no longer be needed. This does not shut down the entire node. It is assumed that content will be forthcoming shortly.- Specified by:
shutdown
in interfaceVRMLScriptNodeType
-
shutdownAll
public void shutdownAll()Completely shutdown this script node. There's no life left in this one so might as well clean up everything. The user code shutdown will be guaranteed to be called before this method.- Specified by:
shutdownAll
in interfaceVRMLScriptNodeType
-
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
- Overrides:
setupFinished
in classAbstractDynamicFieldNode
-
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.
-
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. An eventOut does not have field data available. This is neither an exceptional condition, nor something that should return valid data. Therefore the method returns null if you ask for the value of an eventOut.- Specified by:
getFieldValue
in interfaceVRMLNodeType
- Parameters:
index
- The index of the field to change.- Returns:
- The class representing the field value or null for eventOuts
- Throws:
InvalidFieldException
- The field index is not known
-
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 consecutive 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.- Specified by:
hasFieldChanged
in interfaceVRMLNodeType
- Parameters:
index
- The index of the field to change.- Returns:
- true if the field has changed since last read
-
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
- 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
-
sendRoute
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 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 boolean. 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 boolean. 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.
-
isDEF
-
checkValidContentType
Check to see if the given MIME type is one that would be supported as content coming into this node. This shouldn't be called because it is handled by the script engines, but make a reasonable-pass guess at this anyway based on the set of all types supported.- Specified by:
checkValidContentType
in interfaceVRMLSingleExternalNodeType
- Parameters:
mimetype
- The type to check for- Returns:
- true if this is OK, false if not
-
appendField
public final int appendField(VRMLFieldDeclaration field) throws FieldExistsException, InvalidFieldException Append a field declaration to this node. Overrides the base class to check for eventIns and eventOuts and making sure they have a valid default value.- Specified by:
appendField
in interfaceVRMLScriptNodeType
- Overrides:
appendField
in classAbstractDynamicFieldNode
- 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 nodeInvalidFieldException
-
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
-
setUserData
Set arbitrary data for a given field. Provided primarily to help the EAI fulfills 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
-
copy
Copy this node into the given node. Used as the basis of a copy constructor. A set of field names to ignore is included so that scripts can make use of this method without extra work.- Parameters:
node
- The node that is being copied
-
fireUrlChanged
protected void fireUrlChanged()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. -
fireContentStateChanged
protected void fireContentStateChanged()Send a notification to the registered listeners that the content state has been changed. If no listeners have been registered, then this does nothing, so always call it regardless.
-