Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.scripting.sai
Class BaseNode

java.lang.Object
  extended by org.web3d.vrml.scripting.sai.BaseNode
All Implemented Interfaces:
X3DNode

public class BaseNode
extends java.lang.Object
implements X3DNode

The base representation of any VRML node in the system whether built in or a proto.

May be used as a standalone node, or extended with the abstract data types defined by higher levels of the SAI conformance.

Version:
$Revision: 1.14 $
Author:
Justin Couch

Field Summary
protected  boolean accessPermitted
          Flag for determining the read/write timing ability
protected  java.lang.ref.ReferenceQueue fieldQueue
          Reference queue used for keeping track of field object instances
protected  java.util.HashMap fieldRefMap
          Map containing the field name as key and a SoftReference instance that points to the field object.
protected  VRMLNodeType realNode
          This is the real node that this object represents
 
Constructor Summary
BaseNode(VRMLNodeType node, java.lang.ref.ReferenceQueue refQueue, FieldFactory fac, FieldAccessListener fal, BaseNodeFactory bnf)
          Create a new basic node implementation.
 
Method Summary
protected  void checkAccess()
          Convenience method to check if the node may be accessed at this point in time.
 void dispose()
          Dispose of this node's resources.
 boolean equals(java.lang.Object obj)
          Compare this node for equality to another.
 X3DField getField(java.lang.String name)
          Get a field for this node.
 X3DFieldDefinition[] getFieldDefinitions()
          Get the list of fields that this node contains.
 X3DMetadataObject getMetadata()
          Get the metadata object associated with this node.
 java.lang.String getNodeName()
          Get the type of this node.
 int[] getNodeType()
          Get the basic categorisation type(s) of this node.
 int hashCode()
          Generate the hashcode for this object.
 boolean isRealized()
          Check to see if this node has completed its setup either by being directly informed of it or through implicit measures (see the specification for details).
 void realize()
          Notify this node that its setup stage is now complete.
 void setMetadata(X3DMetadataObject node)
          Set the Metadata object that belongs to this node.
 java.lang.String toString()
          Generate a string version of this node's representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

realNode

protected VRMLNodeType realNode
This is the real node that this object represents


fieldRefMap

protected java.util.HashMap fieldRefMap
Map containing the field name as key and a SoftReference instance that points to the field object. The weak reference is used so that fields can be removed automatically by Java if no longer referenced by user code.


fieldQueue

protected java.lang.ref.ReferenceQueue fieldQueue
Reference queue used for keeping track of field object instances


accessPermitted

protected boolean accessPermitted
Flag for determining the read/write timing ability

Constructor Detail

BaseNode

public BaseNode(VRMLNodeType node,
                java.lang.ref.ReferenceQueue refQueue,
                FieldFactory fac,
                FieldAccessListener fal,
                BaseNodeFactory bnf)
Create a new basic node implementation.

Parameters:
node - The source node this is wrapping
refQueue - The queue used for dealing with field references
fac - Factory used to create field wrappers
fal - The access listener for propogating s2 requests
bnf - The factory used to create node wrappers
Method Detail

setMetadata

public void setMetadata(X3DMetadataObject node)
                 throws InvalidNodeException
Set the Metadata object that belongs to this node. If the object instance is null, then it clears the currently set node instance.

Specified by:
setMetadata in interface X3DNode
Parameters:
node - The new node instance to use
Throws:
InvalidNodeException

getMetadata

public X3DMetadataObject getMetadata()
                              throws InvalidNodeException
Get the metadata object associated with this node. If none is set, it will return null.

Specified by:
getMetadata in interface X3DNode
Returns:
The metadata object instance or null
Throws:
InvalidNodeException

getNodeName

public java.lang.String getNodeName()
                             throws InvalidNodeException
Get the type of this node. The string returned should be the name of the VRML node or the name of the proto instance this node represents.

Specified by:
getNodeName in interface X3DNode
Returns:
The type of this node.
Throws:
InvalidNodeException - The node has had it's resources disposed of

