4 import java.lang.System;
5 import java.lang.reflect.*;
7 import java.util.Hashtable;
9 import java.util.Enumeration;
14 static Hashtable touched =
new Hashtable();
19 static BufferedReader EAIin;
20 static PrintWriter EAIout;
26 public static void add_touched(
Field f) {
27 touched.put(f, Boolean.TRUE);
30 public static void send_touched(String reqid)
throws IOException {
32 Enumeration e = touched.keys();
33 while(e.hasMoreElements()) {
38 String f = b.field() +
" " + val.getOffset();
41 String nodeid = n._get_nodeid();
42 EAIout.println(
"JSENDEV");
43 EAIout.println(nodeid);
49 EAIout.println(
"FINISHED "+reqid);
53 public static void main (String argv[])
54 throws ClassNotFoundException,
55 NoSuchMethodException,
56 InstantiationException,
57 IllegalAccessException,
58 InvocationTargetException,
71 while (sock == null) {
74 sock =
new Socket(
"localhost",Integer.parseInt(argv[0]));
75 }
catch (IOException e) {
77 counter = counter + 1;
79 System.out.println (
" ....FWJavaScript: Java code timed out finding FreeWRL");
82 try {Thread.sleep (500);}
catch (InterruptedException f) { }
86 EAIout =
new PrintWriter (sock.getOutputStream());
87 EAIin =
new BufferedReader(
new InputStreamReader(sock.getInputStream()));
90 System.out.println (
"Security manager commented out");
96 Hashtable scripts =
new Hashtable();
97 EAIout.println(
"JavaClass version 1.0 - www.crc.ca");
101 String cmd = EAIin.readLine();
112 nodeid =EAIin.readLine();
115 if(cmd.equals(
"NEWSCRIPT")) {
116 String url = EAIin.readLine();
117 reqid = EAIin.readLine();
122 = url.substring(url.lastIndexOf(
'/')+1);
123 if (classname.endsWith(
".class"))
124 classname = classname
125 .substring(0, classname.length() - 6);
129 .loadClass(classname).newInstance();
130 }
catch (Exception ex) {
131 System.out.println(
"Can't load script: "
135 s._set_nodeid(nodeid);
137 scripts.put(nodeid,s);
138 }
else if(cmd.equals(
"SETFIELD")) {
139 System.out.println (
"SETFIELD NOT HANDLED YET\n");
141 }
else if(cmd.equals(
"INITIALIZE")) {
143 reqid = EAIin.readLine();
146 }
else if(cmd.equals(
"EVENTSPROCESSED")) {
148 reqid = EAIin.readLine();
151 }
else if(cmd.equals(
"SENDEVENT")) {
153 String fname = EAIin.readLine();
154 String
ftype = EAIin.readLine();
155 reqid = EAIin.readLine();
163 FWCreateField.createConstField(ftype);
164 fval.__fromPerl(EAIin);
166 Double.parseDouble(EAIin.readLine());
175 throw new Exception(
"Invalid command '"
182 public static String getFieldType(
BaseNode node, String fieldname,
187 EAIout.println(
"GETFIELD " + node._get_nodeid() +
" " + fieldname +
" " + kind);
189 return EAIin.readLine();
190 }
catch (IOException e) {
191 throw new InternalError(
"Communication error: "+e);
195 public static void readField(
BaseNode node, String fieldName,
Field fld) {
197 FWJavaScript.EAIout.println(
"READFIELD " + node._get_nodeid() +
" " + fieldName);
198 FWJavaScript.EAIout.flush();
199 fld.__fromPerl(EAIin);
200 }
catch (IOException e) {
201 throw new InternalError(
"Communication error: "+e);
205 public static String getNodeType(
BaseNode node)
208 FWJavaScript.EAIout.println(
"GETTYPE "+ node._get_nodeid());
209 FWJavaScript.EAIout.flush();
210 return EAIin.readLine();
211 }
catch (IOException e) {
212 throw new InternalError(
"Communication error: "+e);
216 public static Browser getBrowser()
222 public static BaseNode[] createVrmlFromString(String vrmlSyntax)
226 FWJavaScript.EAIout.println(
"CREATEVRML");
227 FWJavaScript.EAIout.println(vrmlSyntax);
228 FWJavaScript.EAIout.println(
"EOT");
229 FWJavaScript.EAIout.flush();
230 String intstring = FWJavaScript.EAIin.readLine();
231 int number = Integer.parseInt(intstring);
243 for (
int i = 0; i < number; i++)
244 nodes[i] =
new Node(
""+EAIin.readLine()+
":"+EAIin.readLine());
247 }
catch (IOException e) {
248 throw new InternalError(
"Communication error: "+e);
253 public static BaseNode[] createX3DFromString(String vrmlSyntax)
257 FWJavaScript.EAIout.println(
"CREATEX3D");
258 FWJavaScript.EAIout.println(vrmlSyntax);
259 FWJavaScript.EAIout.println(
"EOT");
260 FWJavaScript.EAIout.flush();
261 String intstring = FWJavaScript.EAIin.readLine();
262 int number = Integer.parseInt(intstring);
274 for (
int i = 0; i < number; i++)
275 nodes[i] =
new Node(
""+EAIin.readLine()+
":"+EAIin.readLine());
278 }
catch (IOException e) {
279 throw new InternalError(
"Communication error: "+e);