org.jomc.ri
Class DefaultObjectManager

Package class diagram package DefaultObjectManager
java.lang.Object
  extended by org.jomc.ri.DefaultObjectManager
All Implemented Interfaces:
org.jomc.ObjectManager

@Generated(value="org.jomc.tools.JavaSources",
           comments="See http://jomc.sourceforge.net/jomc/1.0-alpha-11/jomc-tools")
public class DefaultObjectManager
extends Object
implements org.jomc.ObjectManager

Object management and configuration reference implementation.

Specifications

Version:
$Id: DefaultObjectManager.java 1102 2009-12-07 03:01:58Z schulte2005 $
Author:
Christian Schulte 1.0

Field Summary
protected static String SINGLETON_SCOPE_IDENTIFIER
          Constant for the Singleton scope identifier.
 
Constructor Summary
DefaultObjectManager()
          Creates a new DefaultObjectManager instance.
 
Method Summary
static String getBootstrapClassLoaderClassName()
          Gets the name of the platform's bootstrap class loader class.
static ClassLoader getClassLoader(Class clazz)
          Gets the class loader of a given class.
static ClassLoader getClassLoader(ClassLoader classLoader)
          Gets the parent class loader of a given class loader recursively.
 org.jomc.spi.Locator getDefaultLocator(URI location)
          Gets the default locator implementation for a given location URI.
static Level getDefaultLogLevel()
          Gets the default log level events are logged at.
 org.jomc.spi.Scope getDefaultScope(String identifier)
          Gets the default scope implementation for a given identifier.
 Object getDependency(Object object, String dependencyName)
           
 org.jomc.spi.Invocation getInvocation(Object object, org.jomc.model.Instance instance, Method method, Object[] arguments)
          Gets an invocation for a given object, instance, method and arguments.
 org.jomc.spi.Invoker getInvoker(ClassLoader classLoader)
          Gets the invoker of the given class loader.
 List<org.jomc.spi.Listener> getListeners()
          Gets the list of registered listeners.
 org.jomc.spi.Locator getLocator(ClassLoader classLoader, URI location)
          Gets a locator to use with a given location URI.
 Level getLogLevel()
          Gets the log level of the instance.
 String getMessage(Object object, String messageName, Locale locale, Object arguments)
           
 org.jomc.model.Modules getModules(ClassLoader classLoader)
          Gets the modules of a given class loader.
 Object getObject(Class specification)
           
<T> T
getObject(Class<T> specification, URI location, ClassLoader classLoader)
          Gets an object for a given location URI.
 Object getObject(Class specification, String implementationName)
           
 Object getObject(org.jomc.spi.Scope scope, org.jomc.model.Instance instance, ClassLoader classLoader)
          Gets an object of a given instance from a given scope.
static org.jomc.ObjectManager getObjectManager(ClassLoader classLoader)
          Default ObjectManagerFactory.getObjectManager(ClassLoader) implementation.
 Object getProperty(Object object, String propertyName)
           
 org.jomc.spi.Scope getScope(ClassLoader classLoader, String identifier)
          Gets the scope implementation for a given scope identifier.
 void initialize()
          Initializes the instance.
 boolean isLoggable(Level level)
          Checks if a message at a given level is provided to the listeners of the instance.
protected  void log(Level level, String message, Throwable throwable)
          Notifies registered listeners.
static void setBootstrapClassLoaderClassName(String value)
          Sets the name of the platform's bootstrap class loader class.
static void setDefaultLogLevel(Level value)
          Sets the default log level events are logged at.
 void setLogLevel(Level value)
          Sets the log level of the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLETON_SCOPE_IDENTIFIER

protected static final String SINGLETON_SCOPE_IDENTIFIER
Constant for the Singleton scope identifier.

See Also:
Constant Field Values
Constructor Detail

DefaultObjectManager

@Generated(value="org.jomc.tools.JavaSources",
           comments="See http://jomc.sourceforge.net/jomc/1.0-alpha-11/jomc-tools")
public DefaultObjectManager()
Creates a new DefaultObjectManager instance.

Method Detail

getObject

public Object getObject(Class specification)
Specified by:
getObject in interface org.jomc.ObjectManager

getObject

public Object getObject(Class specification,
                        String implementationName)
Specified by:
getObject in interface org.jomc.ObjectManager

getDependency

public Object getDependency(Object object,
                            String dependencyName)
Specified by:
getDependency in interface org.jomc.ObjectManager

getProperty

public Object getProperty(Object object,
                          String propertyName)
