Permalink
Browse files

move ability to define a JRuby runtime global into static JRubyHelper…

… method

git-svn-id: http://svn.trampolinesystems.com/springy/trunk@9936 7bcaa5c2-c9d6-0310-8dd4-ca458a8cac41
  • Loading branch information...
trampoline committed Nov 20, 2007
1 parent fa1cc06 commit 2ccd481b67343a36cd47f52e6b278bdb0902821f
@@ -19,6 +19,7 @@
import org.springframework.core.io.Resource;
import org.w3c.dom.Document;
import springy.util.IOHelper;
+import springy.util.JRubyHelper;
import java.io.IOException;
import java.io.StringReader;
@@ -92,7 +93,7 @@ protected void loadBeanDefinitions(final DefaultListableBeanFactory beanFactory)
String springy = "load 'springy/context/springy_parse_prepare.rb'";
String ctxt = IOHelper.inputStreamToString(contextResource.getInputStream());
- addGlobal("bean_factory", beanFactory);
+ JRubyHelper.addGlobal(runtime, "bean_factory", beanFactory);
try {
runtime.evalScript(new StringReader(springy), "(springy-parse-prepare-fragment)");
@@ -146,18 +147,4 @@ private synchronized void serializeContext() {
serializedContextAsDocument = (Document) a.get(1);
}
}
-
- private void addGlobal(String name, final Object o) {
-
- runtime.getGlobalVariables().defineReadonly(GlobalVariable.variableName(name),
- new IAccessor() {
- public IRubyObject getValue() {
- return JavaEmbedUtils.javaToRuby( runtime, o );
- }
- public IRubyObject setValue(IRubyObject newValue) {
- return newValue;
- }
- });
-
- }
}
@@ -2,6 +2,11 @@
import org.apache.bsf.BSFException;
import org.jruby.exceptions.RaiseException;
+import org.jruby.Ruby;
+import org.jruby.javasupport.JavaEmbedUtils;
+import org.jruby.runtime.GlobalVariable;
+import org.jruby.runtime.IAccessor;
+import org.jruby.runtime.builtin.IRubyObject;
/**
* JRuby helper class.
@@ -26,4 +31,17 @@ public static Object getProperty( IRubyObject obj , String propertyName )
return javaResult;
}
*/
+ public static void addGlobal(final Ruby runtime, String name, final Object o) {
+
+ runtime.getGlobalVariables().defineReadonly(GlobalVariable.variableName(name),
+ new IAccessor() {
+ public IRubyObject getValue() {
+ return JavaEmbedUtils.javaToRuby( runtime, o );
+ }
+ public IRubyObject setValue(IRubyObject newValue) {
+ return newValue;
+ }
+ });
+
+ }
}

0 comments on commit 2ccd481

Please sign in to comment.