Package org.openbravo.base.provider
Class OBProvider
- java.lang.Object
-
- org.openbravo.base.provider.OBProvider
-
public class OBProvider extends Object
The OBProvider provides the runtime instances of model entities as well as service instances. Classes are registered by their class type and it is identified if the class should be considered to be a singleton or not.The OBProvider is an implementation of the servicelocator pattern discussed in Martin Fowler's article here: http://martinfowler.com/articles/injection.html
- Author:
- mtaal
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_FILE_NAME
-
Constructor Summary
Constructors Constructor Description OBProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(Class<T> clz)
Checks the registry for which class should be used for the passed clz.Object
get(String name)
Returns an instance of the requested service.static OBProvider
getInstance()
boolean
isRegistered(Class<?> clz)
Returns true if the clz is registered.boolean
isRegistered(String name)
Checks if a service is registered under the name passed as a parameter.void
register(Class<?> registrationClass, Class<?> instanceClass, boolean overwrite)
Register an instance for an internal Openbravo class (the registrationClass).protected void
register(String prefix, InputStream is)
void
register(String name, Class<?> instanceClass, boolean overwrite)
Register an instance for an internal Openbravo class or service (the name).protected void
register(String prefix, String configFile)
void
registerInstance(Class<?> registrationClass, Object instanceObj, boolean overwrite)
Register an actual instance for an internal Openbravo class (the registrationClass).void
removeInstance(Class<?> clz)
Removes the singleton instance of the clz (if any) from the internal registry.static void
setInstance(OBProvider instance)
-
-
-
Field Detail
-
CONFIG_FILE_NAME
public static final String CONFIG_FILE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static OBProvider getInstance()
-
setInstance
public static void setInstance(OBProvider instance)
-
isRegistered
public boolean isRegistered(Class<?> clz)
Returns true if the clz is registered.- Parameters:
clz
- the name of this class is used to check if it is already registered- Returns:
- true if the clz is registered
-
isRegistered
public boolean isRegistered(String name)
Checks if a service is registered under the name passed as a parameter.- Parameters:
name
- is used to search the registry- Returns:
- true if a registration exists
-
register
protected void register(String prefix, InputStream is)
-
registerInstance
public void registerInstance(Class<?> registrationClass, Object instanceObj, boolean overwrite)
Register an actual instance for an internal Openbravo class (the registrationClass).- Parameters:
registrationClass
- the original Openbravo classinstanceObj
- the instance to use when the class is requested.overwrite
- true overwrite a current registration, false a current registration is not overwritten
-
register
public void register(Class<?> registrationClass, Class<?> instanceClass, boolean overwrite)
Register an instance for an internal Openbravo class (the registrationClass).- Parameters:
registrationClass
- the original Openbravo classinstanceClass
- the implementation classoverwrite
- true overwrite a current registration, false a current registration is not overwritten
-
register
public void register(String name, Class<?> instanceClass, boolean overwrite)
Register an instance for an internal Openbravo class or service (the name).- Parameters:
name
- the name of the Openbravo class or serviceinstanceClass
- the implementation classoverwrite
- true overwrite a current registration, false a current registration is not overwritten
-
get
public <T> T get(Class<T> clz)
Checks the registry for which class should be used for the passed clz. If no registration is found a new registration is created using the passed clz.- Parameters:
clz
- the class for which an instance is requested- Returns:
- an instance of the clz
-
removeInstance
public void removeInstance(Class<?> clz)
Removes the singleton instance of the clz (if any) from the internal registry. It will be recreated at next request.- Parameters:
clz
- the instance of this class is removed.
-
get
public Object get(String name)
Returns an instance of the requested service. If no registration is found an OBProviderException is thrown- Parameters:
name
- the name of the service- Returns:
- an instance of the service
- Throws:
OBProviderException
-
-