iicm.vrml.pw
Class SceneTraverser

java.lang.Object
  extended by iicm.vrml.pw.Traverser
      extended by iicm.vrml.pw.SceneTraverser

public class SceneTraverser
extends Traverser

Traverses VRML scene graph. It walks through a VRML97 scene nodes hiearchy to extract relevant information and store the data in a W3C DOM Document class.

Version:
1.0 last update: 11 June 2002
Author:
Jane Wu

Field Summary
private  int currentLevel
           
private  java.util.Vector defNames
           
private  org.w3c.dom.Document doc
           
private  boolean isChildOfAppearance
           
private  boolean isChildOfShape
           
private  boolean isChildOfSound
           
private  boolean isChildOfText
           
private  boolean isColorChild
           
private  boolean isCoordinateChild
           
private  boolean isNormalChild
           
private  boolean isTextureCoordinateChild
           
private  org.w3c.dom.Element parentAppearance
           
private  org.w3c.dom.Element parentElement
           
private  boolean parentElementSet
           
private  org.w3c.dom.Element parentOfColor
           
private  org.w3c.dom.Element parentOfCoordinate
           
private  org.w3c.dom.Element parentOfNormal
           
private  org.w3c.dom.Element parentOfTextureCoordinate
           
private  org.w3c.dom.Element parentProto
           
private  java.util.Vector parents
           
private  org.w3c.dom.Element parentShape
           
private  org.w3c.dom.Element parentSound
           
private  org.w3c.dom.Element parentText
           
private  org.w3c.dom.Element sceneElement
           
private  boolean setExternProto
           
private  boolean setFieldValue
           
 
Constructor Summary
SceneTraverser(org.w3c.dom.Document d, org.w3c.dom.Element sceneRoot)
          Constructs a SceneTraverser.
 
Method Summary
private  boolean arraysEqual(float[] array1, float[] array2)
          Returns a boolean value indicating whether two float arrays have equal values.
private  boolean arraysEqual(int[] array1, int[] array2)
          Returns a boolean value indicating whether two integer arrays have equal values.
private  boolean arraysEqual(java.lang.String[] array1, java.lang.String[] array2)
          Returns a boolean value indicating whether two string arrays have equal values.
 void checkISconnect(Node node, org.w3c.dom.Element element)
          Overrides super class's method.
private  java.lang.String convertToString(boolean bool)
          Returns a string representation of a boolean.
private  java.lang.String convertToString(float[] array, int length)
          Returns a string representation of a float array.
private  java.lang.String convertToString(float[] array, int length, int count)
          Returns a string representation of a float array.
private  java.lang.String convertToString(int[] array, int length)
          Returns a string representation of a integer array.
private  java.lang.String convertToString(int[] array, int length, int count)
          Returns a string representation of a integer array.
private  java.lang.String convertToString(java.lang.String[] array, int length, boolean wrapInQuotes)
          Returns a string representation of a string array.
private  org.w3c.dom.Element getFieldElement(Field f, java.lang.String name)
          Returns a field Element by extracting data from the given Field object.
