diff --git a/org.adempiere.base/OSGI-INF/defaultcalloutfactory.xml b/org.adempiere.base/OSGI-INF/defaultcalloutfactory.xml new file mode 100644 index 0000000000..8376223cb8 --- /dev/null +++ b/org.adempiere.base/OSGI-INF/defaultcalloutfactory.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.adempiere.base/src/org/adempiere/base/Core.java b/org.adempiere.base/src/org/adempiere/base/Core.java index facf9c45b8..20e1a156f5 100644 --- a/org.adempiere.base/src/org/adempiere/base/Core.java +++ b/org.adempiere.base/src/org/adempiere/base/Core.java @@ -31,6 +31,7 @@ import org.adempiere.model.ITaxProvider; import org.adempiere.model.MShipperFacade; import org.compiere.impexp.BankStatementLoaderInterface; import org.compiere.impexp.BankStatementMatcherInterface; +import org.compiere.model.Callout; import org.compiere.model.MAddressValidation; import org.compiere.model.MBankAccountProcessor; import org.compiere.model.MPaymentProcessor; @@ -94,8 +95,27 @@ public class Core { return list; } + // IDEMPIERE-2732 /** * + * @param className + * @return callout for className + */ + public static Callout getCallout(String className) { + List 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 * @return ProcessCall instance or null if processId not found */ diff --git a/org.adempiere.base/src/org/adempiere/base/DefaultCalloutFactory.java b/org.adempiere.base/src/org/adempiere/base/DefaultCalloutFactory.java new file mode 100644 index 0000000000..8665ad8e0b --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/DefaultCalloutFactory.java @@ -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; + } + +} diff --git a/org.adempiere.base/src/org/adempiere/base/ICalloutFactory.java b/org.adempiere.base/src/org/adempiere/base/ICalloutFactory.java new file mode 100644 index 0000000000..f768632840 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/ICalloutFactory.java @@ -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); + +} diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index 204f8b2970..76781e59ea 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -2910,10 +2910,12 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable if (methodStart != -1) // no class { String className = cmd.substring(0,methodStart); - //first, check matching extension id in extension registry - call = EquinoxExtensionLocator.instance().locate(Callout.class, Callout.class.getName(), className, (ServiceQuery)null).getExtension(); + // IDEMPIERE-2732 + // get corresponding callout + call = Core.getCallout(className); + // end IDEMPIERE-2732 if (call == null) { - //no match from extension registry, check java classpath + //no match from factory, check java classpath Class cClass = Class.forName(className); call = (Callout)cClass.newInstance(); }