Xj3D VRML/X3D Code API

org.web3d.vrml.scripting.sai
Class BaseExecutionContext

java.lang.Object
  extended byorg.web3d.vrml.scripting.sai.BaseExecutionContext
All Implemented Interfaces:
X3DExecutionContext

public class BaseExecutionContext
extends java.lang.Object
implements X3DExecutionContext

X3DExecutionContext implementation that is used for Protos and the base of a X3DScene.

Version:
$Revision: 1.18 $
Author:
Justin Couch

Field Summary
protected  ComponentInfo[] components
          The list of components in use
protected  int encoding
          The encoding type constant
protected  ErrorReporter errorReporter
          Class that represents the external reporter
protected  VRMLExecutionSpace executionSpace
          The execution space that this context works in
protected  X3DExternProtoDeclaration[] externprotos
          The list of extern protos declared
protected  java.util.ArrayList nodeWrapperList
          Listing of all the valid X3DNode wrappers.
protected  java.util.HashMap nodeWrapperMap
          Mapping of the VRMLNodeType to its X3DNode wrapper
protected  ProfileInfo profile
          The list of profiles in use
protected  X3DProtoDeclaration[] protos
          The array of protos declared
protected  org.web3d.vrml.scripting.sai.BaseNode[] rootNodes
          Listing of root nodes
protected  RouteManager routeManager
          Route manager for handling user added/removed routes
protected  X3DRoute[] routes
          The list of routes in use
protected  java.util.HashMap routeWrapperMap
          Mapping of the ROUTE to its X3DRoute wrapper
protected  BasicScene scene
          The basic scene type
protected  java.lang.String specVersion
          The version of the specification represented
protected  FrameStateManager stateManager
          FrameState manager for creating nodes
protected  java.lang.String url
          The world URL
 
Fields inherited from interface org.web3d.x3d.sai.X3DExecutionContext
ASCII_ENCODING, BIFS_ENCODING, BINARY_ENCODING, LAST_STD_ENCODING, NO_SCENE, SCRIPTED_ENCODING, VRML_ENCODING, XML_ENCODING
 
Constructor Summary
BaseExecutionContext(VRMLExecutionSpace space, RouteManager rm, FrameStateManager fsm, ProfileInfo profile, ComponentInfo[] components, java.lang.ref.ReferenceQueue refQueue, FieldFactory fac, org.web3d.vrml.scripting.sai.FieldAccessListener fal)
          Construct an execution context descriptor for the given information.
BaseExecutionContext(VRMLExecutionSpace space, RouteManager rm, FrameStateManager fsm, ProfileInfo profile, java.lang.ref.ReferenceQueue refQueue, FieldFactory fac, org.web3d.vrml.scripting.sai.FieldAccessListener fal)
          Construct an execution context descriptor for the given information.
 
Method Summary
 X3DRoute addRoute(X3DNode fromX3DNode, java.lang.String readableField, X3DNode toX3DNode, java.lang.String writableField)
          Add a route in this scene.
 X3DNode createNode(java.lang.String name)
          Create a new node in this scene.
 X3DProtoInstance createProto(java.lang.String name)
          Create a new proto instance in this scene.
 ComponentInfo[] getComponents()
          Get the list of all the components declared in the scene.
 int getEncoding()
          Get the encoding of the original file type.
 X3DExternProtoDeclaration getExternProtoDeclaration(java.lang.String name)
          Get the EXTERNPROTO declaration representing the given name.
 java.lang.String[] getExternProtoNames()
          Get the list of EXTERNPROTOs declared in this scene.
 X3DNode getImportedNode(java.lang.String name)
          Get the imported node instance represented by a given name.
 X3DNode getNamedNode(java.lang.String name)
          Get the node instance represented by the given name.
 java.lang.String[] getNamedNodes()
          Get a list of the nodes that have been named with DEF or keyword in this scene.
 ProfileInfo getProfile()
          Get the name of the profile used by this scene.
 X3DProtoDeclaration getProtoDeclaration(java.lang.String name)
          Get the PROTO declaration representing the given name.
 java.lang.String[] getProtosNames()
          Get the list of ordinary PROTO's declared in this scene.
 X3DNode[] getRootNodes()
          Get the list of current root nodes in the scene.
 X3DRoute[] getRoutes()
          Get the list of ROUTEs in this scene.
 java.lang.String getSpecificationVersion()
          Get the specification version name that was used to describe this scene.
 java.lang.String getWorldURL()
          Get the fully qualified URL of this scene.
 void removeExternProtoDeclaration(java.lang.String name)
          Remove the externproto declaration registered under the given name.
 void removeImportedNode(java.lang.String importName)
          Remove the IMPORT statement associated with a given local import name.
 void removeNamedNode(java.lang.String name)
          Calling this method removes any existing mapping between a given literal name and any X3D nodes.
 void removeProtoDeclaration(java.lang.String name)
          Remove the proto declaration registered under the given name.
 void removeRoute(X3DRoute route)
          Delete the route from this scene.
 void setErrorReporter(ErrorReporter reporter)
          Register an error reporter with the engine so that any errors generated by the script code can be reported in a nice, pretty fashion.
 void updateExternProtoDeclaration(java.lang.String name, X3DExternProtoDeclaration externproto)
          Add the EXTERNPROTO declaration representing the given name.
 void updateImportedNode(java.lang.String exportedName, java.lang.String importedName, X3DNode inline)
          Create or modify an IMPORT from the specified inline node to a given import name.
 void updateNamedNode(java.lang.String nodeName, X3DNode node)
          Calling this method creates an association between a literal name and a node.
 void updateProtoDeclaration(java.lang.String name, X3DProtoDeclaration proto)
          Add the PROTO declaration representing the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

specVersion

protected final java.lang.String specVersion
The version of the specification represented


encoding

protected final int encoding
The encoding type constant


profile

protected final ProfileInfo profile
The list of profiles in use


components

protected ComponentInfo[] components
The list of components in use


errorReporter

protected ErrorReporter errorReporter
Class that represents the external reporter


url

protected final java.lang.String url
The world URL


rootNodes

protected org.web3d.vrml.scripting.sai.BaseNode[] rootNodes
Listing of root nodes


protos

protected X3DProtoDeclaration[] protos
The array of protos declared


externprotos

protected X3DExternProtoDeclaration[] externprotos
The list of extern protos declared


routes

protected X3DRoute[] routes
The list of routes in use


executionSpace

protected VRMLExecutionSpace executionSpace
The execution space that this context works in


scene

protected BasicScene scene
The basic scene type


routeManager

protected RouteManager routeManager
Route manager for handling user added/removed routes


stateManager

protected FrameStateManager stateManager
FrameState manager for creating nodes


nodeWrapperList

protected java.util.ArrayList nodeWrapperList
Listing of all the valid X3DNode wrappers.


nodeWrapperMap

protected java.util.HashMap nodeWrapperMap
Mapping of the VRMLNodeType to its X3DNode wrapper


routeWrapperMap

protected java.util.HashMap routeWrapperMap
Mapping of the ROUTE to its X3DRoute wrapper

Constructor Detail

BaseExecutionContext

public BaseExecutionContext(VRMLExecutionSpace space,
                            RouteManager rm,
                            FrameStateManager fsm,
                            ProfileInfo profile,
                            ComponentInfo[] components,
                            java.lang.ref.ReferenceQueue refQueue,
                            FieldFactory fac,
                            org.web3d.vrml.scripting.sai.FieldAccessListener fal)
Construct an execution context descriptor for the given information.

Parameters:
space - The space to source information for this scene
rm - A route manager for users creating/removing routes
fsm - state manager for dealing with dynamic scene graph changes
profile - Instance of the ProfileInfo that describes this scene
components - The component definitions for this scene
refQueue - The queue used for dealing with field references
fac - Factory used to create field wrappers
fal - The access listener for propogating s2 requests

BaseExecutionContext

public BaseExecutionContext(VRMLExecutionSpace space,
                            RouteManager rm,
                            FrameStateManager fsm,
                            ProfileInfo profile,
                            java.lang.ref.ReferenceQueue refQueue,
                            FieldFactory fac,
                            org.web3d.vrml.scripting.sai.FieldAccessListener fal)
Construct an execution context descriptor for the given information.

Parameters:
space - The space to source information for this scene
rm - A route manager for users creating/removing routes
profile - Instance of the ProfileInfo that describes this scene
refQueue - The queue used for dealing with field references
fac - Factory used to create field wrappers
fal - The access listener for propogating s2 requests
Method Detail

getSpecificationVersion

public java.lang.String getSpecificationVersion()
Get the specification version name that was used to describe this scene. The version is a string that is relative to the specification used and is in the format "X.Y" where X and Y are integer values describing major and minor versions, respectively.

