1 package org.myoodb.jythonWeb; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 31 public class Client extends java.applet.Applet implements Runnable , ActionListener 32 { 33 public static int PORT = 80; 34 public static String USERNAME = "admin"; 36 public static String PASSWORD = "admin"; 37 38 private Thread m_thread; 39 private Button m_loadButton; 40 private TextArea m_textArea; 41 42 private synchronized void waitForLoadRequest() 43 { 44 try 45 { 46 wait(); 47 } 48 catch (InterruptedException e) 49 { 50 } 51 } 52 53 private synchronized void loadScriptNotify() 54 { 55 notify(); 56 } 57 58 public void init() 59 { 60 m_textArea = new TextArea(10, 80); 61 m_textArea.setEditable(false); 62 63 m_loadButton = new Button("Get & Run Jython Script from Server"); 64 m_loadButton.addActionListener(this); 65 66 setLayout(new BorderLayout()); 67 add("South", m_textArea); 68 add("North", m_loadButton); 69 } 70 71 public void run() 72 { 73 try 74 { 75 org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myooweb://" + getCodeBase().getHost() + ":" + PORT, USERNAME, PASSWORD); 76 78 Script script = (Script) db.getRoot("Script"); 79 80 if (script == null) 81 { 82 script = (Script) db.createRoot(ScriptDbImpl.class, "Script"); 83 } 85 86 org.python.util.PythonInterpreter interpreter = new org.python.util.PythonInterpreter(); 88 org.python.core.PySystemState.add_package("org.python.core"); 90 while (m_thread != null) 91 { 92 waitForLoadRequest(); 93 94 String code = script.getCode("WebExample.py"); 95 m_textArea.setText(code); 96 97 interpreter.exec(code); 98 } 99 } 100 catch (Exception e) 101 { 102 e.printStackTrace(); 103 } 104 } 105 106 public void start() 107 { 108 if (m_thread == null) 109 { 110 m_thread = new Thread (this); 111 m_thread.setDaemon(true); 112 m_thread.start(); 113 } 114 } 115 116 public void stop() 117 { 118 if (m_thread != null) 119 { 120 m_thread = null; 121 loadScriptNotify(); 122 } 123 } 124 125 public void actionPerformed(ActionEvent evt) 126 { 127 loadScriptNotify(); 128 } 129 } 130 | Popular Tags |