org.andromda.core.common
Class ComponentContainer

java.lang.Object
  extended by org.andromda.core.common.ComponentContainer

public class ComponentContainer
extends java.lang.Object

This handles all registration and retrieval of components within the framework. The purpose of this container is so that we can register default services in a consistent manner by creating a component interface and then placing the file which defines the default implementation in the 'META-INF/services/' directory found on the classpath.

In order to create a new component that can be registered/found through this container you must perform the following steps:

  1. Create the component interface (i.e. org.andromda.core.repository.RepositoryFacade)
  2. Create the component implementation (i.e. org.andromda.repositories.mdr.MDRepositoryFacade)
  3. Create a file with the exact same name as the fully qualified name of the component (i.e. org.andromda.core.repository.RepositoryFacade) that contains the name of the implementation class (i.e. org.andromda.repositories.mdr.MDRepostioryFacade) and place this in the META-INF/services/ directory within the core.
After you perform the above steps, the component can be found by the methods within this class. See each below method for more information on how each performs lookup/retrieval of the components.

Author:
Chad Brandon

Constructor Summary
ComponentContainer()
           
 
Method Summary
 java.lang.Object findComponent(java.lang.Class key)
          Finds the component with the specified Class key.
 java.lang.Object findComponent(java.lang.Object key)
          Finds the component with the specified key.
 java.lang.Object findComponent(java.lang.String key, java.lang.Class type)
          Attempts to find the component with the specified unique key, if it can't be found, the default of the specified type is returned, if no default is set, null is returned.
 java.lang.Object findComponentByNamespace(java.lang.String namespace, java.lang.Object key)
          Finds a component in this container with a unique (within this container) key registered by the specified namespace.
 java.util.Collection findComponentsOfType(java.lang.Class type)
          Finds all components having the given type.
 java.lang.Object findRequiredComponent(java.lang.Class key)
          Attempts to Find the component with the specified type, throwing a ComponentContainerException exception if one can not be found.
protected  java.lang.String getComponentDefaultConfigurationPath(java.lang.Class type)
          Returns the expected path to the component's default configuration file.
static ComponentContainer instance()
          Gets the shared instance of this ComponentContainer.
 boolean isRegistered(java.lang.Object key)
          Registers true (false otherwise) if the component in this container with a unique (within this container) key is registered.
 boolean isRegisteredByNamespace(java.lang.String namespace, java.lang.Object key)
          Registers true (false otherwise) if the component in this container with a unique (within this container) key is registered by the specified namespace.
 java.lang.Object newComponent(java.lang.Class implementation, java.lang.Class type)
          Creates a new component of the given implementation (if it isn't null or empty), otherwise attempts to find the default implementation of the given type by searching the META-INF/services directory for the default implementation.
 java.lang.Object newComponent(java.lang.String implementation, java.lang.Class type)
          Creates a new component of the given implementation (if it isn't null or empty), otherwise attempts to find the default implementation of the given type by searching the META-INF/services directory for the default implementation.
 java.lang.Object newDefaultComponent(java.lang.Class type)
          Creates a new component of the given type by searching the META-INF/services directory and finding its default implementation.
 java.lang.Object registerComponent(java.lang.Object key, java.lang.Object component)
          Registers the component in this container with a unique (within this container) key.
 void registerComponentByNamespace(java.lang.String namespace, java.lang.Object key, java.lang.Object component)
          Registers the component in this container with a unique (within this container) key by the specified namespace.
 void registerComponentType(java.lang.Class type)
          Registers the component of the specified type.
 java.lang.Object registerComponentType(java.lang.String type)
          Registers the components of the specified type.
 java.lang.Object registerDefaultComponent(java.lang.Class componentInterface, java.lang.Class defaultType)
          Registers the "default" for the specified componentInterface.
 void registerDefaultComponent(java.lang.Class componentInterface, java.lang.String defaultTypeName)
          Registers the "default" for the specified componentInterface.
 void shutdown()
          Shuts down this container instance.
 java.lang.Object unregisterComponent(java.lang.String key)
          Unregisters the component in this container with a unique (within this container) key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentContainer

public ComponentContainer()
Method Detail

instance

public static ComponentContainer instance()
Gets the shared instance of this ComponentContainer.

Returns:
PluginDiscoverer the static instance.

findComponent

public java.lang.Object findComponent(java.lang.Object key)
Finds the component with the specified key.

Parameters:
key - the unique key of the component as an Object.
Returns:
Object the component instance.

newComponent

public java.lang.Object newComponent(java.lang.String implementation,
                                     java.lang.Class type)
Creates a new component of the given implementation (if it isn't null or empty), otherwise attempts to find the default implementation of the given type by searching the META-INF/services directory for the default implementation.

Parameters:
implementation - the fully qualified name of the implementation class.
type - the type to retrieve if the implementation is empty.
Returns:
a new instance of the given type

newComponent

public java.lang.Object newComponent(java.lang.Class implementation,
                                     java.lang.Class type)
Creates a new component of the given implementation (if it isn't null or empty), otherwise attempts to find the default implementation of the given type by searching the META-INF/services directory for the default implementation.

Parameters:
implementation - the implementation class.
type - the type to retrieve if the implementation is empty.
Returns:
a new instance of the given type

newDefaultComponent

public java.lang.Object newDefaultComponent(java.lang.Class type)
Creates a new component of the given type by searching the META-INF/services directory and finding its default implementation.

Returns:
a new instance of the given type

getComponentDefaultConfigurationPath

protected final java.lang.String getComponentDefaultConfigurationPath(java.lang.Class type)
Returns the expected path to the component's default configuration file.

Parameters:
type - the component type.
Returns:
the path to the component configuration file.

findComponent

public java.lang.Object findComponent(java.lang.Class key)
Finds the component with the specified Class key. If the component wasn't explicitly registered then the META-INF/services directory on the classpath will be searched in order to find the default component implementation.

Parameters:
key - the unique key as a Class.
Returns:
Object the component instance.

findRequiredComponent

public java.lang.Object findRequiredComponent(java.lang.Class key)
Attempts to Find the component with the specified type, throwing a ComponentContainerException exception if one can not be found.

Parameters:
key - the unique key of the component as an Object.
Returns:
Object the component instance.

findComponent

public java.lang.Object findComponent(java.lang.String key,
                                      java.lang.Class type)
Attempts to find the component with the specified unique key, if it can't be found, the default of the specified type is returned, if no default is set, null is returned. The default is the service found within the META-INF/services directory on your classpath.

Parameters:
key - the unique key of the component.
type - the default type to retrieve if the component can not be found.
Returns:
Object the component instance.

findComponentsOfType

public java.util.Collection findComponentsOfType(java.lang.Class type)
Finds all components having the given type.

Parameters:
type - the component type.
Returns:
Collection all components

unregisterComponent

public java.lang.Object unregisterComponent(java.lang.String key)
Unregisters the component in this container with a unique (within this container) key.

Parameters:
key - the unique key.
Returns:
Object the registered component.

findComponentByNamespace

public java.lang.Object findComponentByNamespace(java.lang.String namespace,
                                                 java.lang.Object key)
Finds a component in this container with a unique (within this container) key registered by the specified namespace.

Parameters:
namespace - the namespace for which to search.
key - the unique key.
Returns:
the found component, or null.

isRegisteredByNamespace

public boolean isRegisteredByNamespace(java.lang.String namespace,
                                       java.lang.Object key)
Registers true (false otherwise) if the component in this container with a unique (within this container) key is registered by the specified namespace.

Parameters:
namespace - the namespace for which to register the component.
key - the unique key.
Returns:
boolean true/false depending on whether or not it is registerd.

isRegistered

public boolean isRegistered(java.lang.Object key)
Registers true (false otherwise) if the component in this container with a unique (within this container) key is registered.

Parameters:
key - the unique key.
Returns:
boolean true/false depending on whether or not it is registerd.

registerComponentByNamespace

public void registerComponentByNamespace(java.lang.String namespace,
                                         java.lang.Object key,
                                         java.lang.Object component)
Registers the component in this container with a unique (within this container) key by the specified namespace.

Parameters:
namespace - the namespace for which to register the component.
key - the unique key.

registerComponent

public java.lang.Object registerComponent(java.lang.Object key,
                                          java.lang.Object component)
Registers the component in this container with a unique (within this container) key.

Parameters:
key - the unique key.
Returns:
Object the registered component.

registerDefaultComponent

public void registerDefaultComponent(java.lang.Class componentInterface,
                                     java.lang.String defaultTypeName)
Registers the "default" for the specified componentInterface.

Parameters:
componentInterface - the interface for the component.
defaultTypeName - the name of the "default" type of the implementation to use for the componentInterface. Its expected that this is the name of a class.

registerDefaultComponent

public java.lang.Object registerDefaultComponent(java.lang.Class componentInterface,
                                                 java.lang.Class defaultType)
Registers the "default" for the specified componentInterface.

Parameters:
componentInterface - the interface for the component.
defaultType - the "default" implementation to use for the componentInterface.
Returns:
Object the registered component.

registerComponentType

public void registerComponentType(java.lang.Class type)
Registers the component of the specified type.

Parameters:
type - the type Class.

registerComponentType

public java.lang.Object registerComponentType(java.lang.String type)
Registers the components of the specified type.

Parameters:
type - the name of a type (must have be able to be instantiated into a Class instance)
Returns:
Object an instance of the type registered.

shutdown

public void shutdown()
Shuts down this container instance.



Copyright © 2003-2008 AndroMDA.org. All Rights Reserved.