Class 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
    • Constructor Detail

      • OBProvider

        public OBProvider()
    • 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,
                                String configFile)
      • 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 class
        instanceObj - 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 class
        instanceClass - the implementation class
        overwrite - 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 service
        instanceClass - the implementation class
        overwrite - 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