FreeWRL/FreeX3D  3.0.0
Node.java
1 package vrml.external;
2 
3 import vrml.external.field.*;
4 import vrml.external.exception.*;
5 import java.util.*;
6 //JAS import java.awt.*;
7 //JAS import java.net.*;
8 //JAS import java.io.*;
9 //JAS import java.lang.reflect.*;
10 
11 public class Node {
12  // Get a string specifying the type of this node. May return the
13  // name of a PROTO, or the class name
14 
15 
16 // the following fields are for treating this node as an eventIn or eventOut.
17  public int EventType = FieldTypes.UnknownType;
18  public String outNode; // Node to send the command to... NULL if not
19  // a get value from viewer call (ie, a Listener
20  // response...
21  public String inNode;
22  public String command; // the actual command...
23  public String RLreturn; // If this is a register listener response...
24  public int nodeptr = 0; //pointer to start of FreeWRL structure in memory
25  public int offset = 0; //offset of actual field in memory from base.
26  public int datasize = 0; // how long this data really is
27  public String datatype;
28  public int ScriptType = 0; // non zero indicates sending to a javascript
29 
30 
31 
32  public String getType() {
33  // spec says:
34  // Get a string specifying the type of this node. May return the
35  // name of a PROTO, or the class name
36  // this will return 2 strings, first X3D node, second DEF name, or __UNDEFINED
37 
38  String NT = Browser.SendNodeEAIType(nodeptr);
39  //System.out.println ("in Java, getType returns " + NT);
40  String[] spl = NT.split(" ",0);
41 
42  //System.out.println ("string split is " + spl[0] + " and " + spl[1]);
43  if (spl[1].equals("__UNDEFINED")) return spl[0];
44  return spl[1];
45  }
46 
47 
48  public EventIn getEventIn(String name) throws InvalidEventInException {
49 
50  EventIn ret;
51 
52  String NNN = "nodeFrom_getEventIn";
53  StringTokenizer tokens;
54 
55  // Return the type that is asked for. To determine the
56  // subclass, look at the string.
57 
58  String st = Browser.SendEventType(nodeptr, name, "eventIn");
59 
60  tokens = new StringTokenizer (st);
61  String NNPR = tokens.nextToken();
62  String NOFF = tokens.nextToken();
63  String NDS = tokens.nextToken();
64  String NewDT = tokens.nextToken();
65  String ScrT = tokens.nextToken();
66  //System.out.println ("EventIn: NNPR " + NNPR + " NOFF " + NOFF +
67  // " NDS " + NDS + " NewDT " + NewDT + " ScrTyp" + ScrT);
68 
69  // check out the return values specified in CFuncs/EAIServ.c
70  if(NewDT.equals("p")) { ret = new EventInMFString();
71  } else if(NewDT.equals("k")) { ret = new EventInSFImage();
72  } else if(NewDT.equals("e")) { ret = new EventInSFTime();
73  } else if(NewDT.equals("c")) { ret = new EventInSFColor();
74  } else if(NewDT.equals("l")) { ret = new EventInMFColor();
75  } else if(NewDT.equals("d")) { ret = new EventInSFFloat();
76  } else if(NewDT.equals("m")) { ret = new EventInMFFloat();
77  } else if(NewDT.equals("o")) { ret = new EventInMFInt32();
78  } else if(NewDT.equals("h")) { ret = new EventInSFNode();
79  } else if(NewDT.equals("r")) { ret = new EventInMFRotation();
80  } else if(NewDT.equals("s")) { ret = new EventInMFVec2f();
81  } else if(NewDT.equals("j")) { ret = new EventInSFVec2f();
82  } else if(NewDT.equals("t")) { ret = new EventInMFVec3f();
83  } else if(NewDT.equals("q")) { ret = new EventInMFNode();
84  } else if(NewDT.equals("i")) { ret = new EventInSFRotation();
85  } else if(NewDT.equals("g")) { ret = new EventInSFString();
86  } else if(NewDT.equals("b")) { ret = new EventInSFBool();
87  } else if(NewDT.equals("f")) { ret = new EventInSFInt32();
88  } else if(NewDT.equals("u")) { ret = new EventInSFVec3f();
89  } else {
90  throw new InvalidEventInException("getEventIn - node field error for \"" + name + "\"");
91  }
92 
93  ret.command = name; ret.inNode = NNN; ret.datatype=NewDT;
94  ret.nodeptr= Integer.parseInt(NNPR); ret.offset=Integer.parseInt(NOFF);
95  ret.datasize = Integer.parseInt(NDS); ret.ScriptType = Integer.parseInt(ScrT);
96  return ret;
97  }
98 
99 
100  // Means of getting a handle to an EventOut of this node
101 
102  public EventOut getEventOut(String name) throws InvalidEventOutException {
103  EventOut ret;
104  StringTokenizer tokens;
105  String NNN = "nodeFrom_getEventOut";
106 
107  String st = Browser.SendEventType(nodeptr, name, "eventOut");
108 
109  tokens = new StringTokenizer (st);
110  String NNPR = tokens.nextToken();
111  String NOFF = tokens.nextToken();
112  String NDS = tokens.nextToken();
113  String NewDT = tokens.nextToken();
114  String ScrT = tokens.nextToken();
115  // System.out.println ("EventOut: NNPR " + NNPR + " NOFF " + NOFF +
116  // " NDS " + NDS + " NewDT " + NewDT + " ScrTyp" + ScrT);
117 
118 
119 
120  // check out the return values specified in CFuncs/EAIServ.c
121  // #define EAI_SFUNKNOWN 'a'
122  // #define EAI_SFBOOL 'b'
123  // #define EAI_SFCOLOR 'c'
124  // #define EAI_SFFLOAT 'd'
125  // #define EAI_SFTIME 'e'
126  // #define EAI_SFINT32 'f'
127  // #define EAI_SFSTRING 'g'
128  // #define EAI_SFNODE 'h'
129  // #define EAI_SFROTATION 'i'
130  // #define EAI_SFVEC2F 'j'
131  // #define EAI_SFIMAGE 'k'
132  // #define EAI_MFCOLOR 'l'
133  // #define EAI_MFFLOAT 'm'
134  // #define EAI_MFTIME 'n'
135  // #define EAI_MFINT32 'o'
136  // #define EAI_MFSTRING 'p'
137  // #define EAI_MFNODE 'q'
138  // #define EAI_MFROTATION 'r'
139  // #define EAI_MFVEC2F 's'
140  // #define EAI_MFVEC3F 't'
141  // #define EAI_SFVEC3F 'u'
142 
143 
144  if(NewDT.equals("p")) { ret = new EventOutMFString();
145  } else if(NewDT.equals("k")) { ret = new EventOutSFImage();
146  } else if(NewDT.equals("e")) { ret = new EventOutSFTime();
147  } else if(NewDT.equals("c")) { ret = new EventOutSFColor();
148  } else if(NewDT.equals("l")) { ret = new EventOutMFColor();
149  } else if(NewDT.equals("d")) { ret = new EventOutSFFloat();
150  } else if(NewDT.equals("m")) { ret = new EventOutMFFloat();
151  } else if(NewDT.equals("o")) { ret = new EventOutMFInt32();
152  } else if(NewDT.equals("h")) { ret = new EventOutSFNode();
153  } else if(NewDT.equals("r")) { ret = new EventOutMFRotation();
154  } else if(NewDT.equals("s")) { ret = new EventOutMFVec2f();
155  } else if(NewDT.equals("j")) { ret = new EventOutSFVec2f();
156  } else if(NewDT.equals("t")) { ret = new EventOutMFVec3f();
157  } else if(NewDT.equals("q")) { ret = new EventOutMFNode();
158  } else if(NewDT.equals("i")) { ret = new EventOutSFRotation();
159  } else if(NewDT.equals("g")) { ret = new EventOutSFString();
160  } else if(NewDT.equals("b")) { ret = new EventOutSFBool();
161  } else if(NewDT.equals("f")) { ret = new EventOutSFInt32();
162  } else if(NewDT.equals("u")) { ret = new EventOutSFVec3f();
163  } else {
164  throw new InvalidEventOutException("getEventOut - node field error for field \"" + name + "\"");
165  }
166 
167  ret.command = name; ret.inNode = NNN; ret.datatype=NewDT;
168  ret.nodeptr=Integer.parseInt(NNPR); ret.offset=Integer.parseInt(NOFF);
169  ret.datasize = Integer.parseInt(NDS); ret.ScriptType = Integer.parseInt(ScrT);
170  return ret;
171  }
172 }