svn commit: r819281 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r819281 - /ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java

jleroux@apache.org
Author: jleroux
Date: Sun Sep 27 10:35:21 2009
New Revision: 819281

URL: http://svn.apache.org/viewvc?rev=819281&view=rev
Log:
A new feature from Shi Yusen (https://issues.apache.org/jira/browse/OFBIZ-2948) - OFBIZ-2948
This change will make it possible to invoke both static method and instance method. See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html#invoke(java.lang.Object,%20java.lang.Object...)
Thanks to Scott for optimisation advice

Modified:
    ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java?rev=819281&r1=819280&r2=819281&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/StandardJavaEngine.java Sun Sep 27 10:35:21 2009
@@ -20,6 +20,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.Map;
 
 import org.ofbiz.service.DispatchContext;
@@ -95,7 +96,11 @@
         try {
             Class<?> c = cl.loadClass(this.getLocation(modelService));
             Method m = c.getMethod(modelService.invoke, DispatchContext.class, Map.class);
-            result = m.invoke(null, dctx, context);
+            if (Modifier.isStatic(m.getModifiers())) {
+                result = m.invoke(null, dctx, context);
+            } else {
+                result = m.invoke(c.newInstance(), dctx, context);
+            }            
         } catch (ClassNotFoundException cnfe) {
             throw new GenericServiceException("Cannot find service [" + modelService.name + "] location class", cnfe);
         } catch (NoSuchMethodException nsme) {