From: Juergen H. <jho...@us...> - 2007-06-11 22:22:40
|
Update of /cvsroot/springframework/spring/src/org/springframework/scripting/jruby In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv846/src/org/springframework/scripting/jruby Modified Files: Tag: mbranch-2-0 JRubyScriptUtils.java Log Message: updated for JRuby 1.0 compatibility Index: JRubyScriptUtils.java =================================================================== RCS file: /cvsroot/springframework/spring/src/org/springframework/scripting/jruby/JRubyScriptUtils.java,v retrieving revision 1.16 retrieving revision 1.16.2.1 diff -C2 -d -r1.16 -r1.16.2.1 *** JRubyScriptUtils.java 14 Mar 2007 12:52:13 -0000 1.16 --- JRubyScriptUtils.java 11 Jun 2007 22:22:36 -0000 1.16.2.1 *************** *** 35,38 **** --- 35,39 ---- import org.jruby.exceptions.RaiseException; import org.jruby.javasupport.JavaEmbedUtils; + import org.jruby.runtime.DynamicScope; import org.jruby.runtime.builtin.IRubyObject; *************** *** 40,48 **** import org.springframework.core.NestedRuntimeException; import org.springframework.util.ClassUtils; /** * Utility methods for handling JRuby-scripted objects. * ! * <p>Note: As of Spring 2.0.4, this class requires JRuby 0.9.8 or higher. * * @author Rob Harrop --- 41,53 ---- import org.springframework.core.NestedRuntimeException; import org.springframework.util.ClassUtils; + import org.springframework.util.ObjectUtils; + import org.springframework.util.ReflectionUtils; + import org.springframework.util.StringUtils; /** * Utility methods for handling JRuby-scripted objects. * ! * <p>Note: As of Spring 2.0.4, this class requires JRuby 0.9.8 or 0.9.9. ! * As of Spring 2.0.6, it supports JRuby 1.0 as well. * * @author Rob Harrop *************** *** 53,56 **** --- 58,66 ---- public abstract class JRubyScriptUtils { + // Determine whether the new JRuby 1.0 parse method is available (incompatible with 0.9) + private final static Method newParseMethod = ClassUtils.getMethodIfAvailable( + Ruby.class, "parse", new Class[] {String.class, String.class, DynamicScope.class, int.class}); + + /** * Create a new JRuby-scripted object from the given script source, *************** *** 77,81 **** Ruby ruby = initializeRuntime(); ! Node scriptRootNode = ruby.parse(scriptSource, "", null); IRubyObject rubyObject = ruby.eval(scriptRootNode); --- 87,93 ---- Ruby ruby = initializeRuntime(); ! Node scriptRootNode = (newParseMethod != null ? ! (Node) ReflectionUtils.invokeMethod(newParseMethod, ruby, new Object[] {scriptSource, "", null, new Integer(0)}) ! : ruby.parse(scriptSource, "", null)); IRubyObject rubyObject = ruby.eval(scriptRootNode); *************** *** 168,172 **** } if (AopUtils.isToStringMethod(method)) { ! return "JRuby object [" + this.rubyObject + "]"; } try { --- 180,188 ---- } if (AopUtils.isToStringMethod(method)) { ! String toStringResult = this.rubyObject.toString(); ! if (!StringUtils.hasText(toStringResult)) { ! toStringResult = ObjectUtils.identityToString(this.rubyObject); ! } ! return "JRuby object [" + toStringResult + "]"; } try { |