org.sakaiproject.service.framework.component
Interface ComponentManager

All Known Implementing Classes:
ComponentManagerAdaptor

public interface ComponentManager

ComponentManager manages service implementation components.

A component is a java class which implements some published Service API.

Components can declare javabean setter methods or constructors to accept configuration parameters and Service API dependency components which are injected by this component framework. An optional "init" and "destroy" method can also be called by the framework. These details are convered in the component's definition in the XML definition file. This file includes bean definitions that follow the format defined by the Spring Framework in the spring-beans DTD.

To register components, call loadXmlFile or loadXmlStream with a file or stream of XML describing the components to register. These can be called more than once, perhaps at different times, or by different webapps, to register multiple sets of components. All registered components are all available to all clients as a single set.

Components are registered under the fully qualified name of the interface the component implements.

To find a component registered to handle a given interface, use get, either with the fully qualified interface name as a string, or the interface Class object. The component manager will find a component if it has been created in scope, or create, wire / configure, and remember the component as needed.

Information about registered components is available from the contains, getLifestyle, and getRegisteredInterfaces methods.

Version:
$Revision: 632 $
Author:
University of Michigan, Sakai Software Development Team

Field Summary
static int LIFESTYLE_MANY
          Lifestyle code: a unique instance of the component will be created for each client get() request.
static int LIFESTYLE_SINGLE
          Lifestyle code: a single instance of the component will be served to all clients.
static int LIFESTYLE_UNKNOWN
          Lifestyle code: unknown lifecycle.
 
Method Summary
 boolean contains(Class iface)
          Check if this interface Class has a registered component.
 boolean contains(String ifaceName)
          Check if this interface Class name has a registered component.
 Object get(Class iface)
          Find a component that is registered to provide this interface.
 Object get(String ifaceName)
          Find a component that is registered to provide this interface.
 int getLifestyle(Class iface)
          Access the lifestyle code for the component implementing this interface.
 Set getLocalRegisteredInterfaces()
          Get all interfaces registered in just this component manager.
 Set getRegisteredInterfaces()
          Get all interfaces registered in the component manager hierarchy.
 boolean isReady()
          Check if the component manager is ready with all expected registrations to start service components.
 void loadComponent(Class iface, Object component)
          Load a single already created component for this interface class as a singleton.
 void loadComponent(String ifaceName, Object component)
          Load a single already created component for this interface class as a singleton.
 void loadXmlFile(String filename)
          Load a set of component definitions from this file.
 void loadXmlStream(InputStream stream)
          Load a set of component definitions from this XML input stream.
 ComponentManager nestComponentManager()
          Create a new component manager nested in this component manager, extending the definitions of this component manager.
 void setReady(boolean ready)
          Set the readiness of the hierarchy
 void unload()
          Unload registrations and release any constructed instances.
 

Field Detail

LIFESTYLE_UNKNOWN

public static final int LIFESTYLE_UNKNOWN
Lifestyle code: unknown lifecycle.

See Also:
Constant Field Values

LIFESTYLE_SINGLE

public static final int LIFESTYLE_SINGLE
Lifestyle code: a single instance of the component will be served to all clients.

See Also:
Constant Field Values

LIFESTYLE_MANY

public static final int LIFESTYLE_MANY
Lifestyle code: a unique instance of the component will be created for each client get() request.

See Also:
Constant Field Values
Method Detail

get

public Object get(Class iface)
Find a component that is registered to provide this interface.

Parameters:
iface - The interface Class.
Returns:
a component instance, or null if not found.

get

public Object get(String ifaceName)
Find a component that is registered to provide this interface.

Parameters:
ifaceName - The fully qualified interface Class name.
Returns:
a component instance, or null if not found.

contains

public boolean contains(Class iface)
Check if this interface Class has a registered component.

Parameters:
iface - The interface Class.
Returns:
true if this interface Class has a registered component, false if not.

contains

public boolean contains(String ifaceName)
Check if this interface Class name has a registered component.

Parameters:
ifaceName - The fully qualified interface Class name.
Returns:
true if this interface has a registered component, false if not.

getLifestyle

public int getLifestyle(Class iface)
Access the lifestyle code for the component implementing this interface.

Parameters:
iface - The interface class.
Returns:
the lifestyle code for the component implementing this interface.
See Also:
LIFESTYLE_UNKNOWN, LIFESTYLE_SINGLE, LIFESTYLE_MANY

getRegisteredInterfaces

public Set getRegisteredInterfaces()
Get all interfaces registered in the component manager hierarchy.

Returns:
A Set (String class name) of all interfaces registered in the component manager.

getLocalRegisteredInterfaces

public Set getLocalRegisteredInterfaces()
Get all interfaces registered in just this component manager.

Returns:
A Set (String class name) of all interfaces registered in the component manager.

unload

public void unload()
Unload registrations and release any constructed instances.


loadXmlFile

public void loadXmlFile(String filename)
Load a set of component definitions from this file.

Parameters:
filename - The name of the file containing the component definition XML.

loadXmlStream

public void loadXmlStream(InputStream stream)
Load a set of component definitions from this XML input stream.

Parameters:
stream - The input stream containing the component definition XML.

loadComponent

public void loadComponent(Class iface,
                          Object component)
Load a single already created component for this interface class as a singleton.

Parameters:
iface - The interface class.
component - The alread created component.

loadComponent

public void loadComponent(String ifaceName,
                          Object component)
Load a single already created component for this interface class as a singleton.

Parameters:
ifaceName - The fully qualified interface Class name.
component - The alread created component.

nestComponentManager

public ComponentManager nestComponentManager()
Create a new component manager nested in this component manager, extending the definitions of this component manager.

Returns:
The new component manager.

isReady

public boolean isReady()
Check if the component manager is ready with all expected registrations to start service components.

Returns:
true if ready, false if not.

setReady

public void setReady(boolean ready)
Set the readiness of the hierarchy

Parameters:
ready - true if ready, false if not.