/** * Sends the XML-RPC request according to the uFlow format * * @return the reply of the server as a UReply object */ private UReply uRequest( String method, String id, String doc, String arg1, String arg2, String arg3) { /* the object received from the xmlrpc server, it is a vector with command-dependant size */ Vector vector = new Vector(); /* what will be replied to the calling client */ UReply reply = null; int error = UReply.OK; /* the vector to be used as param by the xmlrpc client */ Vector params = new Vector(); params.add(id); params.add(doc); if (arg1 != null) params.add((String) arg1); // there are always 3 or less arguments (see uFlow spec) if (arg2 != null) params.add((String) arg2); if (arg3 != null) params.add((String) arg3); /* execute the request */ try { System.out.println("->-- METHOD=" + method + " params=" + params.toString()); vector = (Vector) this.execute(method, params); System.out.println("-->- " + vector.toString() + " " + vector.getClass().getName()); } catch (org.apache.xmlrpc /*.applet*/.XmlRpcException e) { e.printStackTrace(); error = UReply.BAD_REPLY; } catch (java.io.IOException e) { e.printStackTrace(); error = UReply.SERVER_NOT_FOUND; } /* retrieve the error code */ if (((Integer) vector.elementAt(0)).intValue() != UReply.OK) // do not erase any previous error error = ((Integer) vector.elementAt(0)).intValue(); String errorMsg = (String) vector.elementAt(1); /* build the appropriate reply */ if (method.equals("OPEN")) reply = new UrOpen( error, errorMsg, (String) vector.elementAt(2), (String) vector.elementAt(3), (String) vector.elementAt(4), (String) vector.elementAt(5), (String) vector.elementAt(6), (String) vector.elementAt(7), (String) vector.elementAt(8)); if (method.equals("LIST")) reply = new UrList( error, errorMsg, (String) vector.elementAt(2), (String) vector.elementAt(3), (String) vector.elementAt(4), (String) vector.elementAt(5)); if (method.equals("GET_MEDIA")) reply = new UrGetMedia( error, errorMsg, (String) vector.elementAt(2), (String) vector.elementAt(3), (String) vector.elementAt(4), (String) vector.elementAt(5), (String) vector.elementAt(6)); /* case for SAVE and CLOSE */ if (reply == null) reply = new UReply(error, errorMsg); System.out.println("---> " + reply.toString()); return reply; }
@SuppressWarnings("unchecked") public AnimatorCore(File file) throws FileNotFoundException { Beans.setDesignTime(false); rootContext = new BeanContextServicesSupport(); try { URL specURL = new URL("file:///E:/czt/zml/examples/z/birthdaybook_unfolded.tex"); history = new ZLiveHistory("BirthdayBook", "InitBirthdayBook", specURL); } catch (MalformedURLException ex) { ex.printStackTrace(); } XMLDecoder decoder; decoder = new XMLDecoder(new FileInputStream(file), this); try { while (true) { final Form newForm; newForm = (Form) decoder.readObject(); final JFrame frame = new JFrame() { /** */ private static final long serialVersionUID = 4731706062562233200L; public void setVisible(boolean b) { super.setVisible(b); if (newForm.isVisible() != b) newForm.setVisible(b); }; }; newForm.addComponentListener( new ComponentAdapter() { public void componentHidden(ComponentEvent e) { // If the last form was closed, then quit. Vector<Form> visibleForms = new Vector<Form>(forms_); for (Iterator<Form> i = visibleForms.iterator(); i.hasNext(); ) if (!i.next().isVisible()) i.remove(); visibleForms.remove(e.getComponent()); if (visibleForms.isEmpty()) System.exit(0); }; }); newForm.addPropertyChangeListener( "title", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { frame.setTitle((String) evt.getNewValue()); }; }); if (!newForm.isPreferredSizeSet()) newForm.setPreferredSize(newForm.getSize()); newForm.setLocation(0, 0); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(newForm, BorderLayout.CENTER); frame.pack(); frame.setTitle(newForm.getTitle()); // XXX URGENT setVisible should be moved after the init scripts. // If somebody starts using the interface before the init script // finishes it can have `weird and fun' side-effects // frame.setVisible(newForm.getStartsVisible()); forms_.add(newForm); decoder.readObject(); // beanWrappers // unchecked Vector<BeanLink> beanLinks = (Vector<BeanLink>) decoder.readObject(); // eventLinks for (Iterator<BeanLink> iter = beanLinks.iterator(); iter.hasNext(); ) { BeanLink bl = iter.next(); IntrospectionHelper.addBeanListener(bl.source, bl.listenerType, bl.listener); } rootContext.add(newForm); // unchecked } } catch (ArrayIndexOutOfBoundsException ex) { } finally { decoder.close(); } // XXX Load Z specification. // XXX Display appropriate forms. BSFManager bsfm = new BSFManager(); // XXX (register any new scripting languages) // XXX register and declare beans in bsfm try { bsfm.declareBean("History", history, history.getClass()); bsfm.declareBean("AnimatorCore", this, this.getClass()); bsfm.declareBean("Forms", forms_, forms_.getClass()); bsfm.declareBean("err", System.err, System.err.getClass()); bsfm.declareBean("out", System.out, System.out.getClass()); } catch (BSFException ex) { throw new Error( "History,AnimatorCore, or Forms couldn't be declared " + "with the Scripting Engine. " + ex); } rootContext.addService(BSFManager.class, new BSFServiceProvider(bsfm)); rootContext.addService(History.class, new HistoryServiceProvider(history)); try { bsfm.exec(initScriptLanguage_, "init", 1, 1, initScript_); } catch (BSFException ex) { // XXX Do something? // error dialog? // send message back? // make it settable? System.err.println("Init Script caught BSFException:"); System.err.println(ex); ex.printStackTrace(); System.err.println("------"); ex.getTargetException().printStackTrace(); } ; for (Iterator<Form> it = forms_.iterator(); it.hasNext(); ) { Form form = it.next(); boolean v = form.getStartsVisible(); form.setVisible(v); System.err.println("Setting visible " + form.getName() + " = " + v); } };