private  boolean setObjectName(org.w3c.dom.Element element, java.lang.String objname)
          Registers object name for the node.
 void tAnchor(Anchor n)
          Traverses an Anchor node.
 void tAppearance(Appearance n)
          Traverses an Appearance node.
 void tAudioClip(AudioClip n)
          Traverses an AudioClip node.
 void tBackground(Background n)
          Traverses a Background node.
 void tBillboard(Billboard n)
          Traverses a Billboard node.
 void tBox(Box n)
          Traverses a Box node.
 void tCollision(Collision n)
          Traverses a Collision node.
 void tColor(Color n)
          Traverses a Color node.
 void tColorInterpolator(ColorInterpolator n)
          Traverses a ColorInterpolator node.
 void tCone(Cone n)
          Traverses a Cone node.
 void tCoordinate(Coordinate n)
          Traverses a Coordinate node.
 void tCoordinateInterpolator(CoordinateInterpolator n)
          Traverses a CoordinateInterpolator node.
 void tCylinder(Cylinder n)
          Traverses a Cylinder node.
 void tCylinderSensor(CylinderSensor n)
          Traverses a CylinderSensor node.
 void tDirectionalLight(DirectionalLight n)
          Traverses a DirectionalLight node.
 void tElevationGrid(ElevationGrid n)
          Traverses an ElevationGrid node.
 void tExtrusion(Extrusion n)
          Traverses an Extrusion node.
 void tFog(Fog n)
          Traverses a Fog node.
 void tFontStyle(FontStyle n)
          Traverses a FontStyle node.
 void tGroup(Group n)
          Traverses a Group node.
 void tGroupNode(GroupNode n)
          Overrides super class's method.
 void tImageTexture(ImageTexture n)
          Traverses an ImageTexture node.
 void tIndexedFaceSet(IndexedFaceSet n)
          Traverses an IndexedFaceSet node.
 void tIndexedLineSet(IndexedLineSet n)
          Traverses an IndexedLineSet node.
 void tInline(Inline n)
          Traverses an Inline node.
 void tLOD(LOD n)
          Traverses a LOD node.
 void tMaterial(Material n)
          Traverses a Material node.
 void tMovieTexture(MovieTexture n)
          Traverses a MovieTexture node.
 void tNavigationInfo(NavigationInfo n)
          Traverses a NavigationInfo node.
 void tNormal(Normal n)
          Traverses a Normal node.
 void tNormalInterpolator(NormalInterpolator n)
          Traverses a NormalInterpolator node.
 void tOrientationInterpolator(OrientationInterpolator n)
          Traverses an OrientationInterpolator node.
 void tPixelTexture(PixelTexture n)
          Traverses a PixelTexture node.
 void tPlaneSensor(PlaneSensor n)
          Traverses a PlaneSensor node.
 void tPointLight(PointLight n)
          Traverses a PointLight node.
 void tPointSet(PointSet n)
          Traverses a PointSet node.
 void tPositionInterpolator(PositionInterpolator n)
          Traverses a PositionInterpolator node.
 void tProtoInstance(ProtoInstance n)
          Traverses a ProtoInstance node.
 void tProtoNode(ProtoNode n)
          Traverses a Proto node.
 void tProximitySensor(ProximitySensor n)
          Traverses a ProximitySensor node.
private  void traverseGenericNode(Node node, org.w3c.dom.Element parent)
          Traverses a generic node with a given parent.
 void tRoute(RouteNode n)
          Traverses a ROUTE node (statement).
 void tScalarInterpolator(ScalarInterpolator n)
          Traverses a ScalarInterpolator node.
 void tScript(Script n)
          Traverses a Script node.
 void tShape(Shape n)
          Traverses a Shape node.
 void tSound(Sound n)
          Traverses a Sound node.
 void tSphere(Sphere n)
          Traverses a Sphere node.
 void tSphereSensor(SphereSensor n)
          Traverses a SphereSensor node.
 void tSpotLight(SpotLight n)
          Traverses a SpotLight node.
 void tSwitch(Switch n)
          Traverses a Switch node.
 void tText(Text n)
          Traverses a Texture node.
 void tTextureCoordinate(TextureCoordinate n)
          Traverses a TextureCoordinate node.
 void tTextureTransform(TextureTransform n)
          Traverses a TextureTransform node.
 void tTimeSensor(TimeSensor n)
          Traverses a TimeSensor node.
 void tTouchSensor(TouchSensor n)
          Traverses a TouchSensor node.
 void tTransform(Transform n)
          Traverses a Transform node.
 void tViewpoint(Viewpoint n)
          Traverses a Viewpoint node.
 void tVisibilitySensor(VisibilitySensor n)
          Traverses a VisibilitySensor node.
 void tWorldInfo(WorldInfo n)
          Traverses a WorldInfo node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doc

private org.w3c.dom.Document doc

sceneElement

private org.w3c.dom.Element sceneElement

parentElement

private org.w3c.dom.Element parentElement

parentProto

private org.w3c.dom.Element parentProto

parentShape

private org.w3c.dom.Element parentShape

parentAppearance

private org.w3c.dom.Element parentAppearance

parentText

private org.w3c.dom.Element parentText

parentSound

private org.w3c.dom.Element parentSound

parentOfColor

private org.w3c.dom.Element parentOfColor

parentOfNormal

private org.w3c.dom.Element parentOfNormal

parentOfTextureCoordinate

private org.w3c.dom.Element parentOfTextureCoordinate

parentOfCoordinate

private org.w3c.dom.Element parentOfCoordinate

defNames

private java.util.Vector defNames

parents

private java.util.Vector parents

currentLevel

private int currentLevel

parentElementSet

private boolean parentElementSet

setFieldValue

private boolean setFieldValue

setExternProto

private boolean setExternProto

isChildOfSound

private boolean isChildOfSound

isChildOfShape

private boolean isChildOfShape

isChildOfAppearance

private boolean isChildOfAppearance

isChildOfText

private boolean isChildOfText

isColorChild

private boolean isColorChild

isNormalChild

private boolean isNormalChild

isTextureCoordinateChild

private boolean isTextureCoordinateChild

isCoordinateChild

private boolean isCoordinateChild
Constructor Detail

SceneTraverser

public SceneTraverser(org.w3c.dom.Document d,
                      org.w3c.dom.Element sceneRoot)
Constructs a SceneTraverser.

Parameters:
d - W3C DOM Document
sceneRoot - the root Scene element
Method Detail

checkISconnect

public void checkISconnect(Node node,
                           org.w3c.dom.Element element)
Overrides super class's method.

Parameters:
node - the node to traverse
element - the element to check

tGroupNode

public void tGroupNode(GroupNode n)
Overrides super class's method.

Overrides:
tGroupNode in class Traverser
Parameters:
n - the node to traverse

tProtoInstance

public void tProtoInstance(ProtoInstance n)
Traverses a ProtoInstance node.

Specified by:
tProtoInstance in class Traverser
Parameters:
n - a ProtoInstance node to traverse

tProtoNode

public void tProtoNode(ProtoNode n)
Traverses a Proto node.

Specified by:
tProtoNode in class Traverser
Parameters:
n - a Proto node to traverse

tViewpoint

public void tViewpoint(Viewpoint n)
Traverses a Viewpoint node.

Specified by:
tViewpoint in class Traverser
Parameters:
n - a Viewpoint node to traverse

tNavigationInfo

public void tNavigationInfo(NavigationInfo n)
Traverses a NavigationInfo node.

Specified by:
tNavigationInfo in class Traverser
Parameters:
n - a NavigationInfo node to traverse

tFog

public void tFog(Fog n)
Traverses a Fog node.

Specified by:
tFog in class Traverser
Parameters:
n - a Fog node to traverse

tBackground

public void tBackground(Background n)
Traverses a Background node.

Specified by:
tBackground in class Traverser
Parameters:
n - a Background node to traverse

tRoute

public void tRoute(RouteNode n)
Traverses a ROUTE node (statement).

Overrides:
tRoute in class Traverser
Parameters:
n - a ROUTE node to traverse

tScalarInterpolator

public void tScalarInterpolator(ScalarInterpolator n)
Traverses a ScalarInterpolator node.

Specified by:
tScalarInterpolator in class Traverser
Parameters:
n - a ScalerInterpolator node to traverse

tPositionInterpolator

public void tPositionInterpolator(PositionInterpolator n)
Traverses a PositionInterpolator node.

Specified by:
tPositionInterpolator in class Traverser
Parameters:
n - a PositionInterpolator node to traverse

tOrientationInterpolator

public void tOrientationInterpolator(OrientationInterpolator n)
Traverses an OrientationInterpolator node.

Specified by:
tOrientationInterpolator in class Traverser
Parameters:
n - an OrientationInterpolator node

tNormalInterpolator

public void tNormalInterpolator(NormalInterpolator n)
Traverses a NormalInterpolator node.

Specified by:
tNormalInterpolator in class Traverser
Parameters:
n - a NormalInterpolator node to traverse

