Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer
Class DefaultNodeFactory

java.lang.Object
  extended by org.web3d.vrml.renderer.DefaultNodeFactory
All Implemented Interfaces:
java.lang.Cloneable, VRMLNodeFactory
Direct Known Subclasses:
NRNodeFactory, OGLNodeFactory

public class DefaultNodeFactory
extends java.lang.Object
implements VRMLNodeFactory, java.lang.Cloneable

Singleton implementation of the VRMLNodeFactory that produces implementations of the nodes and can be customised for a specific renderer.

This implementation serves two purposes - generalised node factory implementation and the base of a renderer-specific implementation. The class is a full instance allowing it to be used directly, but the constructor is marked protected so that you can't create an instance directly. However, you can use the static factory method to fetch the singleton instance for that particular renderer type.

Property Files

Yes, there are a lot used by this class. Most of them we don't know until runtime because the loading of one file is used to find the definition of another file to load with further property information. There is a much more in-depth tutorial on how to extend Xj3D one the website, so this is just an overview.

At the top of the pile is xj3d.properties. This file is used at startup of the factory. In here, is located the list of profiles supported, components supported and renderers supported. The list of profiles are then used to load a separate property file for each profile, with the file name profile_name.properties. The file name is all lower case, regardless of what the initial formal profile name is. In the profiile properties file is the title and the list of each component and level that is required for that profile.

After the profiles, there is a list of the components that may be supported. This list just points to the property file that contains the definition of the component. These files may be placed anywhere, however, for the inbuilt components of Xj3D, you will find the property files in this package (directory). Users wishing to create custom components may place them anywhere, so long as they are findable in the CLASSPATH at runtime. Each file contains a title, name of the implementor and a URL of that implementor. In addition, it contains the definition of the maximum level supported by that component and the list of nodes that are provided at each level.

Version:
$Revision: 2.7 $
Author:
Justin Couch

Field Summary
static java.lang.String JAVA3D_RENDERER
          Definition of the Java3D renderer
protected  int majorVersion
          The major version of the spec this file belongs to.
protected  int minorVersion
          The minor version of the spec this file belongs to.
static java.lang.String MOBILE_RENDERER
          Definition of the Mobile renderer
static java.lang.String NULL_RENDERER
          Definition of the null renderer
static java.lang.String OPENGL_RENDERER
          Definition of the OpenGL renderer
 
Fields inherited from interface org.web3d.vrml.lang.VRMLNodeFactory
ANY_LEVEL
 
Constructor Summary
protected DefaultNodeFactory(java.lang.String rendererID)
          Construct an instance of the factory for the given renderer type.
 
Method Summary
 ComponentInfo addComponent(java.lang.String name, int level)
          Add a component level requirement to the factory nodes.
static void clearCachedInfo()
          Convenience method to clear all the cached information so that we start again with new information.
 java.lang.Object clone()
          Create a clone of this factory.
static VRMLNodeFactory createFactory(java.lang.String rendererID)
          Factory method to create an instance of the node factory that can be used for a specific renderer.
 VRMLNode createVRMLNode(java.lang.String nodeName, boolean staticNode)
          Create a new node instance from the given node name.
 VRMLNode createVRMLNode(java.lang.String component, java.lang.String nodeName, boolean staticNode)
          Create a new node instance of the given node that exists in the given component.
 VRMLNode createVRMLNode(VRMLNode node, boolean staticNode)
          Create a new node instance that is a cloned copy of the given node.
 void disableComponent(int[] specVersion, java.lang.String componentName, int level)
          Disable a component.
 ComponentInfo[] getAvailableComponents()
          List all of the available components that this factory is capable of supporting.
 java.lang.String[] getAvailableProfileNames()
          Convenience method to get just the names all the available profiles that this factory is capable of supporting.
 ProfileInfo[] getAvailableProfiles()
          List the all the available profiles that this factory is capable of supporting.
 int[] getMaxSupportedSpecVersion()
          Get the maximum supported spec version.
 int[] getSpecVersion()
          Get the spec version that this node factory is currently set to.
static VRMLNodeFactory newInstance(java.lang.String rendererID)
          Factory method to create an new instance of the node factory every time the method is called.
 void setErrorReporter(ErrorReporter errorReporter)
          Register an error errorReporter with the factory instance so that any errors generated by the creation of nodes can be reported in a nice, pretty fashion.
 void setProfile(java.lang.String profile)
          Set the profile that is to be supported for subsequent node creation calls.
 void setSpecVersion(int major, int minor)
          Set the spec version that this node factory should be setting it's profile information for.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA3D_RENDERER

public static final java.lang.String JAVA3D_RENDERER
Definition of the Java3D renderer

See Also:
Constant Field Values

NULL_RENDERER

public static final java.lang.String NULL_RENDERER
Definition of the null renderer

See Also:
Constant Field Values

OPENGL_RENDERER

public static final java.lang.String OPENGL_RENDERER
Definition of the OpenGL renderer

See Also:
Constant Field Values

MOBILE_RENDERER

public static final java.lang.String MOBILE_RENDERER
Definition of the Mobile renderer

See Also:
Constant Field Values

majorVersion

protected int majorVersion
The major version of the spec this file belongs to.


minorVersion

protected int minorVersion
The minor version of the spec this file belongs to.

Constructor Detail

DefaultNodeFactory

protected DefaultNodeFactory(java.lang.String rendererID)
Construct an instance of the factory for the given renderer type.

Parameters:
rendererID - The ID of the renderer to use for this factory
Method Detail

setErrorReporter

public void setErrorReporter(ErrorReporter errorReporter)
Register an error errorReporter with the factory instance so that any errors generated by the creation of nodes can be reported in a nice, pretty fashion. Setting a value of null will clear the currently set errorReporter. If one is already set, the new value replaces the old.

Specified by:
setErrorReporter in interface VRMLNodeFactory
Parameters:
errorReporter - The instance to use or null

setSpecVersion

public void setSpecVersion(int major,
                           int minor)
                    throws UnsupportedSpecVersionException
Set the spec version that this node factory should be setting it's profile information for.

Specified by:
setSpecVersion in interface VRMLNodeFactory
Parameters:
major - The major version of the VRML/X3D spec to use
minor - The minor version of the VRML/X3D spec to use
Throws:
UnsupportedSpecVersionException - The profile is not unsupported by this implementation

getSpecVersion

public int[] getSpecVersion()
Get the spec version that this node factory is currently set to.

Specified by:
getSpecVersion in interface VRMLNodeFactory
Returns:
An int array of major, minor version.

setProfile

public void setProfile(java.lang.String profile)
                throws UnsupportedProfileException
Set the profile that is to be supported for subsequent node creation calls. Calling this method will clear all previously set profile and components.

Specified by:
setProfile in interface VRMLNodeFactory
Parameters:
profile - The name of the profile to use
Throws:
UnsupportedProfileException - The profile is not unsupported by this implementation

getMaxSupportedSpecVersion

public int[] getMaxSupportedSpecVersion()
Get the maximum supported spec version.

Specified by:
getMaxSupportedSpecVersion in interface VRMLNodeFactory
Returns:
An int array of major, minor version.

disableComponent

public void disableComponent(int[] specVersion,
                             java.lang.String componentName,
                             int level)
Disable a component. Typically done when something finds out it cannot support the component.

Specified by:
disableComponent in interface VRMLNodeFactory
Parameters:
specVersion - The spec version. Major, Minor.
componentName - The component name
level - The component level and higher to disable

addComponent

public ComponentInfo addComponent(java.lang.String name,
                                  int level)
                           throws UnsupportedComponentException
Add a component level requirement to the factory nodes. If that component or level is not supported, an exception is thrown. If the level is ANY_LEVEL then that says to find the highest supported component.

