Source code: com/trapezium/vrml/grammar/NodeStatementRule.java
1 /*
2 * @(#)NodeStatementRule.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.grammar;
12
13 import com.trapezium.vrml.Scene;
14 import com.trapezium.vrml.VrmlElement;
15 import com.trapezium.parse.TokenEnumerator;
16
17
18 /**
19 * Creates the scene graph component for a node
20 *
21 * This is the only part of the grammar other than the VRML97parser
22 * that is publicly accessible. This is necessary because SFNodeValue
23 * and MFNodeValue in the com.trapezium.vrml.fields package
24 * use an instance of this to create node scene graph components.
25 *
26 * Grammar handled by "Build" method:
27 * <PRE>
28 * nodeStatement ::=
29 * node |
30 * DEF nodeNameId node |
31 * USE nodeNameId ;
32 * </PRE>
33 * The portion "DEF nodeNameId node" is handled by DEFRule.java
34 * The portion "USE nodeNameId" is handled by USERule.java
35 *
36 * @author Johannes N. Johannsen
37 * @version 1.12, 24 April 1998, NodeRule parameter for autodef
38 * @version 1.1, 12 Dec 1997
39 *
40 * @since 1.0
41 */
42 public class NodeStatementRule {
43 DEFRule defRule;
44 USERule useRule;
45 NodeRule nodeRule;
46
47 /** Constructor */
48 public NodeStatementRule( NodeRule nodeRule ) {
49 this.nodeRule = nodeRule;
50 defRule = new DEFRule( nodeRule );
51 useRule = new USERule();
52 }
53
54 /**
55 * Factory/Builder method for adding a node child to a parent element. DEFed nodes
56 * have file scope, so register their names at the Scene level.
57 */
58 public void Build( int tokenOffset, TokenEnumerator v, Scene scene, VrmlElement parent ) {
59 GrammarRule.Enter( "NodeStatement" );
60
61 if ( v.sameAs( tokenOffset, "DEF" )) {
62 defRule.Build( tokenOffset, v, scene, parent );
63 } else if ( v.sameAs( tokenOffset, "USE" )) {
64 useRule.Build( tokenOffset, v, scene, parent );
65 } else {
66 nodeRule.Build( tokenOffset, v, scene, parent );
67 }
68 GrammarRule.Exit( "NodeStatement" );
69 }
70 }