Source code: com/trapezium/vrml/grammar/DEFRule.java
1 /*
2 * @(#)DEFRule.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.vrml.node.DEFUSENode;
16 import com.trapezium.vrml.node.Node;
17 import com.trapezium.parse.TokenEnumerator;
18
19 /**
20 * Creates a DEF node scene graph component.
21 *
22 * Grammar handled by "Build" method:
23 * <PRE>
24 * DEF nodeNameId node
25 * </PRE>
26 * After the node is created, its name is registered in the Scene.
27 * If any other node is registered with that same name, both are
28 * marked with "duplicate DEF" warnings.
29 *
30 * @author Johannes N. Johannsen
31 * @version 1.12, 24 April 1998, nodeRule parameter for autodef
32 * @version 1.12, 12 March 1998, added Table 7 base profile warning
33 * @version 1.1, 12 Dec 1997
34 *
35 * @since 1.0
36 */
37 public class DEFRule {
38 NodeRule nodeRule;
39
40 DEFRule( NodeRule nodeRule ) {
41 this.nodeRule = nodeRule;
42 }
43
44 /** Create DEF node scene graph components, and add to the Scene graph.
45 *
46 * @param tokenOffset token starting the "DEF...."
47 * @param v TokenEnumerator containing file text
48 * @param scene Scene containing this DEF
49 * @param parent VrmlElement that is the immediate parent of this DEf
50 */
51 void Build( int tokenOffset, TokenEnumerator v, Scene scene, VrmlElement parent ) {
52 GrammarRule.Enter( "DEFRule.Build" );
53
54 // at this point, we know tok is "DEF", get next one
55 DEFUSENode d = new DEFUSENode( tokenOffset, v, DEFUSENode.DEF );
56 tokenOffset = v.getNextToken();
57 parent.addChild( d );
58 String defId = d.getId();
59 DEFUSENode checkDef = scene.getDEF( defId );
60 if ( defId != null ) {
61 if ( defId.length() > Table7.NameLimit ) {
62 d.setError( "Nonconformance, name length " + defId.length() + " exceeds base profile name length " + Table7.NameLimit );
63 }
64 }
65 scene.registerDEF( d );
66
67 nodeRule.Build( tokenOffset, v, scene, d );
68 d.setLastTokenOffset( v.getCurrentTokenOffset() );
69 if ( checkDef != null ) {
70 d.setError( "Warning, duplicate DEF" );
71 checkDef.setError( "Warning, duplicate DEF" );
72 }
73
74 GrammarRule.Exit( "DEFRule.Build" );
75 }
76 }