Specified by:
getProperty in interface org.jomc.ObjectManager

getMessage

public String getMessage(Object object,
                         String messageName,
                         Locale locale,
                         Object arguments)
Specified by:
getMessage in interface org.jomc.ObjectManager

getObjectManager

public static org.jomc.ObjectManager getObjectManager(ClassLoader classLoader)
Default ObjectManagerFactory.getObjectManager(ClassLoader) implementation.

Returns:
The default ObjectManager singleton instance.
See Also:
ObjectManagerFactory.getObjectManager(ClassLoader)

getListeners

public List<org.jomc.spi.Listener> getListeners()
Gets the list of registered listeners.

This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the object. This is why there is no set method for the listeners property.

Returns:
The list of registered listeners.

getDefaultLogLevel

public static Level getDefaultLogLevel()
Gets the default log level events are logged at.

The default log level is controlled by system property org.jomc.ri.DefaultObjectManager.defaultLogLevel holding the log level to log events at by default. If that property is not set, the WARNING default is returned.

Returns:
The log level events are logged at by default.
See Also:
getLogLevel(), Level.parse(java.lang.String)

setDefaultLogLevel

public static void setDefaultLogLevel(Level value)
Sets the default log level events are logged at.

Parameters:
value - The new default level events are logged at or null.
See Also:
getDefaultLogLevel()

getLogLevel

public Level getLogLevel()
Gets the log level of the instance.

Returns:
The log level of the instance.
See Also:
getDefaultLogLevel(), setLogLevel(java.util.logging.Level), isLoggable(java.util.logging.Level)

setLogLevel

public void setLogLevel(Level value)
Sets the log level of the instance.

Parameters:
value - The new log level of the instance or null.
See Also:
getLogLevel(), isLoggable(java.util.logging.Level)

isLoggable

public boolean isLoggable(Level level)
Checks if a message at a given level is provided to the listeners of the instance.

Parameters:
level - The level to test.
Returns:
true if messages at level are provided to the listeners of the instance; false if messages at level are not provided to the listeners of the instance.
Throws:
NullPointerException - if level is null.
See Also:
getLogLevel(), setLogLevel(java.util.logging.Level), log(java.util.logging.Level, java.lang.String, java.lang.Throwable)

getBootstrapClassLoaderClassName

public static String getBootstrapClassLoaderClassName()
Gets the name of the platform's bootstrap class loader class.

The name of the platform's bootstrap class loader class is controlled by system property org.jomc.ri.DefaultObjectManager.bootstrapClassLoaderClassName holding the name of the platform's bootstrap class loader class. If that property is not set, the bootstrap class loader is assumed to be represented by a null parent class loader.

Returns:
The name of the platform's bootstrap class loader class or null.
See Also:
getClassLoader(java.lang.ClassLoader)

setBootstrapClassLoaderClassName

public static void setBootstrapClassLoaderClassName(String value)
Sets the name of the platform's bootstrap class loader class.

Parameters:
value - The new name of the platform's bootstrap class loader class or null.
See Also:
getBootstrapClassLoaderClassName()

getModules

public org.jomc.model.Modules getModules(ClassLoader classLoader)
Gets the modules of a given class loader.

Parameters:
classLoader - The class loader to get the modules of.
Returns:
The modules of the given class loader.
Throws:
NullPointerException - if classLoader is null,

getClassLoader

public static ClassLoader getClassLoader(Class clazz)
Gets the class loader of a given class.

Parameters:
clazz - The class whose class loader to return.
Returns:
The class loader of clazz.
Throws:
NullPointerException - if clazz is null.

getClassLoader

public static ClassLoader getClassLoader(ClassLoader classLoader)
Gets the parent class loader of a given class loader recursively.

This method recursively finds the parent class loader of the given class loader. Recursion stops at the platform's bootstrap class loader. That class loader is detected when either the current class loader has no parent (a call to the getParent() method returns null) or when the class name of the current class loader's parent class loader is equal to the name returned by method getBootstrapClassLoaderClassName(). Configuration of the name of the platform's bootstrap class loader class is needed when the platform's getParent() method of the ClassLoader class does not return null to indicate the bootstrap class loader but instead returns an instance of ClassLoader.

Parameters:
classLoader - The class loader whose parent class loader to return or null to return a ClassLoader instance representing the platform's bootstrap class loader.
Returns:
The parent class loader of classLoader.
Throws:
NullPointerException - if classLoader is null.
See Also:
getBootstrapClassLoaderClassName(), ClassLoader.getParent()

getObject

public Object getObject(org.jomc.spi.Scope scope,
                        org.jomc.model.Instance instance,
                        ClassLoader classLoader)
                 throws InstantiationException
Gets an object of a given instance from a given scope.

Parameters:
scope - The scope to get the object from or null.
instance - The instance of the object to get.
classLoader - The class loader to use for creating the object.
Returns:
An object of instance from scope or null if no such object is found.
Throws:
NullPointerException - if instance or classLoader is null.
InstantiationException - if creating an object fails.

getObject

public <T> T getObject(Class<T> specification,
                       URI location,
                       ClassLoader classLoader)
            throws InstantiationException,
                   ClassNotFoundException,
                   IOException
Gets an object for a given location URI.

Type Parameters:
T - The type of the object.
Parameters:
specification - The specification class of the object to locate.
location - The location URI of the object to locate.
classLoader - The class loader to use for loading locator classes.
Returns:
An object located at location or null if no such object is found.
Throws:
NullPointerException - if specification, location or classLoader is null.
InstantiationException - if instantiating a locator fails.
ClassNotFoundException - if the class of specification is not found.
IOException - if locating the object fails.

getScope

public org.jomc.spi.Scope getScope(ClassLoader classLoader,
                                   String identifier)
                            throws InstantiationException
Gets the scope implementation for a given scope identifier.

Parameters:
classLoader - The class loader to use for loading scope implementations.
identifier - The identifier of the scope to get an implementation of.
Returns:
The implementation of the scope identified by identifier or null if no such scope implementation is found.
Throws:
NullPointerException - if classLoader or identifier is null.
InstantiationException - if instantiating a scope fails.
See Also:
getDefaultScope(java.lang.String)

getDefaultScope

public org.jomc.spi.Scope getDefaultScope(String identifier)
Gets the default scope implementation for a given identifier.

Parameters:
identifier - The identifier of the scope to get a default implementation of.
Returns:
The default implementation of the scope identified by identifier or null if no such default implementation is available.
Throws:
NullPointerException - if identifier is null.
See Also:
getScope(java.lang.ClassLoader, java.lang.String)

getLocator

public org.jomc.spi.Locator getLocator(ClassLoader classLoader,
                                       URI location)
                                throws InstantiationException
Gets a locator to use with a given location URI.

Parameters:
classLoader - The class loader to use for loading locator implementations.
location - The location URI to get a locator for.
Returns:
The locator to use for locating objects at location or null if no such locator is available.
Throws:
NullPointerException - if classLoader or location is null.
InstantiationException - if instantiating a locator fails.
See Also:
getDefaultLocator(java.net.URI)

getDefaultLocator

public org.jomc.spi.Locator getDefaultLocator(URI location)
Gets the default locator implementation for a given location URI.

Parameters:
location - The location URI to get a default locator implementation for.
Returns:
The default locator implementation for location or null if no default implementation is available for location.
Throws:
NullPointerException - if location is null.
See Also:
getLocator(java.lang.ClassLoader, java.net.URI)

getInvoker

public org.jomc.spi.Invoker getInvoker(ClassLoader classLoader)
                                throws InstantiationException
Gets the invoker of the given class loader.

Parameters:
classLoader - The class loader to use for loading invoker implementations.
Returns:
The invoker of the given class loader.
Throws:
NullPointerException - if classLoader is null.
InstantiationException - if instantiating a new invoker fails.

getInvocation

public org.jomc.spi.Invocation getInvocation(Object object,
                                             org.jomc.model.Instance instance,
                                             Method method,
                                             Object[] arguments)
                                      throws InstantiationException
Gets an invocation for a given object, instance, method and arguments.

Parameters:
object - The object to invoke.
instance - The instance of the object to invoke.
method - The method to invoke on object.
arguments - The arguments of the invocation or null.
Returns:
An invocation with object, instance, method and arguments.
Throws:
NullPointerException - if object, instance or method is null.
InstantiationException - if instantiating a new invocation fails.

initialize

public void initialize()
                throws InstantiationException
Initializes the instance.

This method is called once on first usage of a new instance.

Throws:
InstantiationException - if initialization fails.

log

protected void log(Level level,
                   String message,
                   Throwable throwable)
Notifies registered listeners.

Parameters:
level - The level of the event.
message - The message of the event or null.
throwable - The throwable of the event or null.
Throws:
NullPointerException - if level is null.


Copyright © 2005-2009 The JOMC Project. All Rights Reserved.