Specified by:
getSpecificationVersion in interface X3DExecutionContext
Returns:
The version used for this scene

getEncoding

public int getEncoding()
Get the encoding of the original file type.

Specified by:
getEncoding in interface X3DExecutionContext
Returns:
The encoding description

getProfile

public ProfileInfo getProfile()
Get the name of the profile used by this scene. If the profile is not set, will return null.

Specified by:
getProfile in interface X3DExecutionContext
Returns:
The name of the profile, or null

getComponents

public ComponentInfo[] getComponents()
Get the list of all the components declared in the scene. If there were no components registered, this will return null.

Specified by:
getComponents in interface X3DExecutionContext
Returns:
The components declared or null

getWorldURL

public java.lang.String getWorldURL()
                             throws InvalidBrowserException
Get the fully qualified URL of this scene. This returns the entire URL including any possible arguments that might be associated with a CGI call or similar mechanism. If the world was created programmatically, this will return null.

Specified by:
getWorldURL in interface X3DExecutionContext
Returns:
A string of the URL or null if not supported.
Throws:
InvalidBrowserException - The dispose method has been called on this browser reference.
ConnectionException - An error occurred in the connection to the browser.

getRoutes

public X3DRoute[] getRoutes()
Get the list of ROUTEs in this scene. This gives all of the top level routes in the scene in the order that they are declared.

Specified by:
getRoutes in interface X3DExecutionContext
Returns:
The list of ROUTE instances in this scene

addRoute

public X3DRoute addRoute(X3DNode fromX3DNode,
                         java.lang.String readableField,
                         X3DNode toX3DNode,
                         java.lang.String writableField)
                  throws InvalidBrowserException,
                         InvalidReadableFieldException,
                         InvalidWritableFieldException,
                         InvalidNodeException
Add a route in this scene. The route is considered to be part of this scene regardless of whether the two end points are or not. The route will remain valid as long as both nodes are live and this scene is live. If this scene becomes invalid (eg a loadURL call is successful) then the route will no longer exist and there shall be no connection between the two nodes.

Specified by:
addRoute in interface X3DExecutionContext
Parameters:
fromX3DNode - The source node for the route
readableField - The readable field source of the route
toX3DNode - The destination node of the route
writableField - The writable field destination of the route
Throws:
InvalidReadableFieldException - if the named readable field does not exist
InvalidWritableFieldException - if the named writable field does not exist.
InvalidNodeException - The nominated destination or source node has been disposed of
InvalidBrowserException - The dispose method has been called on this browser reference.
ConnectionException - An error occurred in the connection to the browser.

removeRoute

public void removeRoute(X3DRoute route)
                 throws InvalidBrowserException
Delete the route from this scene. If the route is not part of this scene an exception is generated.

Specified by:
removeRoute in interface X3DExecutionContext
Parameters:
route - The route reference to delete
Throws:
InvalidBrowserException - The dispose method has been called on this browser reference.

getProtosNames

public java.lang.String[] getProtosNames()
Get the list of ordinary PROTO's declared in this scene. EXTERNPROTOs are not included in this list.

Specified by:
getProtosNames in interface X3DExecutionContext
Returns:
The list of proto instances in this scene

getProtoDeclaration

public X3DProtoDeclaration getProtoDeclaration(java.lang.String name)
Get the PROTO declaration representing the given name.

Specified by:
getProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the proto to fetch

updateProtoDeclaration

public void updateProtoDeclaration(java.lang.String name,
                                   X3DProtoDeclaration proto)
Add the PROTO declaration representing the given name.

Specified by:
updateProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the proto to fetch
proto - The declaration for the name

removeProtoDeclaration

public void removeProtoDeclaration(java.lang.String name)
Remove the proto declaration registered under the given name.

Specified by:
removeProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the proto to fetch

getExternProtoNames

public java.lang.String[] getExternProtoNames()
Get the list of EXTERNPROTOs declared in this scene. The instances may or may not have been loaded at this point. Check with the interface declaration to see if this is the case.

Specified by:
getExternProtoNames in interface X3DExecutionContext
Returns:
The list of EXTERNPROTO instances in this scene

getExternProtoDeclaration

public X3DExternProtoDeclaration getExternProtoDeclaration(java.lang.String name)
Get the EXTERNPROTO declaration representing the given name.

Specified by:
getExternProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the externproto to fetch

updateExternProtoDeclaration

