FreeWRL/FreeX3D  3.0.0
FreeWRLNode.java
1 package sai;
2 import org.web3d.x3d.sai.*;
3 
4 import java.util.*;
5 
6 public class FreeWRLNode implements X3DNode {
7  private String name = null; // Node name
8  private int type = -1; // Node type
9  private String ptr = null; // Pointer to the node
10  private String perlPtr = null;
11  boolean disposed;
12  FreeWRLBrowser browser;
13 
14  public FreeWRLNode(FreeWRLBrowser b) {
15  browser = b;
16  disposed = false;
17  }
18 
19  public String toString() {
20  String str;
21  str = new String("NODE" + perlPtr);
22  return str;
23  }
24 
25  public boolean equals(Object o) {
26  return (o != null) && (o instanceof FreeWRLNode) && (ptr== ((FreeWRLNode)o).getPointer());
27  }
28 
29  public String getNodeName() throws InvalidNodeException, ConnectionException {
30  checkValid();
31  return name;
32  }
33 
34  public void setPerlPtr(String p) {
35  perlPtr = p;
36  }
37 
38  public String getPerlPtr() {
39  return perlPtr;
40  }
41 
42  public String getName() {
43  return name;
44  }
45  public int[] getNodeType() throws InvalidNodeException, ConnectionException {
46  checkValid();
47  String retval;
48  int[] ret = new int[1];
49  retval = browser.sendGlobalCommand("k " + ptr);
50  ret[0] = Integer.parseInt(retval);
51  return ret;
52  }
53  public X3DFieldDefinition[] getFieldDefinitions() throws InvalidNodeException, ConnectionException {
54  String command;
55  String retval;
56  String name, access, type;
57  StringTokenizer tokens;
59  int numFields;
60  int i;
61  int iaccess, itype;
62 
63  checkValid();
64  command = "h " + ptr;
65  retval = browser.sendGlobalCommand(command);
66  System.out.println("got retval: " + retval);
67 
68  tokens= new StringTokenizer(retval);
69 
70  if ((retval == null) || (retval.equals(""))) {
71  return null;
72  }
73 
74  numFields = Integer.parseInt(tokens.nextToken());
75 
76  defs = new FreeWRLFieldDefinition[numFields];
77 
78  for (i = 0; i < numFields; i++) {
79  name = tokens.nextToken();
80  type = tokens.nextToken();
81  access = tokens.nextToken();
82  itype = FreeWRLFieldTypes.getIntType(type);
83  iaccess = FreeWRLFieldTypes.getAccessFromType(access);
84  defs[i] = new FreeWRLFieldDefinition(name, iaccess, itype);
85  }
86 
87  return defs;
88  }
89  public X3DField getField(String fieldName) throws InvalidNameException, InvalidNodeException, ConnectionException {
90  FreeWRLField ret;
91  String NNN = "nodeFrom_getEventIn";
92  StringTokenizer tokens;
93 
94  checkValid();
95 
96  // Return the type that is asked for. To determine the subclass, look at the string.
97  String st = browser.SendEventType(perlPtr, ptr, fieldName, "eventIn");
98 
99  tokens = new StringTokenizer(st);
100  String NNPR = tokens.nextToken();
101  String NOFF = tokens.nextToken();
102  String NDS = tokens.nextToken();
103  String NewDT = tokens.nextToken();
104  String ScrT = tokens.nextToken();
105  String access = tokens.nextToken();
106 
107  if (access.equals("FreeWRLPTR")) {
108  throw new InvalidFieldException("Field name " + fieldName + " is not a valid field for this node");
109  }
110  int ia = FreeWRLFieldTypes.getAccessFromType(access);
112 
113  if (NewDT.equals("p")) {
114  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
115  ret = new FWMFString(def, browser);
116  } else if (NewDT.equals("k")) {
117  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
118  ret = new FWSFImage(def, browser);
119  } else if (NewDT.equals("e")) {
120  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
121  ret = new FWSFTime(def, browser);
122  } else if (NewDT.equals("c")) {
123  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
124  ret = new FWSFColor(def, browser);
125  } else if (NewDT.equals("l")) {
126  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
127  ret = new FWMFColor(def, browser);
128  } else if (NewDT.equals("d")) {
129  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
130  ret = new FWSFFloat(def, browser);
131  } else if (NewDT.equals("m")) {
132  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
133  ret = new FWMFFloat(def, browser);
134  } else if (NewDT.equals("o")) {
135  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
136  ret = new FWMFInt32(def, browser);
137  } else if (NewDT.equals("h")) {
138  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
139  ret = new FWSFNode(def, browser);
140  } else if (NewDT.equals("r")) {
141  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
142  ret = new FWMFRotation(def, browser);
143  } else if (NewDT.equals("s")) {
144  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
145  ret = new FWMFVec2f(def, browser);
146  } else if (NewDT.equals("j")) {
147  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
148  ret = new FWSFVec2f(def, browser);
149  } else if (NewDT.equals("l")) {
150  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
151  ret = new FWMFVec3f(def, browser);
152  } else if (NewDT.equals("q")) {
153  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
154  ret = new FWMFNode(def, browser);
155  } else if (NewDT.equals("i")) {
156  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
157  ret = new FWSFRotation(def, browser);
158  } else if (NewDT.equals("g")) {
159  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
160  ret = new FWSFString(def, browser);
161  } else if (NewDT.equals("b")) {
162  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
163  ret = new FWSFBool(def, browser);
164  } else if (NewDT.equals("f")) {
165  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
166  ret = new FWSFInt32(def, browser);
167  } else if (NewDT.equals("v")) {
168  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
169  ret = new FWMFColorRGBA(def, browser);
170  } else if (NewDT.equals("w")) {
171  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
172  ret = new FWSFColorRGBA(def, browser);
173  } else if (NewDT.equals("u")) {
174  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
175  ret = new FWSFVec3f(def, browser);
176  } else if (NewDT.equals("z")) {
177  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
178  ret = new FWSFVec3d(def, browser);
179  } else if (NewDT.equals("A")) {
180  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
181  ret = new FWMFVec3d(def, browser);
182  } else if (NewDT.equals("B")) {
183  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
184  ret = new FWSFVec2d(def, browser);
185  } else if (NewDT.equals("C")) {
186  def = new FreeWRLFieldDefinition(fieldName, ia, FreeWRLFieldTypes.getIntType(NewDT));
187  ret = new FWMFVec2d(def, browser);
188  } else {
189  throw new InvalidFieldException("Field name " + fieldName + " is not a valid field for this node");
190  }
191 
192  ret.setCommand(fieldName);
193  ret.setNode(NNN);
194  ret.setDataType(NewDT);
195  ret.setNodePtr(NNPR);
196  ret.setOffset(NOFF);
197  ret.setDataSize(NDS);
198  ret.setScriptType(ScrT);
199  return ret;
200  }
201  public void dispose() throws InvalidNodeException {
202  disposed = true;
203  }
204 
205  public void setNodeName(String n) {
206  name = n;
207  }
208 
209  public void setType(int t) {
210  type = t;
211  }
212 
213  public void setPointer(String p) {
214  ptr = p;
215  }
216 
217  public String getPointer() {
218  return ptr;
219  }
220 
221  public void setMetadata(X3DMetadataObject data) throws InvalidNodeException, ConnectionException {
222  checkValid();
223  }
224 
225  public X3DMetadataObject getMetadata() throws InvalidNodeException, ConnectionException {
226  checkValid();
227  return null;
228  }
229 
230  private void checkValid() {
231  if (disposed) {
232  throw new InvalidNodeException ("This node has been disposed");
233  }
234  }
235 }