From fb883fd47c8e7572680c8bc7ca8ced88599e3caf Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 21 Nov 2012 16:54:18 +0800 Subject: [PATCH] IDEMPIERE-359 Add OSGi Service support for existing extension point. Added process factory interface. --- .../src/org/adempiere/base/Core.java | 23 +++- .../org/adempiere/base/IProcessFactory.java | 32 ++++++ org.adempiere.ui.zk/META-INF/MANIFEST.MF | 2 +- .../OSGI-INF/processfactory.xml | 7 ++ .../webui/util/ProcessFactoryImpl.java | 45 ++++++++ org.adempiere.ui.zk/build.properties | 105 +++++++++--------- 6 files changed, 155 insertions(+), 59 deletions(-) create mode 100644 org.adempiere.base/src/org/adempiere/base/IProcessFactory.java create mode 100644 org.adempiere.ui.zk/OSGI-INF/processfactory.xml create mode 100644 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ProcessFactoryImpl.java diff --git a/org.adempiere.base/src/org/adempiere/base/Core.java b/org.adempiere.base/src/org/adempiere/base/Core.java index b40e2c3a3f..306c17980a 100644 --- a/org.adempiere.base/src/org/adempiere/base/Core.java +++ b/org.adempiere.base/src/org/adempiere/base/Core.java @@ -24,6 +24,7 @@ import java.net.URL; import java.util.List; import java.util.logging.Level; +import org.compiere.model.MBankAccountProcessor; import org.compiere.model.MPaymentProcessor; import org.compiere.model.ModelValidator; import org.compiere.model.PaymentInterface; @@ -80,7 +81,16 @@ public class Core { * @return ProcessCall instance or null if serviceId not found */ public static ProcessCall getProcess(String serviceId) { - return Service.locator().locate(ProcessCall.class, "org.adempiere.base.Process", serviceId, null).getService(); + ProcessCall process = null; + List factories = Service.locator().list(IProcessFactory.class).getServices(); + if (factories != null && !factories.isEmpty()) { + for(IProcessFactory factory : factories) { + process = factory.newProcessInstance(serviceId); + if (process != null) + return process; + } + } + return Service.locator().locate(ProcessCall.class, "org.adempiere.base.Process", serviceId, null).getService(); } /** @@ -94,17 +104,18 @@ public class Core { /** * Get payment processor instance - * @param mpp payment processor model + * @param mbap payment processor model * @param mp payment model * @return initialized PaymentProcessor or null */ - public static PaymentProcessor getPaymentProcessor(MPaymentProcessor mpp, PaymentInterface mp) { + public static PaymentProcessor getPaymentProcessor(MBankAccountProcessor mbap, PaymentInterface mp) { if (s_log.isLoggable(Level.FINE)) - s_log.fine("create for " + mpp); + s_log.fine("create for " + mbap); + MPaymentProcessor mpp = new MPaymentProcessor(mbap.getCtx(), mbap.getC_PaymentProcessor_ID(), mbap.get_TrxName()); String className = mpp.getPayProcessorClass(); if (className == null || className.length() == 0) { - s_log.log(Level.SEVERE, "No PaymentProcessor class name in " + mpp); + s_log.log(Level.SEVERE, "No PaymentProcessor class name in " + mbap); return null; } // @@ -130,7 +141,7 @@ public class Core { } // Initialize - myProcessor.initialize(mpp, mp); + myProcessor.initialize(mbap, mp); // return myProcessor; } diff --git a/org.adempiere.base/src/org/adempiere/base/IProcessFactory.java b/org.adempiere.base/src/org/adempiere/base/IProcessFactory.java new file mode 100644 index 0000000000..3f71656a96 --- /dev/null +++ b/org.adempiere.base/src/org/adempiere/base/IProcessFactory.java @@ -0,0 +1,32 @@ +/****************************************************************************** + * Copyright (C) 2012 Heng Sin Low * + * Copyright (C) 2012 Trek Global * + * 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.process.ProcessCall; + +/** + * + * @author hengsin + * + */ +public interface IProcessFactory { + + /** + * Create new process instance + * @param className + * @return new process instance + */ + public ProcessCall newProcessInstance(String className); + +} diff --git a/org.adempiere.ui.zk/META-INF/MANIFEST.MF b/org.adempiere.ui.zk/META-INF/MANIFEST.MF index c1aa808ed8..45c5b862bb 100644 --- a/org.adempiere.ui.zk/META-INF/MANIFEST.MF +++ b/org.adempiere.ui.zk/META-INF/MANIFEST.MF @@ -57,4 +57,4 @@ Bundle-Activator: org.adempiere.webui.WebUIActivator Eclipse-ExtensibleAPI: true Eclipse-RegisterBuddy: org.zkoss.zk.library Web-ContextPath: webui -Service-Component: OSGI-INF/reportviewerprovider.xml, OSGI-INF/defaultinfofactory.xml, OSGI-INF/defaulteditorfactory.xml, OSGI-INF/jrviewerprovider.xml, OSGI-INF/resourcefinder.xml, OSGI-INF/defaultpaymentformfactory.xml +Service-Component: OSGI-INF/reportviewerprovider.xml, OSGI-INF/defaultinfofactory.xml, OSGI-INF/defaulteditorfactory.xml, OSGI-INF/jrviewerprovider.xml, OSGI-INF/resourcefinder.xml, OSGI-INF/defaultpaymentformfactory.xml, OSGI-INF/processfactory.xml diff --git a/org.adempiere.ui.zk/OSGI-INF/processfactory.xml b/org.adempiere.ui.zk/OSGI-INF/processfactory.xml new file mode 100644 index 0000000000..04cbf3c7da --- /dev/null +++ b/org.adempiere.ui.zk/OSGI-INF/processfactory.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ProcessFactoryImpl.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ProcessFactoryImpl.java new file mode 100644 index 0000000000..9a553df352 --- /dev/null +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ProcessFactoryImpl.java @@ -0,0 +1,45 @@ +/****************************************************************************** + * Copyright (C) 2012 Heng Sin Low * + * Copyright (C) 2012 Trek Global * + * 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.webui.util; + +import org.adempiere.base.IProcessFactory; +import org.compiere.process.ProcessCall; + +/** + * @author hengsin + * + */ +public class ProcessFactoryImpl implements IProcessFactory { + + /** + * default constructor + */ + public ProcessFactoryImpl() { + } + + /* (non-Javadoc) + * @see org.adempiere.base.IProcessFactory#newProcessInstance(java.lang.String) + */ + @Override + public ProcessCall newProcessInstance(String className) { + ProcessCall process = null; + try { + Class clazz = getClass().getClassLoader().loadClass(className); + process = (ProcessCall) clazz.newInstance(); + } catch (Exception e) { + } + return process; + } + +} diff --git a/org.adempiere.ui.zk/build.properties b/org.adempiere.ui.zk/build.properties index 1359ade0ba..3ac783b6fc 100644 --- a/org.adempiere.ui.zk/build.properties +++ b/org.adempiere.ui.zk/build.properties @@ -1,52 +1,53 @@ -output.. = WEB-INF/classes/ -bin.includes = META-INF/,\ - WEB-INF/,\ - css/,\ - images/,\ - index.zul,\ - js/,\ - theme/,\ - theme.zs,\ - zul/,\ - timeout.zul,\ - plugin.xml,\ - WEB-INF/classes/,\ - WEB-INF/lib/atmosphere-runtime-0.9.jar,\ - WEB-INF/lib/atmosphere-compat-jbossweb-0.9.jar,\ - WEB-INF/lib/atmosphere-compat-tomcat-0.9.jar,\ - WEB-INF/lib/atmosphere-compat-tomcat7-0.9.jar,\ - metainfo/,\ - WEB-INF/lib/calendar.jar,\ - calendar.css,\ - calendar.zul,\ - calendar_mini.zul,\ - divarrow.zul,\ - divtab.zul,\ - OSGI-INF/,\ - OSGI-INF/reportviewerprovider.xml,\ - OSGI-INF/defaultinfofactory.xml,\ - OSGI-INF/defaulteditorfactory.xml,\ - OSGI-INF/jrviewerprovider.xml,\ - OSGI-INF/resourcefinder.xml,\ - OSGI-INF/defaultpaymentformfactory.xml -src.includes = WEB-INF/classes/,\ - WEB-INF/tld/,\ - WEB-INF/web.xml,\ - WEB-INF/xsd/,\ - WEB-INF/zk.xml,\ - css/,\ - images/,\ - index.zul,\ - js/,\ - theme/,\ - theme.zs,\ - zul/,\ - metainfo/,\ - calendar.css,\ - calendar.zul,\ - calendar_mini.zul,\ - divarrow.zul,\ - divtab.zul -source.. = WEB-INF/src/ -bin.excludes = WEB-INF/src/,\ - WEB-INF/web-2.5.xml +output.. = WEB-INF/classes/ +bin.includes = META-INF/,\ + WEB-INF/,\ + css/,\ + images/,\ + index.zul,\ + js/,\ + theme/,\ + theme.zs,\ + zul/,\ + timeout.zul,\ + plugin.xml,\ + WEB-INF/classes/,\ + WEB-INF/lib/atmosphere-runtime-0.9.jar,\ + WEB-INF/lib/atmosphere-compat-jbossweb-0.9.jar,\ + WEB-INF/lib/atmosphere-compat-tomcat-0.9.jar,\ + WEB-INF/lib/atmosphere-compat-tomcat7-0.9.jar,\ + metainfo/,\ + WEB-INF/lib/calendar.jar,\ + calendar.css,\ + calendar.zul,\ + calendar_mini.zul,\ + divarrow.zul,\ + divtab.zul,\ + OSGI-INF/,\ + OSGI-INF/reportviewerprovider.xml,\ + OSGI-INF/defaultinfofactory.xml,\ + OSGI-INF/defaulteditorfactory.xml,\ + OSGI-INF/jrviewerprovider.xml,\ + OSGI-INF/resourcefinder.xml,\ + OSGI-INF/defaultpaymentformfactory.xml,\ + OSGI-INF/processfactory.xml +src.includes = WEB-INF/classes/,\ + WEB-INF/tld/,\ + WEB-INF/web.xml,\ + WEB-INF/xsd/,\ + WEB-INF/zk.xml,\ + css/,\ + images/,\ + index.zul,\ + js/,\ + theme/,\ + theme.zs,\ + zul/,\ + metainfo/,\ + calendar.css,\ + calendar.zul,\ + calendar_mini.zul,\ + divarrow.zul,\ + divtab.zul +source.. = WEB-INF/src/ +bin.excludes = WEB-INF/src/,\ + WEB-INF/web-2.5.xml