Commit 93fefd78 authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Use the JSR223 API for explorer FScript console.

parent 97f2745a
......@@ -130,6 +130,7 @@
<version>${frascati.version}</version>
</dependency>
<!-- Bindings support -->
<dependency>
<groupId>org.objectweb.fractal.bf.connectors</groupId>
<artifactId>fractal-bf-connectors-soap-cxf</artifactId>
......@@ -150,6 +151,12 @@
<artifactId>fractal-bf-connectors-json-rpc</artifactId>
<version>${fractal-bf.version}</version>
</dependency>
<!-- Java RMI Binding dynamic reconfiguration support (set security manager) -->
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-binding-rmi</artifactId>
<version>${frascati.version}</version>
</dependency>
<!-- OW2 FraSCAti Servlet CXF. -->
<dependency>
......
......@@ -22,12 +22,16 @@
*/
package org.ow2.frascati.explorer.fscript.action;
import javax.script.Bindings;
import javax.script.ScriptContext;
import org.objectweb.fractal.api.Component;
import org.objectweb.util.explorer.api.MenuItem;
import org.objectweb.util.explorer.api.MenuItemTreeView;
import org.objectweb.util.explorer.api.TreeView;
import org.ow2.frascati.explorer.fscript.gui.Console;
import org.ow2.frascati.fscript.FraSCAtiScript;
import org.ow2.frascati.fscript.FraSCAtiFScript;
import org.ow2.frascati.fscript.jsr223.FraSCAtiScriptEngineFactory;
/**
* This class provides a way to interact with the FScript engine.
......@@ -50,7 +54,11 @@ public class FscriptAction
* @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
*/
public void actionPerformed(final MenuItemTreeView tree) throws Exception {
FraSCAtiScript.getSingleton().updateContext("root", (Component) tree.getSelectedObject());
FraSCAtiScriptEngineFactory factory = new FraSCAtiScriptEngineFactory();
Bindings ctx = FraSCAtiFScript.getSingleton().getScriptEngine().getBindings(ScriptContext.ENGINE_SCOPE);
factory.addDomainToContext(ctx);
factory.updateContext(ctx, "root", (Component) tree.getSelectedObject());
new Console().setVisible(true);
}
}
......@@ -38,6 +38,7 @@ import java.io.StringReader;
import java.util.Set;
import java.util.StringTokenizer;
import javax.script.ScriptException;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JEditorPane;
......@@ -53,10 +54,10 @@ import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import org.objectweb.fractal.fscript.FScriptException;
import org.objectweb.fractal.fscript.InvalidScriptException;
import org.objectweb.fractal.fscript.jsr223.InvocableScriptEngine;
import org.ow2.frascati.assembly.factory.api.ClassLoaderManager;
import org.ow2.frascati.fscript.FraSCAtiScript;
import org.ow2.frascati.explorer.ExplorerGUI;
import org.ow2.frascati.fscript.FraSCAtiFScript;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.swing.JFileChooser;
......@@ -70,6 +71,9 @@ public class Console extends JFrame {
private static final String title = "FraSCAti Script console";
private static final String prompt = "FraSCAtiScript> ";
/** The FraSCAti Script engine */
InvocableScriptEngine engine = null;
/** Graphical components. */
private JTextField input = new JTextField(40);
private JScrollPane outputScrollPane = new JScrollPane();
......@@ -92,6 +96,11 @@ public class Console extends JFrame {
*/
public Console() {
super(title);
// Get the script engine
engine = (InvocableScriptEngine) FraSCAtiFScript.getSingleton().getScriptEngine();
// GUI set up
this.setLayout( new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS) );
addStylesToDocument( output.getStyledDocument() );
addComponents();
......@@ -229,10 +238,10 @@ public class Console extends JFrame {
Reader source = new StringReader( editorPane.getText() );
displayMessage("Loading procedures from editor");
procs = FraSCAtiScript.getSingleton().getLoader().load(source);
procs = (Set<String>) engine.eval(source);
for (String proc : procs)
displayMessage("+-> Adding procedure '"+ proc +"'");
} catch (InvalidScriptException ise) {
} catch (ScriptException ise) {
displayError(ise);
}
}
......@@ -380,7 +389,7 @@ public class Console extends JFrame {
InputStream in = null;
Reader source = null;
classLoaderManager = FraSCAtiScript.getSingleton().getFrascatiClassLoaderManager();
classLoaderManager = ExplorerGUI.getSingleton().getClassLoaderManager();
if ( classLoaderManager != null ) {
cl = classLoaderManager.getClassLoader();
cmd = cmd.substring(6);
......@@ -390,19 +399,19 @@ public class Console extends JFrame {
Set<String> procs = null;
displayMessage("Loading procedures from "+ cmd);
procs = FraSCAtiScript.getSingleton().getLoader().load(source);
procs = (Set<String>) engine.eval(source);
for (String proc : procs)
displayMessage("+-> Adding procedure '"+ proc +"'");
} catch (InvalidScriptException e) {
} catch (ScriptException e) {
displayError(e);
}
} else
displayError("Cannot found the domain-config interface!");
} else try {
Object obj = FraSCAtiScript.getSingleton().execute(cmd);
Object obj = engine.eval(cmd);
if ( obj != null )
displayMessage( obj.toString() );
} catch (FScriptException e2) {
} catch (ScriptException e2) {
displayError(e2);
}
// outputScrollPane.s
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment