IDEMPIERE-2732 Make Callouts replaceable by Factory approach

refined to check on requested method in class provided by factory
This commit is contained in:
Dirk Niemeyer 2015-08-28 17:19:58 +02:00
parent 2eb0e245ac
commit 234b5786a4
4 changed files with 19 additions and 7 deletions

View File

@ -99,13 +99,14 @@ public class Core {
/**
*
* @param className
* @param method
* @return callout for className
*/
public static Callout getCallout(String className) {
public static Callout getCallout(String className, String methodName) {
List<ICalloutFactory> factories = Service.locator().list(ICalloutFactory.class).getServices();
if (factories != null) {
for(ICalloutFactory factory : factories) {
Callout callout = factory.getCallout(className);
Callout callout = factory.getCallout(className, methodName);
if (callout != null) {
return callout;
}

View File

@ -13,6 +13,7 @@
*****************************************************************************/
package org.adempiere.base;
import java.lang.reflect.Method;
import java.util.logging.Level;
import org.adempiere.base.equinox.EquinoxExtensionLocator;
@ -39,7 +40,7 @@ public class DefaultCalloutFactory implements ICalloutFactory {
* @see org.adempiere.base.ICalloutFactory#getCallout(java.lang.String)
*/
@Override
public Callout getCallout(String className) {
public Callout getCallout(String className, String methodName) {
Callout callout = null;
callout = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension();
if (callout == null) {
@ -86,8 +87,17 @@ public class DefaultCalloutFactory implements ICalloutFactory {
log.log(Level.WARNING, "Instance for " + className, ex);
return null;
}
//Check if callout method does really exist
Method[] methods = calloutClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(methodName)) {
return callout;
}
}
}
return callout;
log.log(Level.FINE, "Required method " + methodName + " not found in class " + className);
return null;
}
}

View File

@ -25,8 +25,9 @@ public interface ICalloutFactory {
/**
*
* @param className
* @param methodName
* @return matching Callout
*/
public Callout getCallout(String className);
public Callout getCallout(String className, String methodName);
}

View File

@ -2910,15 +2910,15 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
{
String className = cmd.substring(0,methodStart);
// IDEMPIERE-2732
method = cmd.substring(methodStart+1);
// get corresponding callout
call = Core.getCallout(className);
call = Core.getCallout(className, method);
// end IDEMPIERE-2732
if (call == null) {
//no match from factory, check java classpath
Class<?> cClass = Class.forName(className);
call = (Callout)cClass.newInstance();
}
method = cmd.substring(methodStart+1);
}
}
catch (Exception e)