IDEMPIERE-2732 Make Callouts replaceable by Factory approach
refined to check on requested method in class provided by factory
This commit is contained in:
parent
2eb0e245ac
commit
234b5786a4
|
@ -99,13 +99,14 @@ public class Core {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param className
|
* @param className
|
||||||
|
* @param method
|
||||||
* @return callout for className
|
* @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();
|
List<ICalloutFactory> factories = Service.locator().list(ICalloutFactory.class).getServices();
|
||||||
if (factories != null) {
|
if (factories != null) {
|
||||||
for(ICalloutFactory factory : factories) {
|
for(ICalloutFactory factory : factories) {
|
||||||
Callout callout = factory.getCallout(className);
|
Callout callout = factory.getCallout(className, methodName);
|
||||||
if (callout != null) {
|
if (callout != null) {
|
||||||
return callout;
|
return callout;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.adempiere.base;
|
package org.adempiere.base;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.base.equinox.EquinoxExtensionLocator;
|
import org.adempiere.base.equinox.EquinoxExtensionLocator;
|
||||||
|
@ -39,7 +40,7 @@ public class DefaultCalloutFactory implements ICalloutFactory {
|
||||||
* @see org.adempiere.base.ICalloutFactory#getCallout(java.lang.String)
|
* @see org.adempiere.base.ICalloutFactory#getCallout(java.lang.String)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Callout getCallout(String className) {
|
public Callout getCallout(String className, String methodName) {
|
||||||
Callout callout = null;
|
Callout callout = null;
|
||||||
callout = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension();
|
callout = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension();
|
||||||
if (callout == null) {
|
if (callout == null) {
|
||||||
|
@ -86,8 +87,17 @@ public class DefaultCalloutFactory implements ICalloutFactory {
|
||||||
log.log(Level.WARNING, "Instance for " + className, ex);
|
log.log(Level.WARNING, "Instance for " + className, ex);
|
||||||
return null;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,9 @@ public interface ICalloutFactory {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param className
|
* @param className
|
||||||
|
* @param methodName
|
||||||
* @return matching Callout
|
* @return matching Callout
|
||||||
*/
|
*/
|
||||||
public Callout getCallout(String className);
|
public Callout getCallout(String className, String methodName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2910,15 +2910,15 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
{
|
{
|
||||||
String className = cmd.substring(0,methodStart);
|
String className = cmd.substring(0,methodStart);
|
||||||
// IDEMPIERE-2732
|
// IDEMPIERE-2732
|
||||||
|
method = cmd.substring(methodStart+1);
|
||||||
// get corresponding callout
|
// get corresponding callout
|
||||||
call = Core.getCallout(className);
|
call = Core.getCallout(className, method);
|
||||||
// end IDEMPIERE-2732
|
// end IDEMPIERE-2732
|
||||||
if (call == null) {
|
if (call == null) {
|
||||||
//no match from factory, check java classpath
|
//no match from factory, check java classpath
|
||||||
Class<?> cClass = Class.forName(className);
|
Class<?> cClass = Class.forName(className);
|
||||||
call = (Callout)cClass.newInstance();
|
call = (Callout)cClass.newInstance();
|
||||||
}
|
}
|
||||||
method = cmd.substring(methodStart+1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
Loading…
Reference in New Issue