public void updateExternProtoDeclaration(java.lang.String name,
                                         X3DExternProtoDeclaration externproto)
Add the EXTERNPROTO declaration representing the given name.

Specified by:
updateExternProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the externproto to fetch
externproto - The declaration for the name

removeExternProtoDeclaration

public void removeExternProtoDeclaration(java.lang.String name)
Remove the externproto declaration registered under the given name.

Specified by:
removeExternProtoDeclaration in interface X3DExecutionContext
Parameters:
name - The name of the externproto to fetch

getNamedNodes

public java.lang.String[] getNamedNodes()
Get a list of the nodes that have been named with DEF or keyword in this scene. The map is keyed by the name string and the values are the X3DNode instances. If there are no nodes marked with DEF then the map will be empty.

Specified by:
getNamedNodes in interface X3DExecutionContext
Returns:
A map of the DEF'd nodes.

getNamedNode

public X3DNode getNamedNode(java.lang.String name)
Get the node instance represented by the given name.

Specified by:
getNamedNode in interface X3DExecutionContext
Parameters:
name - The name of the node to fetch the definition for
Returns:
The node instance or null if not known

removeNamedNode

public void removeNamedNode(java.lang.String name)
Calling this method removes any existing mapping between a given literal name and any X3D nodes.

Specified by:
removeNamedNode in interface X3DExecutionContext
Parameters:
name - The literal name of the mapping to remove.

updateNamedNode

public void updateNamedNode(java.lang.String nodeName,
                            X3DNode node)
Calling this method creates an association between a literal name and a node. If there is already a mapping from a given literal name to some value, that mapping will be replaced by the new mapping. If a mapping for that literal name did not exist, one will be created. There may exist multiple literal names which map to a given X3D node.

Specified by:
updateNamedNode in interface X3DExecutionContext
Parameters:
nodeName - The literal name to change.
node - The node to map to.

getImportedNode

public X3DNode getImportedNode(java.lang.String name)
Get the imported node instance represented by a given name.

Specified by:
getImportedNode in interface X3DExecutionContext
Parameters:
name - The name of the import to fetch
Returns:
A node wrapper representing the node

removeImportedNode

public void removeImportedNode(java.lang.String importName)
Remove the IMPORT statement associated with a given local import name. See 19777-2 6.4.9 namedNode handling.

Specified by:
removeImportedNode in interface X3DExecutionContext
Parameters:
importName - The local name used in the IMPORT

updateImportedNode

public void updateImportedNode(java.lang.String exportedName,
                               java.lang.String importedName,
                               X3DNode inline)
Create or modify an IMPORT from the specified inline node to a given import name. If 'importName' has already been used as the local name for an import, the old value will be replaced by the new value. Otherwise the appropriate new IMPORT will be constructed. See 19777-2 6.4.9 namedNode handling

Specified by:
updateImportedNode in interface X3DExecutionContext
Parameters:
exportedName - The node name as exported from the inline
importedName - The name to use locally for the imported node
inline - The "DEF'd Inline" of the IMPORT (ISO 19775:2005).

getRootNodes

public X3DNode[] getRootNodes()
Get the list of current root nodes in the scene. The array contains the items in the order they were added or declared in the initial file or added after the initial scene was created.

Specified by:
getRootNodes in interface X3DExecutionContext
Returns:
The list of root nodes in the scene

createNode

public X3DNode createNode(java.lang.String name)
Create a new node in this scene. The node creation uses the pre-set profile and component information to ensure the validity of what the user wishes to create. If the named node is not in one of the defined profile or components then an exception is generated. This cannot be used to create nodes that are declared as protos or extern protos in this scene. You must use the proto-specific mechanisms for that.

Specified by:
createNode in interface X3DExecutionContext
Parameters:
name - The node's name to create
Returns:
The node pointer that represents the given name
Throws:
InvalidNodeException - The name does not represent a node in the given list of profile and components for this scene

createProto

public X3DProtoInstance createProto(java.lang.String name)
Create a new proto instance in this scene. The node creation uses the name space semantics to locate the appropriate proto. This may require the browser to first look in the local proto space and then walk backwards up the proto declaration spaces to find a match.

Specified by:
createProto in interface X3DExecutionContext
Parameters:
name - The proto's name to create
Returns:
The node pointer that represents the given proto
Throws:
InvalidNodeException - The name does not represent a known proto declaration in the available namespaces

setErrorReporter

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

Parameters:
reporter - The instance to use or null

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium