Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/trapezium/vrml/ROUTE.java


1   /*
2    * @(#)ROUTE.java
3    *
4    * Copyright (c) 1998 by Trapezium Development LLC.  All Rights Reserved.
5    *
6    * The information in this file is the property of Trapezium Development LLC
7    * and may be used only in accordance with the terms of the license granted
8    * by Trapezium.
9    *
10   */
11  package com.trapezium.vrml;
12  
13  import com.trapezium.parse.TokenEnumerator;
14  import com.trapezium.vrml.grammar.VRML97;
15  
16  /**
17   *  Scene graph component representing a ROUTE.
18   *
19   *  @author          Johannes N. Johannsen
20   *  @version         1.1, 17 Dec 1997
21   *
22   *  @since           1.0
23   */
24  public class ROUTE extends MultipleTokenElement {
25      /** ROUTE constructor */
26    public ROUTE( int tokenOffset, TokenEnumerator v ) {
27      super( tokenOffset );
28      v.breakLineAt( tokenOffset );
29    }
30  
31      /** Get the ROUTE source object field name */
32    public String getSourceFieldName() {
33        return( getChildFieldName( 0 ));
34    }
35  
36      /** Get the ROUTE destination object field name */
37    public String getDestFieldName() {
38        return( getChildFieldName( 2 ));
39    }
40  
41      /** Get the ROUTE source object DEF name */
42    public String getSourceDEFname() {
43        return( getChildNodeName( 0 ));
44    }
45  
46      /** Set the ROUTE source object DEF name */
47    public void setSourceDEFname( String newName ) {
48        setChildNodeName( 0, newName );
49    }
50  
51      /** Get the ROUTE destination object DEF name */
52    public String getDestDEFname() {
53        return( getChildNodeName( 2 ));
54    }
55    
56    /** Set the ROUTE dest object DEF name */
57    public void setDestDEFname( String newName ) {
58        setChildNodeName( 2, newName );
59    }
60  
61      /** Get the DEF name of a ROUTE node */
62    String getChildNodeName( int offset ) {
63        RouteElement re = (RouteElement)getChildAt( offset );
64        if ( re != null ) {
65            return( re.getNodeName() );
66        } else {
67            return( null );
68        }
69    }
70  
71      /** Set the DEF name of a particular ROUTE child */
72    void setChildNodeName( int offset, String newName ) {
73        RouteElement re = (RouteElement)getChildAt( offset );
74        if ( re != null ) {
75            re.setNodeName( newName );
76        }
77    }
78  
79    /** Get the name of a ROUTE field */
80    String getChildFieldName( int offset ) {
81        RouteElement re = (RouteElement)getChildAt( offset );
82        if ( re != null ) {
83            return( re.getFieldName() );
84        } else {
85            return( null );
86        }
87    }
88  
89      /** Get a particular RouteElement */
90      public RouteElement getRouteElement( int offset ) {
91          int counter = 0;
92          for ( int i = 0; i < numberChildren(); i++ ) {
93              VrmlElement e = getChildAt( i );
94              if ( e instanceof RouteElement ) {
95                  if ( counter == offset ) {
96                      return( (RouteElement)e );
97                  } else {
98                      counter++;
99                  }
100             }
101         }
102         return( null );
103     }
104     
105   public RouteDestination getRouteDestination() {
106     for ( int i = 0; i < numberChildren(); i++ ) {
107       VrmlElement e = getChildAt( i );
108       if ( e instanceof RouteDestination ) {
109         RouteDestination rd = (RouteDestination)e;
110         return( rd );
111       }
112     }
113     return( null );
114   }
115 
116     /** Verify that the data types of the ROUTE source and destination match */
117   public void checkTypes() {
118     RouteElement source = (RouteElement)getChildAt( 0 );
119     RouteElement dest = (RouteElement)getChildAt( 2 );
120     if (( source != null ) && ( dest != null )) {
121       String sourceType = source.getFieldType();
122       String destType = dest.getFieldType();
123       sourceType = VRML97.convertToVRML97( sourceType );
124       destType = VRML97.convertToVRML97( destType );
125       if (( sourceType != null ) && ( destType != null )) {
126         if ( sourceType.compareTo( destType ) != 0 ) {
127           setError( "type mismatch, routing " + sourceType + " to " + destType );
128         }
129       }
130     }
131   }
132 }