Equinox Integration 2/Tutorial Extension Point

From ADempiere
Revision as of 06:27, 31 January 2010 by Viola (Talk) (Replace core code by call to service)

Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.

If you want to extract some functionality out of the core and provide a new extension point so that plug-ins can provide an extension, read on.

Example: Let plugins implement how invoices are posted to FACCT.

Replace core code by call to service

  • Navigate to Doc_Invoice.createFaccts()
  • Insert the line IInvoicePoster invoicePoster = Service.locate().getInvoicePoster(). Eclipse will highlight some errors, we will repeatedly use Code assist (Ctrl-1) to proceed.
  • Position the cursor on IInvoicePoster, create new interface using code assist.
    • Create the interface in the package org.adempiere.base
    • In this package, all core interfaces should resist.
    • Create the (empty) interface and save.
  • Back to Doc_Invoice, position the cursor on getInvoicePoster(), create new method using code assist.
    • The new method is inserted in the interface IServiceLocator. Save it.
  • Back to Doc_Invoice, insert the line invoicePoster.post()
  • create new method post() using code assist.
    • The method is inserted into the new interface IInvoicePoster
  • Notice there is now a compile error in EquinoxServiceLocator. This is the equinox implementation of IServiceLocator. It now lacks the implementation of getInvoicePoster().
    • We want to invoke an extension. So we look for extensions by an extension point id, say org.adempiere.base.InvoicePoster.
    • This is done by the ExtensionList (Beware! If more than one plugin will be installed providing extensions to InvoicePoster, only one will be executed this way. You can nevertheless iterate over all extension using ExtensionList, if you want.):
	public Callout getInvoicePoster() {
		ExtensionList<IInvoicePoster> list = 
                   new ExtensionList<IInvoicePoster>(IInvoicePoster.class, "org.adempiere.base.InvoicePoster");
		return list.first();
	}

Locate and define extension point

Write the plugin