Xj3D VRML/X3D Code API

org.web3d.vrml.nodes.proto
Class AbstractProto

java.lang.Object
  extended byorg.web3d.vrml.nodes.proto.AbstractProto
All Implemented Interfaces:
VRMLNodeTemplate
Direct Known Subclasses:
ExternalPrototypeDecl, ProtoInstancePlaceHolder, PrototypeDecl

public abstract class AbstractProto
extends java.lang.Object
implements VRMLNodeTemplate

Base representation of the common functionality for the PROTO and EXTERNPROTO node types.

Note: This implementation does not handle IS values to pass field information to body nodes.

Version:
$Revision: 1.10 $
Author:
Justin Couch

Field Summary
protected static java.lang.String BAD_NODE_MSG
          A standard message for when the supplied node is wrong.
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  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  boolean isVrml97
          Flag indicating VRML97 semantics
protected  java.lang.String nodeName
          The name of the node.
protected  NodeTemplateToInstanceCreator protoCreator
          The proto creator that is responsible for creating new instances of this node.
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
AbstractProto(java.lang.String name, int majorVersion, int minorVersion, NodeTemplateToInstanceCreator creator)
          Create a new instance of a proto that has the given name.
 
Method Summary
 void addNodeListener(VRMLNodeListener l)
          Add a listener to this node instance.
 int appendField(VRMLFieldDeclaration field)
          Append a field declaration to this node.
protected  void checkNodeType(VRMLNodeType node)
          Check to see if the supplied node type is the same as this node.
 void deleteField(int index)
          Delete the field at the given index.
 void deleteField(VRMLFieldDeclaration field)
          Delete the named field.
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.
 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.
 int getNumFields()
          Get the number of fields defined for this node.
 java.lang.String getVRMLNodeName()
          Get the name of this node as a string.
 boolean isVRML97()
          Check to see if the node is using VRML97 semantics
 void removeNodeListener(VRMLNodeListener l)
          Remove a listener from this node instance.
 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.
 
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.VRMLNodeTemplate
createNewInstance, getPrimaryType
 

Field Detail

BAD_NODE_MSG

protected static final java.lang.String BAD_NODE_MSG
A standard message for when the supplied node is wrong. Just add the node name of the wrong type to the end.

See Also:
Constant Field Values

VRML97_FIELD_MSG

protected static final java.lang.String VRML97_FIELD_MSG
Message when the field type is not valid in VRML97

See Also:
Constant Field Values

FIELD_CLASH_MSG

protected static final java.lang.String FIELD_CLASH_MSG
When the same field is defined twice, but with different types

See Also:
Constant Field Values

fieldIndexMap

protected final java.util.Map fieldIndexMap
Data mapping holding the field name -> index (Integer) mapping


fieldDeclList

protected final java.util.List fieldDeclList
List of the field maps registered in order for their definitions. When created, this list will have a null value in each index position for the size of the number of declared fields. This allows a user to set(int, object) the value if they want. However, it is recommended that you use the appendField(VRMLFieldDeclaration) method instead.


nodeName

protected final java.lang.String nodeName
The name of the node. "Script" or the proto name.


fieldData

protected final VRMLFieldData fieldData
Scratch class var for returning field data


errorReporter

protected ErrorReporter errorReporter
Reporter instance for handing out errors


vrmlMajorVersion

protected int vrmlMajorVersion
The major version of the spec this instance belongs to.


vrmlMinorVersion

protected int vrmlMinorVersion
The minor version of the spec this instance belongs to.


isVrml97

protected boolean isVrml97
Flag indicating VRML97 semantics


protoCreator

protected NodeTemplateToInstanceCreator protoCreator
The proto creator that is responsible for creating new instances of this node. This will be, by necessity a renderer-specific class based on this abstract interface.

Constructor Detail

AbstractProto

public AbstractProto(java.lang.String name,
                     int majorVersion,
                     int minorVersion,
                     NodeTemplateToInstanceCreator creator)
Create a new instance of a proto that has the given name.

Parameters:
name - The name of the proto to use
majorVersion - The major version number of this scene
minorVersion - The minor version number of this scene
creator - The node creator for generating instances of ourself
Method Detail