tCoordinateInterpolator

public void tCoordinateInterpolator(CoordinateInterpolator n)
Traverses a CoordinateInterpolator node.

Specified by:
tCoordinateInterpolator in class Traverser
Parameters:
n - a CoordinateInterpolator node to traverse

tColorInterpolator

public void tColorInterpolator(ColorInterpolator n)
Traverses a ColorInterpolator node.

Specified by:
tColorInterpolator in class Traverser
Parameters:
n - a ColorInterpolator node to traverse

tTextureTransform

public void tTextureTransform(TextureTransform n)
Traverses a TextureTransform node.

Specified by:
tTextureTransform in class Traverser
Parameters:
n - a TextureTransform node to traverse

tPixelTexture

public void tPixelTexture(PixelTexture n)
Traverses a PixelTexture node.

Specified by:
tPixelTexture in class Traverser
Parameters:
n - a PixelTexture node to traverse

tMovieTexture

public void tMovieTexture(MovieTexture n)
Traverses a MovieTexture node.

Specified by:
tMovieTexture in class Traverser
Parameters:
n - a MovieTexture node to traverse

tImageTexture

public void tImageTexture(ImageTexture n)
Traverses an ImageTexture node.

Specified by:
tImageTexture in class Traverser
Parameters:
n - an ImageTexture node to traverse

tMaterial

public void tMaterial(Material n)
Traverses a Material node.

Specified by:
tMaterial in class Traverser
Parameters:
n - a Material node

tFontStyle

public void tFontStyle(FontStyle n)
Traverses a FontStyle node.

Specified by:
tFontStyle in class Traverser
Parameters:
n - a FontStyle node to traverse

tAppearance

public void tAppearance(Appearance n)
Traverses an Appearance node.

Specified by:
tAppearance in class Traverser
Parameters:
n - an Appearance node to traverse

tTextureCoordinate

public void tTextureCoordinate(TextureCoordinate n)
Traverses a TextureCoordinate node.

Specified by:
tTextureCoordinate in class Traverser
Parameters:
n - a TextureCoordinate node to traverse

tNormal

public void tNormal(Normal n)
Traverses a Normal node.

Specified by:
tNormal in class Traverser
Parameters:
n - a Normal node to traverse

tCoordinate

public void tCoordinate(Coordinate n)
Traverses a Coordinate node.

Specified by:
tCoordinate in class Traverser
Parameters:
n - a Coordinate node to traverse

tColor

public void tColor(Color n)
Traverses a Color node.

Specified by:
tColor in class Traverser
Parameters:
n - a Color node to traverse

tText

public void tText(Text n)
Traverses a Texture node.

Specified by:
tText in class Traverser
Parameters:
n - a Text node to traverse

tSphere

public void tSphere(Sphere n)
Traverses a Sphere node.

Specified by:
tSphere in class Traverser
Parameters:
n - a Sphere node to traverse

tPointSet

public void tPointSet(PointSet n)
Traverses a PointSet node.

Specified by:
tPointSet in class Traverser
Parameters:
n - a PointSet node to traverse

tIndexedLineSet

public void tIndexedLineSet(IndexedLineSet n)
Traverses an IndexedLineSet node.

Specified by:
tIndexedLineSet in class Traverser
Parameters:
n - an IndexedLineSet node to traverse

tIndexedFaceSet

public void tIndexedFaceSet(IndexedFaceSet n)
Traverses an IndexedFaceSet node.

Specified by:
tIndexedFaceSet in class Traverser
Parameters:
n - an IndexedFaceSet node to traverse

tExtrusion

public void tExtrusion(Extrusion n)
Traverses an Extrusion node.

Specified by:
tExtrusion in class Traverser
Parameters:
n - an Extrusion node to traverse

tElevationGrid

public void tElevationGrid(ElevationGrid n)
Traverses an ElevationGrid node.

Specified by:
tElevationGrid in class Traverser
Parameters:
n - an ElevationGrid node to traverse

tCylinder

public void tCylinder(Cylinder n)
Traverses a Cylinder node.

Specified by:
tCylinder in class Traverser
Parameters:
n - a Cylinder node to traverse

tCone

public void tCone(Cone n)
Traverses a Cone node.

Specified by:
tCone in class Traverser
Parameters:
n - a Cone node to traverse

tBox

public void tBox(Box n)
Traverses a Box node.

Specified by:
tBox in class Traverser
Parameters:
n - a Box node to traverse

tVisibilitySensor

public void tVisibilitySensor(VisibilitySensor n)
Traverses a VisibilitySensor node.

Specified by:
tVisibilitySensor in class Traverser
Parameters:
n - a VisibilitySensor node to traverse

tTouchSensor

public void tTouchSensor(TouchSensor n)
Traverses a TouchSensor node.

Specified by:
tTouchSensor in class Traverser
Parameters:
n - a TouchSensor node

tTimeSensor

public void tTimeSensor(TimeSensor n)
Traverses a TimeSensor node.

Specified by:
tTimeSensor in class Traverser
Parameters:
n - a TimeSensor node to traverse

tSphereSensor

public void tSphereSensor(SphereSensor n)
Traverses a SphereSensor node.

Specified by:
tSphereSensor in class Traverser
Parameters:
n - a SphereSensor node to traverse

tProximitySensor

public void tProximitySensor(ProximitySensor n)
Traverses a ProximitySensor node.

Specified by:
tProximitySensor in class Traverser
Parameters:
n - a ProximitySensor node to traverse

tPlaneSensor

public void tPlaneSensor(PlaneSensor n)
Traverses a PlaneSensor node.

Specified by:
tPlaneSensor in class Traverser
Parameters:
n - a PlaneSensor node to traverse

tCylinderSensor

public void tCylinderSensor(CylinderSensor n)
Traverses a CylinderSensor node.

Specified by:
tCylinderSensor in class Traverser
Parameters:
n - a CylinderSensor node to traverse

tWorldInfo

public void tWorldInfo(WorldInfo n)
Traverses a WorldInfo node.

Specified by:
tWorldInfo in class Traverser
Parameters:
n - a WorldInfo node to traverse

tScript

public void tScript(Script n)
Traverses a Script node.

Specified by:
tScript in class Traverser
Parameters:
n - a Script node to traverse

tSpotLight

public void tSpotLight(SpotLight n)
Traverses a SpotLight node.

Specified by:
tSpotLight in class Traverser
Parameters:
n - a SpotLight node to traverse

tSound

public void tSound(Sound n)
Traverses a Sound node.

Specified by:
tSound in class Traverser
Parameters:
n - a Sound node to traverse

tShape

public void tShape(Shape n)
Traverses a Shape node.

Specified by:
tShape in class Traverser
Parameters:
n - a Shape node to traverse

tPointLight

public void tPointLight(PointLight n)
Traverses a PointLight node.

Specified by:
tPointLight in class Traverser
Parameters:
n - a PointLight node to traverse

tDirectionalLight

public void tDirectionalLight(DirectionalLight n)
Traverses a DirectionalLight node.

Specified by:
tDirectionalLight in class Traverser
Parameters:
n - a DirectionalLight node to traverse

tAudioClip

public void tAudioClip(AudioClip n)
Traverses an AudioClip node.

Specified by:
tAudioClip in class Traverser
Parameters:
n - an AudioClip node to traverse

tSwitch

public void tSwitch(Switch n)
Traverses a Switch node.

Overrides:
tSwitch in class Traverser
Parameters:
n - a Switch node to traverse

tLOD

public void tLOD(LOD n)
Traverses a LOD node.

Overrides:
tLOD in class Traverser
Parameters:
n - a LOD node to traverse

tInline

public void tInline(Inline n)
Traverses an Inline node.

Overrides:
tInline in class Traverser
Parameters:
n - an Inline node

tTransform

public void tTransform(Transform n)
Traverses a Transform node.

Overrides:
tTransform in class Traverser
Parameters:
n - a Transform node to traverse

tCollision