getFieldDefinitions

public X3DFieldDefinition[] getFieldDefinitions()
                                         throws InvalidNodeException
Get the list of fields that this node contains. This will return one definition for each field regardless of whether it is eventIn/Out, exposedField or field access type.

Specified by:
getFieldDefinitions in interface X3DNode
Returns:
The definitions for all fields of this node
Throws:
InvalidNodeException - The node has had it's resources disposed of

realize

public void realize()
             throws InvalidNodeException
Notify this node that its setup stage is now complete. This will cause all its fields to become non-writable, leaving only eventIns and exposedFields writable. A user is not required to call this method as it will be implicitly called immediately this node is added to any other node. Any call after the first is ignored.

Specified by:
realize in interface X3DNode
Throws:
InvalidNodeException - The node has had it's resources disposed of

isRealized

public boolean isRealized()
                   throws InvalidNodeException
Check to see if this node has completed its setup either by being directly informed of it or through implicit measures (see the specification for details).

Specified by:
isRealized in interface X3DNode
Returns:
true if this node has completed the setup stage, false otherwise
Throws:
InvalidNodeException - The node has had it's resources disposed of

getNodeType

public int[] getNodeType()
                  throws InvalidNodeException
Get the basic categorisation type(s) of this node. The types values are provided in the array of values. There is no specific order of the returned types. It is expected that most node types, which only descend from a single parent type would return an array of length 1. The returned value(s) should be the most derived type applicable for that node. For example, a Material node should return MaterialNodeType value, not AppearanceChildNodeType value.

Specified by:
getNodeType in interface X3DNode
Returns:
The primary type(s) of this node
Throws:
InvalidNodeException - The node has had it's resources disposed of

getField

public X3DField getField(java.lang.String name)
                  throws InvalidFieldException,
                         InvalidNodeException
Get a field for this node.

If the basic field required is an exposedField you can use either the standard name (such as translation) or you can use the set_ / _changed modifier (such as set_translation). If the field asked for is of field access type then an object is returned that cannot be read or written to. However, this allows the option for building editor type applications that may permit reading and writing of field access types when not running the VRML event model.

Specified by:
getField in interface X3DNode
Parameters:
name - The name of the field that is required
Returns:
A reference to the field requested.
Throws:
InvalidFieldException - The named field does not exist for this node.
InvalidNodeException - The node has had it's resources disposed of

dispose

public void dispose()
             throws InvalidNodeException
Dispose of this node's resources. This is used to indicate to the browser that the java side of the application does not require the resources represented by this node. The browser is now free to do what it likes with the node.

This in no way implies that the browser is to remove this node from the scene graph, only that the java code is no longer interested in this particular node through this reference.

Once this method has been called, any further calls to methods of this instance of the class is shall generate an InvalidNodeException.

Specified by:
dispose in interface X3DNode
Throws:
InvalidNodeException - The node is no longer valid and can't be disposed of again.

hashCode

public int hashCode()
Generate the hashcode for this object. In order to allow this node to be used as a key lookup in a hashMap, we want to override this to make sure that we compare against the real node that we're wrapping. In doing so, we're maintaining the contract required by Java as the equals() method compares for the same thing.

Overrides:
hashCode in class java.lang.Object
Returns:
The hash value for this object

equals

public boolean equals(java.lang.Object obj)
Compare this node for equality to another. To do this, we want to see if they're representing the same base internal node instance. If they are (through using the reference comparison), then return true;

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare against
Returns:
true if these represent the same internal object

toString

public java.lang.String toString()
                          throws InvalidNodeException
Generate a string version of this node's representation.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this node
Throws:
InvalidNodeException

checkAccess

protected void checkAccess()
Convenience method to check if the node may be accessed at this point in time. If it is not, it will throw an exception appropriate to the situation.

Throws:
InvalidNodeException - The node handle is no longer valid
InvalidOperationTimingException - Can't access the node at this point in time

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium