IDEMPIERE-2732 Make Callouts replaceable by Factory approach
This commit is contained in:
parent
bf9a6c91a5
commit
b96bfd7229
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.adempiere.base.DefaultCalloutFactory">
|
||||||
|
<implementation class="org.adempiere.base.DefaultCalloutFactory"/>
|
||||||
|
<service>
|
||||||
|
<provide interface="org.adempiere.base.ICalloutFactory"/>
|
||||||
|
</service>
|
||||||
|
</scr:component>
|
|
@ -31,6 +31,7 @@ import org.adempiere.model.ITaxProvider;
|
||||||
import org.adempiere.model.MShipperFacade;
|
import org.adempiere.model.MShipperFacade;
|
||||||
import org.compiere.impexp.BankStatementLoaderInterface;
|
import org.compiere.impexp.BankStatementLoaderInterface;
|
||||||
import org.compiere.impexp.BankStatementMatcherInterface;
|
import org.compiere.impexp.BankStatementMatcherInterface;
|
||||||
|
import org.compiere.model.Callout;
|
||||||
import org.compiere.model.MAddressValidation;
|
import org.compiere.model.MAddressValidation;
|
||||||
import org.compiere.model.MBankAccountProcessor;
|
import org.compiere.model.MBankAccountProcessor;
|
||||||
import org.compiere.model.MPaymentProcessor;
|
import org.compiere.model.MPaymentProcessor;
|
||||||
|
@ -94,8 +95,27 @@ public class Core {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IDEMPIERE-2732
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param className
|
||||||
|
* @return callout for className
|
||||||
|
*/
|
||||||
|
public static Callout getCallout(String className) {
|
||||||
|
List<ICalloutFactory> factories = Service.locator().list(ICalloutFactory.class).getServices();
|
||||||
|
if (factories != null) {
|
||||||
|
for(ICalloutFactory factory : factories) {
|
||||||
|
Callout callout = factory.getCallout(className);
|
||||||
|
if (callout != null) {
|
||||||
|
return callout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
* @param processId Java class name or equinox extension id
|
* @param processId Java class name or equinox extension id
|
||||||
* @return ProcessCall instance or null if processId not found
|
* @return ProcessCall instance or null if processId not found
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2015 Dirk Niemeyer *
|
||||||
|
* Copyright (C) 2015 action 42 GmbH *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.adempiere.base;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.adempiere.base.equinox.EquinoxExtensionLocator;
|
||||||
|
import org.compiere.model.Callout;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author a42niem
|
||||||
|
*
|
||||||
|
* This is just a blueprint for creation of a CalloutFactory
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DefaultCalloutFactory implements ICalloutFactory {
|
||||||
|
|
||||||
|
private final static CLogger log = CLogger.getCLogger(DefaultCalloutFactory.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* default constructor
|
||||||
|
*/
|
||||||
|
public DefaultCalloutFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.adempiere.base.ICalloutFactory#getCallout(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Callout getCallout(String className) {
|
||||||
|
Callout callout = null;
|
||||||
|
callout = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension();
|
||||||
|
if (callout == null) {
|
||||||
|
//Get Class
|
||||||
|
Class<?> calloutClass = null;
|
||||||
|
//use context classloader if available
|
||||||
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
if (classLoader != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
calloutClass = classLoader.loadClass(className);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
if (log.isLoggable(Level.FINE))log.log(Level.FINE, className, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (calloutClass == null)
|
||||||
|
{
|
||||||
|
classLoader = this.getClass().getClassLoader();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
calloutClass = classLoader.loadClass(className);
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException ex)
|
||||||
|
{
|
||||||
|
log.log(Level.WARNING, className, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calloutClass == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get callout
|
||||||
|
try
|
||||||
|
{
|
||||||
|
callout = (Callout)calloutClass.newInstance();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
log.log(Level.WARNING, "Instance for " + className, ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return callout;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2015 Dirk Niemeyer *
|
||||||
|
* Copyright (C) 2015 action 42 GmbH *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.adempiere.base;
|
||||||
|
|
||||||
|
import org.compiere.model.Callout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author a42niem
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ICalloutFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param className
|
||||||
|
* @return matching Callout
|
||||||
|
*/
|
||||||
|
public Callout getCallout(String className);
|
||||||
|
|
||||||
|
}
|
|
@ -2910,10 +2910,12 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
if (methodStart != -1) // no class
|
if (methodStart != -1) // no class
|
||||||
{
|
{
|
||||||
String className = cmd.substring(0,methodStart);
|
String className = cmd.substring(0,methodStart);
|
||||||
//first, check matching extension id in extension registry
|
// IDEMPIERE-2732
|
||||||
call = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension();
|
// get corresponding callout
|
||||||
|
call = Core.getCallout(className);
|
||||||
|
// end IDEMPIERE-2732
|
||||||
if (call == null) {
|
if (call == null) {
|
||||||
//no match from extension registry, 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();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue