21 rNodes =
new ArrayList(1);
22 routes =
new ArrayList(1);
23 metaData =
new HashMap();
28 profile =
FWProfInfo.getProfile(
new String(
"Full"));
32 for (
int i = 0; i < n.length; i++) {
42 String tofield, fromfield;
43 StringTokenizer tokens;
48 root = (
FreeWRLNode) browser.getNode(
"_Sarah_this_is_the_FreeWRL_System_Root_Node");
50 MFNode children = (MFNode) root.getField(
"children");
51 numnodes = children.size();
53 children.getValue(nodes);
54 for (i = 0; i < numnodes; i++) {
57 retval = browser.sendGlobalCommand(
"j");
59 tokens =
new StringTokenizer(retval);
61 numRoutes = Integer.parseInt(tokens.nextToken());
63 for (i = 0; i < numRoutes; i++) {
65 fromnode.setPerlPtr(tokens.nextToken());
66 fromnode.setPointer(tokens.nextToken());
67 fromfield = tokens.nextToken();
69 tonode.setPerlPtr(tokens.nextToken());
70 tonode.setPointer(tokens.nextToken());
71 tofield = tokens.nextToken();
72 route =
new FWRoute(fromnode, fromfield, tonode, tofield);
80 metaData =
new HashMap();
81 rNodes =
new ArrayList(1);
82 routes =
new ArrayList(1);
87 profile =
FWProfInfo.getProfile(
new String(
"Full"));
92 metaData =
new HashMap();
101 rNodes =
new ArrayList(1);
102 routes =
new ArrayList(1);
104 if ((profile !=
null) && (components !=
null)) {
105 ComponentInfo[] profcomps = profile.getComponents();
106 tempcomps =
new ArrayList(1);
108 for (i = 0; i < profcomps.length; i++) {
110 for (j = 0; j < components.length; j++) {
111 if ((profcomps[i].getName()).equals(components[j].getName())) {
112 if ((profcomps[i].getLevel()) > (components[j].getLevel())) {
113 tempcomps.add(profcomps[i]);
116 tempcomps.add(components[j]);
122 tempcomps.add(profcomps[i]);
126 for (j = 0; j < components.length; j++) {
128 for (i = 0; i < profcomps.length; i++) {
129 if ((profcomps[i].getName()).equals(components[j].getName())) {
134 tempcomps.add(components[j]);
138 Object[] returnval = tempcomps.toArray();
142 for (i = 0; i < returnval.length; i++) {
149 public void setCurrent(
boolean val) {
153 public String getMetaData(String
key)
throws InvalidExecutionContextException {
154 return (String) metaData.get(
key);
157 public void setMetaData(String
key, String value)
throws InvalidExecutionContextException {
158 metaData.put(
key, value);
161 public X3DNode getExportedNode(String nodeName)
throws InvalidExecutionContextException, NodeUnavailableException, InvalidNameException {
163 return browser.getNode(nodeName);
166 public void updateExportedNode(String nodeName, String newName)
throws InvalidExecutionContextException, InvalidNameException {
173 nodeRef = browser.getNode(nodeName);
175 retval = browser.sendGlobalCommand(
"c " + newName +
" " + nodeRef);
177 if (retval.equals(
"1")) {
178 throw new InvalidNameException(
"Unable to update node name: " + nodeName);
182 public void removeExportedNode(String nodeName)
throws InvalidExecutionContextException, InvalidNameException {
187 retval = browser.sendGlobalCommand(
"d " + nodeName);
189 if (retval.equals(
"1")) {
190 throw new InvalidNameException(
"Unable to remove node name: " + nodeName);
194 public void addRootNode(
X3DNode rootNode)
throws InvalidExecutionContextException, NodeInUseException, InsufficientCapabilitiesException {
200 if (rootNode ==
null) {
206 rNodes.add(rootNode);
208 root = (
FreeWRLNode) browser.getNode(
"_Sarah_this_is_the_FreeWRL_System_Root_Node");
209 MFNode addChildren = (MFNode) root.getField(
"addChildren");
210 addChildren.setValue(1, nodes);
214 public void removeRootNode(
X3DNode rootNode)
throws InvalidExecutionContextException {
221 if (rootNode ==
null) {
227 index = rNodes.indexOf(rootNode);
229 System.out.println(
"Node not present");
232 rNodes.remove(index);
234 root = (
FreeWRLNode) browser.getNode(
"_Sarah_this_is_the_FreeWRL_System_Root_Node");
235 MFNode removeChildren = (MFNode) root.getField(
"removeChildren");
236 removeChildren.setValue(1, nodes);
240 public String getSpecificationVersion()
throws InvalidExecutionContextException {
243 spec = browser.sendGlobalCommand(
"Y");
244 int version = Integer.parseInt(spec);
246 spec =
new String(
"2.0");
247 }
else if (version == 4) {
248 spec =
new String(
"1.0");
250 spec =
new String(
"0.0");
255 public int getEncoding()
throws InvalidExecutionContextException {
258 spec = browser.sendGlobalCommand(
"Y");
259 return Integer.parseInt(spec);
262 public ProfileInfo getProfile()
throws InvalidExecutionContextException {
267 public ComponentInfo[] getComponents()
throws InvalidExecutionContextException {
272 public String getWorldURL()
throws InvalidExecutionContextException {
276 myurl = browser.sendGlobalCommand(
"O");
281 public X3DNode getNamedNode(String nodeName)
throws InvalidExecutionContextException, NodeUnavailableException, InvalidNameException {
283 return browser.getNode(nodeName);
286 public X3DNode getImportedNode(String nodeName)
throws InvalidExecutionContextException, NodeUnavailableException, InvalidNameException {
288 return browser.getNode(nodeName);
291 public X3DNode createNode(String nodeName)
throws InvalidExecutionContextException, InvalidNameException {
293 StringTokenizer tokens;
298 if (nodeName ==
null) {
299 throw new InvalidNameException(
"No node of type " + nodeName +
" exists");
302 retval = browser.sendGlobalCommand(
"a " + nodeName);
304 if (retval.equals(
"")) {
305 throw new InvalidNameException(
"No node of type " + nodeName +
" exists");
307 tokens =
new StringTokenizer(retval);
309 newnode.setPerlPtr(tokens.nextToken());
310 newnode.setPointer(tokens.nextToken());
316 public X3DProtoInstance createProto(String protoName)
throws InvalidExecutionContextException, InvalidNameException {
318 StringTokenizer tokens;
323 if (protoName ==
null) {
324 throw new InvalidNameException(
"No PROTO of type " + protoName +
" exists");
327 retval = browser.sendGlobalCommand(
"b " + protoName);
328 if (retval.equals(
"")) {
329 throw new InvalidNameException(
"No PROTO of type " + protoName +
" exists");
331 tokens =
new StringTokenizer(retval);
333 proto.setPerlPtr(tokens.nextToken());
334 proto.setPointer(tokens.nextToken());
335 proto.setNodeName(protoName);
342 public void updateNamedNode(String nodeName,
X3DNode nodeRef)
throws InvalidExecutionContextException, InvalidNameException, ImportedNodeException {
347 retval = browser.sendGlobalCommand(
"c " + nodeName +
" " + nodeRef);
349 if (retval.equals(
"1")) {
350 throw new InvalidNameException(
"Unable to update node name: " + nodeName);
354 public void updateImportedNode(String nodeName, String importedName,
X3DNode nodeRef)
throws InvalidExecutionContextException, InvalidNameException, ImportedNodeException {
358 public void removeNamedNode(String nodeName)
throws InvalidExecutionContextException, InvalidNameException {
363 retval = browser.sendGlobalCommand(
"d " + nodeName);
365 if (retval.equals(
"1")) {
366 throw new InvalidNameException(
"Unable to remove node name: " + nodeName);
370 public void removeImportedNode(String nodeName)
throws InvalidExecutionContextException, InvalidNameException {
375 retval = browser.sendGlobalCommand(
"d " + nodeName);
377 if (retval.equals(
"1")) {
378 throw new InvalidNameException(
"Unable to remove imported node name: " + nodeName);
382 public X3DProtoDeclaration getProtoDeclaration(String protoName)
throws InvalidExecutionContextException, InvalidNameException {
384 StringTokenizer tokens;
397 retval = browser.sendGlobalCommand(
"e " + protoName);
399 if (retval.equals(
"1")) {
400 throw new InvalidNameException(
"The proto declaration " + protoName +
" does not exist");
405 tokens =
new StringTokenizer(retval);
407 dec.setProtoName(tokens.nextToken());
408 type = tokens.nextToken();
409 numFields = Integer.valueOf(tokens.nextToken()).intValue();
413 for (
int i = 0; i < numFields; i++) {
414 fieldAccess = tokens.nextToken();
415 fieldType = tokens.nextToken();
416 fieldName = tokens.nextToken();
420 defaultValue = tokens.nextToken();
426 if (defaultValue.equals(
"[")) {
427 while(!temp.equals(
"]")) {
428 temp = tokens.nextToken();
429 defaultValue = defaultValue +
" " + temp;
433 if (defaultValue.charAt(0) == test) {
434 while(!temp.endsWith(tests)) {
435 temp = tokens.nextToken();
436 defaultValue = defaultValue +
" " + temp;
440 defs[i].setDefaultValue(defaultValue);
448 public void updateProtoDeclaration(String protoName, X3DProtoDeclaration newDeclaration)
throws InvalidExecutionContextException, InvalidNameException {
452 retval = browser.sendGlobalCommand(
"f " + protoName +
" " + newDeclaration);
453 System.out.println(
"sent: f " + protoName +
" " + newDeclaration);
455 if (retval.equals(
"1")) {
456 throw new InvalidNameException(
"Proto name " + protoName +
" is already in use");
461 public void removeProtoDeclaration(String protoName)
throws InvalidExecutionContextException, InvalidNameException {
465 if (protoName ==
null) {
466 throw new InvalidNameException(
"The proto declaration " + protoName +
" does not exist");
468 retval = browser.sendGlobalCommand(
"g " + protoName);
470 if (retval.equals(
"1")) {
471 throw new InvalidNameException(
"Unable to remove proto name: " + protoName);
475 public X3DExternProtoDeclaration getExternProtoDeclaration(String protoName)
throws InvalidExecutionContextException, InvalidNameException, URLUnavailableException {
476 return (X3DExternProtoDeclaration) getProtoDeclaration(protoName);
479 public void updateExternProtoDeclaration(String protoName, X3DExternProtoDeclaration newDeclaration)
throws InvalidExecutionContextException {
480 updateProtoDeclaration(protoName, newDeclaration);
483 public void removeExternProtoDeclaration(String protoName)
throws InvalidExecutionContextException {
484 removeProtoDeclaration(protoName);
487 public X3DNode[] getRootNodes()
throws InvalidExecutionContextException {
489 Object[] returnval = rNodes.toArray();
491 for (
int i = 0; i < rNodes.size(); i++)
496 public X3DRoute[] getRoutes()
throws InvalidExecutionContextException {
498 Object[] returnval = routes.toArray();
500 for (
int i = 0; i < routes.size(); i++)
501 temp[i] = (
FWRoute) returnval[i];
505 public X3DRoute addRoute(
X3DNode startNode, String startName,
X3DNode endNode, String endEvent)
throws InvalidExecutionContextException, InvalidNodeException, InvalidFieldException {
510 System.out.println(
"retval: " + retval);
511 if (retval.equals(
"1")) {
512 throw new InvalidFieldException(
"Unable to create ROUTE");
519 public void removeRoute(X3DRoute route)
throws InvalidExecutionContextException, InvalidNodeException, InvalidFieldException {
523 throw new InvalidNodeException(
"No such route exists");
526 index = routes.indexOf(route);
528 System.out.println(
"Route not present");
532 routes.remove(index);
534 browser.deleteRoute((
FreeWRLNode)(route.getSourceNode()), route.getSourceField(), (
FreeWRLNode)(route.getDestinationNode()), route.getDestinationField());
537 public void checkValid() {
539 throw new InvalidExecutionContextException(
"This context has been disposed");
543 public void dispose() {