Permalink
Browse files

Added a binding for , the logical node context for the plugin.

  • Loading branch information...
1 parent cdc7191 commit 0dea72c46a7b8a1eb998c5f3597844759bd78291 @howech howech committed Mar 1, 2011
@@ -15,6 +15,8 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
/**
* Simple class that sets up a jruby based decorator.
@@ -35,15 +37,16 @@ public static SinkDecoBuilder builder() {
public EventSinkDecorator<EventSink> build(Context context,
String... argv) {
- EventSinkDecorator d = null;
+ EventSinkDecorator<EventSink> d = null;
Preconditions.checkArgument(argv.length >= 1,
"usage: jRubyDecorator script.rb [optional script arguments]");
ScriptEngine jruby = new ScriptEngineManager().getEngineByName("ruby");
jruby.put(ScriptEngine.ARGV, java.util.Arrays.copyOfRange(argv, 1, argv.length));
-
+ Bindings bindings = new SimpleBindings();
+ bindings.put("context", context);
try {
- d = (EventSinkDecorator) jruby.eval(new BufferedReader(new FileReader(argv[0])));
+ d = (EventSinkDecorator<EventSink>) jruby.eval(new BufferedReader(new FileReader(argv[0])),bindings);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Script file not found: " + argv[0], e);
} catch (ScriptException e) {
@@ -15,9 +15,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
+import javax.script.SimpleBindings;
/**
* Simple source that creates a ruby class determinded by a script.
@@ -39,9 +41,10 @@ public EventSink build(Context cntxt, String... argv) {
ScriptEngine jruby = new ScriptEngineManager().getEngineByName("ruby");
jruby.put(ScriptEngine.ARGV, Arrays.copyOfRange(argv, 1, argv.length));
-
+ Bindings bindings = new SimpleBindings();
+ bindings.put("context", cntxt);
try {
- s = (EventSink) jruby.eval(new BufferedReader(new FileReader(argv[0])));
+ s = (EventSink) jruby.eval(new BufferedReader(new FileReader(argv[0])),bindings);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Script file not found: " + argv[0], e);
} catch (ScriptException e) {
@@ -15,9 +15,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
+import javax.script.SimpleBindings;
/**
* Simple source that creates a ruby class determinded by a script.
@@ -38,9 +40,10 @@ public EventSource build(Context ctx,String... argv) {
ScriptEngine jruby = new ScriptEngineManager().getEngineByName("ruby");
jruby.put(ScriptEngine.ARGV, Arrays.copyOfRange(argv, 1, argv.length));
-
+ Bindings bindings = new SimpleBindings();
+ bindings.put("context", ctx);
try {
- s = (EventSource) jruby.eval(new BufferedReader(new FileReader(argv[0])));
+ s = (EventSource) jruby.eval(new BufferedReader(new FileReader(argv[0])),bindings);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Script file not found: " + argv[0], e);
} catch (ScriptException e) {
@@ -49,6 +52,8 @@ public EventSource build(Context ctx,String... argv) {
return s;
}
+
+ @Override
public EventSource build(String... strings) {
return build(null,strings);
}

0 comments on commit 0dea72c

Please sign in to comment.