public class ComponentContainer extends 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:
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.
Constructor and Description |
---|
ComponentContainer() |
Modifier and Type | Method and Description |
---|---|
Object |
findComponent(Class key)
Finds the component with the specified Class
key . |
Object |
findComponent(Object key)
Finds the component with the specified
key . |
Object |
findComponent(String key,
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. |
Object |
findComponentByNamespace(String namespace,
Object key)
Finds a component in this container with a unique (within this container)
key registered by the specified namespace . |
Collection |
findComponentsOfType(Class type)
Finds all components having the given
type . |
Object |
findRequiredComponent(Class key)
Attempts to Find the component with the specified
type ,
throwing a ComponentContainerException exception if one can not
be found. |
protected String |
getComponentDefaultConfigurationPath(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(Object key)
Registers true (false otherwise) if the component in this container with
a unique (within this container)
key is registered. |
boolean |
isRegisteredByNamespace(String namespace,
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 . |
Object |
newComponent(Class implementation,
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. |
Object |
newComponent(String implementation,
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. |
Object |
newDefaultComponent(Class type)
Creates a new component of the given
type by searching the
META-INF/services directory and finding its default
implementation. |
Object |
registerComponent(Object key,
Object component)
Registers the component in this container with a unique (within this
container)
key . |
void |
registerComponentByNamespace(String namespace,
Object key,
Object component)
Registers the component in this container with a unique (within this
container)
key by the specified namespace . |
void |
registerComponentType(Class type)
Registers the component of the specified
type . |
Object |
registerComponentType(String type)
Registers the components of the specified
type . |
Object |
registerDefaultComponent(Class componentInterface,
Class defaultType)
Registers the "default" for the specified componentInterface.
|
void |
registerDefaultComponent(Class componentInterface,
String defaultTypeName)
Registers the "default" for the specified componentInterface.
|
void |
shutdown()
Shuts down this container instance.
|
Object |
unregisterComponent(String key)
Unregisters the component in this container with a unique (within this
container)
key . |
public ComponentContainer()
public static ComponentContainer instance()
public Object findComponent(Object key)
key
.key
- the unique key of the component as an Object.public Object newComponent(String implementation, Class type)
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.implementation
- the fully qualified name of the implementation
class.type
- the type to retrieve if the implementation is empty.type
public Object newComponent(Class implementation, Class type)
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.implementation
- the implementation class.type
- the type to retrieve if the implementation is empty.type
public Object newDefaultComponent(Class type)
type
by searching the
META-INF/services
directory and finding its default
implementation.type
- type
protected final String getComponentDefaultConfigurationPath(Class type)
type
- the component type.public Object findComponent(Class key)
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.key
- the unique key as a Class.public Object findRequiredComponent(Class key)
type
,
throwing a ComponentContainerException
exception if one can not
be found.key
- the unique key of the component as an Object.public Object findComponent(String key, Class type)
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.key
- the unique key of the component.type
- the default type to retrieve if the component can not be
found.public Collection findComponentsOfType(Class type)
type
.type
- the component type.public Object unregisterComponent(String key)
key
.key
- the unique key.public Object findComponentByNamespace(String namespace, Object key)
key
registered by the specified namespace
.namespace
- the namespace for which to search.key
- the unique key.public boolean isRegisteredByNamespace(String namespace, Object key)
key
is registered by the
specified namespace
.namespace
- the namespace for which to register the component.key
- the unique key.public boolean isRegistered(Object key)
key
is registered.key
- the unique key.public void registerComponentByNamespace(String namespace, Object key, Object component)
key
by the specified namespace
.namespace
- the namespace for which to register the component.key
- the unique key.component
- public Object registerComponent(Object key, Object component)
key
.key
- the unique key.component
- public void registerDefaultComponent(Class componentInterface, String defaultTypeName)
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.public Object registerDefaultComponent(Class componentInterface, Class defaultType)
componentInterface
- the interface for the component.defaultType
- the "default" implementation to use for the
componentInterface.public void registerComponentType(Class type)
type
.type
- the type Class.public Object registerComponentType(String type)
type
.type
- the name of a type (must have be able to be instantiated into
a Class instance)public void shutdown()
Copyright © 2003–2014 AndroMDA.org. All rights reserved.