NF9 OSGi New Document Factory
From iDempiere en
Feature: OSGi New Document Factory
Goal: Development
Description: Implement a new document factory base class (MappedDocumentFactory class and IMappedDocumentFactory interface).
Usage:
With following Doc class:
public class MyDocInOut extends Doc_InOut { public MyDocInOut(MAcctSchema as, ResultSet rs, String trxName) { super(as, rs, trxName); } }
Developer can use one of the following approach:
1. At plugin Activator start method, register the document class.
public void start(BundleContext context) throws Exception { IMappedDocumentFactory factory = Core.getMappedDocumentFactory(); factory.addMapping(null, MInOut.Table_Name, (p) -> new MyDocInOut(p.as, p.rs, p.trxName)); //need to reset cache if you are replacing doc classes from core CacheMgt.get().reset(DocManager.IDOC_FACTORY_CACHE_TABLE_NAME); }
2. Create an osgi component, at the bind method for the IMappedDocumentFactory service.
public void bindService(IMappedDocumentFactory factory) { factory.addMapping(null, MInOut.Table_Name, (p) -> new MyDocInOut(p.as, p.rs, p.trxName)); //need to reset cache if you are replacing doc classes from core CacheMgt.get().reset(DocManager.IDOC_FACTORY_CACHE_TABLE_NAME); }
3. Create a subclass of MappedDocumentFactory, register as IDocFactory service (DO NOT register as IMappedDocumentFactory service).
public class MyDocFactory extends MappedDocumentFactory { public MyDocFactory() { addMapping(null, MInOut.Table_Name, (p) -> new MyDocInOut(p.as, p.rs, p.trxName)); //need to reset cache if you are replacing doc classes from core CacheMgt.get().reset(DocManager.IDOC_FACTORY_CACHE_TABLE_NAME); } }
Technical Info: IDEMPIERE-4695