public void tCollision(Collision n)
Traverses a Collision node.

Overrides:
tCollision in class Traverser
Parameters:
n - a Collision node to traverse

tBillboard

public void tBillboard(Billboard n)
Traverses a Billboard node.

Overrides:
tBillboard in class Traverser
Parameters:
n - a Billboard node to traverse

tAnchor

public void tAnchor(Anchor n)
Traverses an Anchor node.

Overrides:
tAnchor in class Traverser
Parameters:
n - an Anchor node to traverse

tGroup

public void tGroup(Group n)
Traverses a Group node.

Overrides:
tGroup in class Traverser
Parameters:
n - a Group node to traverse

setObjectName

private boolean setObjectName(org.w3c.dom.Element element,
                              java.lang.String objname)
Registers object name for the node. The ojbect name can either be a DEF attribute or an USE attribute. If the name is unique, then it is for the DEF attribute, else it is for the USE attribute.

Parameters:
element - the node element
objname - the object name
Returns:
true if the object name is a DEF, or false if it is a USE

convertToString

private java.lang.String convertToString(boolean bool)
Returns a string representation of a boolean.

Parameters:
bool - a boolean value
Returns:
a string representation of the given boolean

convertToString

private java.lang.String convertToString(int[] array,
                                         int length)
Returns a string representation of a integer array.

Parameters:
array - an array containing integer elements
length - number of valid integer numbers
Returns:
a string representation of the given integer array

convertToString

private java.lang.String convertToString(int[] array,
                                         int length,
                                         int count)
Returns a string representation of a integer array.

Parameters:
array - an array containing integer elements
length - number of valid integer numbers
count - number of float numbers on a single line
Returns:
a string representation of the given integer array

convertToString

private java.lang.String convertToString(float[] array,
                                         int length)
Returns a string representation of a float array.

Parameters:
array - an array containing float elements
length - number of valid float numbers
Returns:
a string representation of the given float array

convertToString

private java.lang.String convertToString(float[] array,
                                         int length,
                                         int count)
Returns a string representation of a float array.

Parameters:
array - an array containing float elements
length - number of valid float numbers
count - number of float numbers on a single line
Returns:
a string representation of the given float array

convertToString

private java.lang.String convertToString(java.lang.String[] array,
                                         int length,
                                         boolean wrapInQuotes)
Returns a string representation of a string array.

Parameters:
array - an array containing string elements
length - number of valid strings
wrapInQuotes - if true, wrape each string in quotes, false otherwise
Returns:
a string representation of the given string array

arraysEqual

private boolean arraysEqual(float[] array1,
                            float[] array2)
Returns a boolean value indicating whether two float arrays have equal values. The arrays are equal only if every element in one array is equal to the corresponding element in the other array.

Parameters:
array1 - first array of float elements
array2 - second array of float elements
Returns:
true if two arrays are equal, false otherwise

arraysEqual

private boolean arraysEqual(int[] array1,
                            int[] array2)
Returns a boolean value indicating whether two integer arrays have equal values. The arrays are equal only if every element in one array is equal to the corresponding element in the other array.

Parameters:
array1 - first array of integer elements
array2 - second array of integer elements
Returns:
true if two arrays are equal, false otherwise

arraysEqual

private boolean arraysEqual(java.lang.String[] array1,
                            java.lang.String[] array2)
Returns a boolean value indicating whether two string arrays have equal values. The arrays are equal only if every element in one array is equal to the corresponding element in the other array.

Parameters:
array1 - first array of string elements
array2 - second array of string elements
Returns:
true if two arrays are equal, false otherwise

getFieldElement

private org.w3c.dom.Element getFieldElement(Field f,
                                            java.lang.String name)
Returns a field Element by extracting data from the given Field object.

Parameters:
f - the structure that contains relevent data
name - user specified field name
Returns:
a field Element

traverseGenericNode

private void traverseGenericNode(Node node,
                                 org.w3c.dom.Element parent)
Traverses a generic node with a given parent.

Parameters:
node - the generic node to traverse
parent - the parent element