Specified by:
addComponent in interface VRMLNodeFactory
Parameters:
name - The name of the component
level - The level of the component to support
Returns:
The component information declaration matching the input
Throws:
UnsupportedComponentException - The component or level is not unsupported by this implementation

getAvailableProfiles

public ProfileInfo[] getAvailableProfiles()
List the all the available profiles that this factory is capable of supporting. It is not the list of set profiles to filter for.

Specified by:
getAvailableProfiles in interface VRMLNodeFactory
Returns:
A list of the supported profiles

getAvailableProfileNames

public java.lang.String[] getAvailableProfileNames()
Convenience method to get just the names all the available profiles that this factory is capable of supporting. It is not the list of set profiles to filter for.

Specified by:
getAvailableProfileNames in interface VRMLNodeFactory
Returns:
A list of the supported profile names

getAvailableComponents

public ComponentInfo[] getAvailableComponents()
List all of the available components that this factory is capable of supporting.

Specified by:
getAvailableComponents in interface VRMLNodeFactory
Returns:
The definition of all the available components

createVRMLNode

public VRMLNode createVRMLNode(java.lang.String nodeName,
                               boolean staticNode)
                        throws UnsupportedNodeException
Create a new node instance from the given node name. A best guess is made to the node's profile that it belongs to. This means that it could occasionally get it wrong if there are conflicting node names. If it does not understand the node type then it will return null.

Specified by:
createVRMLNode in interface VRMLNodeFactory
Parameters:
nodeName - The name of the node instance to create
staticNode - Whether this node is will be modified
Returns:
An instance of the node, uninitialised or null.
Throws:
UnsupportedNodeException - The node is not part of the declared profile and components

createVRMLNode

public VRMLNode createVRMLNode(java.lang.String component,
                               java.lang.String nodeName,
                               boolean staticNode)
                        throws UnsupportedComponentException,
                               UnsupportedNodeException
Create a new node instance of the given node that exists in the given component. If the node does not exist in that component then null is returned.

Specified by:
createVRMLNode in interface VRMLNodeFactory
Parameters:
component - The name of the component to create the name for
nodeName - The name of the node instance to create
staticNode - Whether this node is will be modified
Returns:
An instance of the node, uninitialised or null.
Throws:
UnsupportedComponentException - The component is not in the list of usable profiles currently set
UnsupportedNodeException - The node is not part of the declared profile and components

createVRMLNode

public VRMLNode createVRMLNode(VRMLNode node,
                               boolean staticNode)
Create a new node instance that is a cloned copy of the given node. The copy shall be a shallow copy. All of the node's direct field data has full copies of the values made, but any referenced child nodes are not included in the copy.

The primary use of this method is in generating proto instances from a set of template nodes. The parser of the proto will be responsible for making sure the children scene graphs are correctly built by sucessive calls to this method. Note that this implies the source node may well be from a different renderer implementation to the output form.

Specified by:
createVRMLNode in interface VRMLNodeFactory
Parameters:
node - The node instance to create a copy of
staticNode - Whether this node is will be modified
Returns:
An instance of the node initialised to the values or null.

createFactory

public static VRMLNodeFactory createFactory(java.lang.String rendererID)
Factory method to create an instance of the node factory that can be used for a specific renderer.

Parameters:
rendererID - The ID of the renderer to use for this factory

newInstance

public static VRMLNodeFactory newInstance(java.lang.String rendererID)
Factory method to create an new instance of the node factory every time the method is called.

Parameters:
rendererID - The ID of the renderer to use for this factory

clearCachedInfo

public static void clearCachedInfo()
Convenience method to clear all the cached information so that we start again with new information. This will clear all global information, not just the info in the current instance.


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a clone of this factory. The clone will have the same profile and component mix already constructed.

Specified by:
clone in interface VRMLNodeFactory
Overrides:
clone in class java.lang.Object
Returns:
A cloned copy of this instance
Throws:
java.lang.CloneNotSupportedException - Was not able to clone the object

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium