NF9 OSGi New Mapped By Name Factory

From iDempiere en

Feature: OSGi New Mapped By Name Factory

Goal: Development

Developer: Hengsin (talk)

Description: iDempiere have many OSGi factory that create the requested instance by class name or a string key (IProcessFactory, IModelValidatorFactory, IPaymentProcessorFactory, etc). This ticket add generic typed, lambda function based interface and class that help to simplify the development of such factory class.

New interface and class:
1. org.adempiere.base.IMappedByNameFactory<T> interface
2. org.adempiere.base.MappedByNameFactory<T> class (implements IMappedByNameFactory<T>)

Usage:
To add new implementation of BankStatementMatcherInterface.
1. Create class that implement the BankStatementMatcherInterface interface

public class MyBankStatementMatcher implements BankStatementMatcherInterface {
	@Override
	public BankStatementMatchInfo findMatch(MBankStatementLine bsl) {
	    return null;
	}

	@Override
	public BankStatementMatchInfo findMatch(X_I_BankStatement ibs) {
	    return null;
	}
}

2. Create factory class that implement the IBankStatementMatcherFactory interface.

public class MyBankStatementMatcherFactory extends MappedByNameFactory<BankStatementMatcherInterface> implements IBankStatementMatcherFactory {
	public MyBankStatementMatcherFactory() {
           //add mapping from name/key to create new instance lambda expression
           addMapping(MyBankStatementMatcher.class.getName(), () -> new MyBankStatementMatcher());
	}

	@Override
	public BankStatementMatcherInterface newBankStatementMatcherInstance(String className)     {
           //use the newInstance default method at IMappedByNameFactory interface
           return newInstance(className);
	}		
}

Technical Info: IDEMPIERE-4704

Cookies help us deliver our services. By using our services, you agree to our use of cookies.