setErrorReporter

public 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. Setting a value of null will clear the currently set reporter. If one is already set, the new value replaces the old.

Specified by:
setErrorReporter in interface VRMLNodeTemplate
Parameters:
reporter - The instance to use or null

addNodeListener

public void addNodeListener(VRMLNodeListener l)
Add a listener to this node instance. If the listener is already added or null the request is silently ignored.

Parameters:
l - The listener instance to add

removeNodeListener

public void removeNodeListener(VRMLNodeListener l)
Remove a listener from this node instance. If the listener is null or not registered, the request is silently ignored.

Parameters:
l - The listener to be removed

fireFieldChanged

protected void fireFieldChanged(int index)
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.

Parameters:
index - The index of the field that changed

getVRMLNodeName

public java.lang.String getVRMLNodeName()
Get the name of this node as a string.

Specified by:
getVRMLNodeName in interface VRMLNodeTemplate
Returns:
The name of the node

getFieldCount

public int getFieldCount()
Get the count of the number of fields currently registered.

Specified by:
getFieldCount in interface VRMLNodeTemplate
Returns:
The number of fields available

appendField

public int appendField(VRMLFieldDeclaration field)
                throws FieldExistsException,
                       InvalidFieldException
Append a field declaration to this node. This is added to the current list on the end. If the field already exists with the given name but different values exception will be generated. If the field has exactly the same signature it will silently ignore the request.

Specified by:
appendField in interface VRMLNodeTemplate
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 node
InvalidFieldException - The field type is not valid for this specification version

deleteField

public void deleteField(int index)
                 throws InvalidFieldException,
                        java.lang.IndexOutOfBoundsException
Delete the field at the given index. This will not shuffle fields down from higher index values. That index just becomes invalid to set values to. If no field exists at that index or it is out of range, an exception will be generated.

Specified by:
deleteField in interface VRMLNodeTemplate
Parameters:
index - The index of the field to delete
Throws:
InvalidFieldException - The field does not exist at the index
java.lang.IndexOutOfBoundsException - The index provided is out of range for the current field numbers

deleteField

public void deleteField(VRMLFieldDeclaration field)
                 throws InvalidFieldException,
                        java.lang.IndexOutOfBoundsException
Delete the named field. This will not shuffle fields down from higher index values. That index just becomes invalid to set values to. If no field exists at that index or it is out of range, an exception will be generated.

Specified by:
deleteField in interface VRMLNodeTemplate
Parameters:
field - The field to delete
Throws:
InvalidFieldException - The named field does not exist
java.lang.IndexOutOfBoundsException - The index provided is out of range for the current field numbers

getAllFields

public java.util.List getAllFields()
Make a listing of all fields that are currently registered in this node. The list contains instances of VRMLFieldDeclaration.

Specified by:
getAllFields in interface VRMLNodeTemplate
Returns:
A list of the current field declarations

isVRML97

public boolean isVRML97()
Check to see if the node is using VRML97 semantics

Returns:
true if this is a VRML97 node

checkNodeType

protected void checkNodeType(VRMLNodeType node)
Check to see if the supplied node type is the same as this node. It does a case sensitive string comparison based on thier node name. If they are not the same then an IllegalArgumentException is thrown. If the same, nothing happens.

Parameters:
node - The node to check
Throws:
java.lang.IllegalArgumentException - The nodes are not the same

getFieldIndex

public int getFieldIndex(java.lang.String fieldName)
Get the index of the given field name. If the name does not exist for this node then return a value of -1.

Specified by:
getFieldIndex in interface VRMLNodeTemplate
Parameters:
fieldName - The name of the field we want the index from
Returns:
The index of the field name or -1

getFieldDeclaration

public VRMLFieldDeclaration getFieldDeclaration(int index)
Get the declaration of the field at the given index. This allows for reverse lookup if needed. If the field does not exist, this will give a value of null.

Specified by:
getFieldDeclaration in interface VRMLNodeTemplate
Parameters:
index - The index of the field to get information
Returns:
A representation of this field's information

getNumFields

public int getNumFields()
Get the number of fields defined for this node.

Specified by:
getNumFields in interface VRMLNodeTemplate
Returns:
The number of fields.

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium