IDEMPIERE-359 Add OSGi Service support for existing extension point. Added process factory interface.

This commit is contained in:
Heng Sin Low 2012-11-21 16:54:18 +08:00
parent f0cac5bd82
commit fb883fd47c
6 changed files with 155 additions and 59 deletions

View File

@ -24,6 +24,7 @@ import java.net.URL;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.MBankAccountProcessor;
import org.compiere.model.MPaymentProcessor; import org.compiere.model.MPaymentProcessor;
import org.compiere.model.ModelValidator; import org.compiere.model.ModelValidator;
import org.compiere.model.PaymentInterface; import org.compiere.model.PaymentInterface;
@ -80,6 +81,15 @@ public class Core {
* @return ProcessCall instance or null if serviceId not found * @return ProcessCall instance or null if serviceId not found
*/ */
public static ProcessCall getProcess(String serviceId) { public static ProcessCall getProcess(String serviceId) {
ProcessCall process = null;
List<IProcessFactory> 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(); return Service.locator().locate(ProcessCall.class, "org.adempiere.base.Process", serviceId, null).getService();
} }
@ -94,17 +104,18 @@ public class Core {
/** /**
* Get payment processor instance * Get payment processor instance
* @param mpp payment processor model * @param mbap payment processor model
* @param mp payment model * @param mp payment model
* @return initialized PaymentProcessor or null * @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)) 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(); String className = mpp.getPayProcessorClass();
if (className == null || className.length() == 0) { 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; return null;
} }
// //
@ -130,7 +141,7 @@ public class Core {
} }
// Initialize // Initialize
myProcessor.initialize(mpp, mp); myProcessor.initialize(mbap, mp);
// //
return myProcessor; return myProcessor;
} }

View File

@ -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);
}

View File

@ -57,4 +57,4 @@ Bundle-Activator: org.adempiere.webui.WebUIActivator
Eclipse-ExtensibleAPI: true Eclipse-ExtensibleAPI: true
Eclipse-RegisterBuddy: org.zkoss.zk.library Eclipse-RegisterBuddy: org.zkoss.zk.library
Web-ContextPath: webui 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

View File

@ -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.ui.zk.process.factory">
<implementation class="org.adempiere.webui.util.ProcessFactoryImpl"/>
<service>
<provide interface="org.adempiere.base.IProcessFactory"/>
</service>
</scr:component>

View File

@ -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;
}
}

View File

@ -28,7 +28,8 @@ bin.includes = META-INF/,\
OSGI-INF/defaulteditorfactory.xml,\ OSGI-INF/defaulteditorfactory.xml,\
OSGI-INF/jrviewerprovider.xml,\ OSGI-INF/jrviewerprovider.xml,\
OSGI-INF/resourcefinder.xml,\ OSGI-INF/resourcefinder.xml,\
OSGI-INF/defaultpaymentformfactory.xml OSGI-INF/defaultpaymentformfactory.xml,\
OSGI-INF/processfactory.xml
src.includes = WEB-INF/classes/,\ src.includes = WEB-INF/classes/,\
WEB-INF/tld/,\ WEB-INF/tld/,\
WEB-INF/web.xml,\ WEB-INF/web.xml,\