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