org.openpermis.editor.policy.configuration
Class BasicComponentFactory

java.lang.Object
  extended by org.openpermis.editor.policy.configuration.BasicComponentFactory
All Implemented Interfaces:
ComponentFactory

public class BasicComponentFactory
extends Object
implements ComponentFactory

Basic implementation of a pico container based component factory.

Since:
0.9.0

Constructor Summary
BasicComponentFactory(ClassSettings settings, ConfigurationReader reader)
          Creates a new component factory for the specified configuration URL.
BasicComponentFactory(org.picocontainer.MutablePicoContainer contextContainer, org.picocontainer.MutablePicoContainer factoryContainer)
          Creates a new component factory for the specified context and factory container.
 
Method Summary
 void addFactoryAdapter(org.picocontainer.ComponentAdapter<?> componentAdapter)
          Adds a component adapter to the factory container.
 void addFactoryComponent(Object implOrInstance)
          Adds a component implementation or instance to the factory container.
 void addFactoryComponent(Object componentKey, Object implOrInstance)
          Adds a component implementation or instance to the factory container with a key.
 boolean canCreate(TypeKey typeKey)
          Check if this factory can create components of the given type.
<T> T
create(Class<?> type, State... context)
          Creates a component.
<T> T
create(TypeKey typeKey, State... context)
          Creates a typed component.
protected
<T> T
getComponent(Object key, State... context)
           
<T> List<T>
instances(Class<T> type)
          Returns a list of all instances of a specific type stored at the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicComponentFactory

public BasicComponentFactory(ClassSettings settings,
                             ConfigurationReader reader)
                      throws ConfigurationException
Creates a new component factory for the specified configuration URL.

Parameters:
settings - the object to store configuration settings to.
reader - the reader for the configuration.
Throws:
ConfigurationException - passed on, see ConfigurationReader.configure(org.openpermis.editor.policy.configuration.ClassSettings, org.picocontainer.MutablePicoContainer).
Since:
0.9.0

BasicComponentFactory

public BasicComponentFactory(org.picocontainer.MutablePicoContainer contextContainer,
                             org.picocontainer.MutablePicoContainer factoryContainer)
Creates a new component factory for the specified context and factory container.

The context has to be a parent container of the factory container (not checked).

The factory becomes the new owner of the two containers passed in!

Parameters:
contextContainer - the context container that is modified during construction time to add optional state to.
factoryContainer - the readonly factory container that contains the implementation classes or keys.
Since:
0.9.0
Method Detail

addFactoryComponent

public void addFactoryComponent(Object implOrInstance)
Adds a component implementation or instance to the factory container.

Implementation classes will be added without caching.

Parameters:
implOrInstance - the component implementation or instance add.
Since:
0.9.0

addFactoryComponent

public void addFactoryComponent(Object componentKey,
                                Object implOrInstance)
Adds a component implementation or instance to the factory container with a key.

Implementation classes will be added without caching.

Parameters:
componentKey - the component key to use.
implOrInstance - the component implementation or instance add.
Since:
0.9.0

addFactoryAdapter

public void addFactoryAdapter(org.picocontainer.ComponentAdapter<?> componentAdapter)
Adds a component adapter to the factory container.

Parameters:
componentAdapter - the component adapter to add.
Since:
0.9.0

getComponent

protected <T> T getComponent(Object key,
                             State... context)
Since:
0.9.0

create

public <T> T create(Class<?> type,
                    State... context)
Description copied from interface: ComponentFactory
Creates a component.

The context state supplied is used to fill in missing parameters that are not available as default instances or implementations at the factory.

Specified by:
create in interface ComponentFactory
Type Parameters:
T - the component type, has to correspond to the scope of the type key.
Parameters:
type - the class for which to create the component.
context - additional state to inject to the component created.
Returns:
the component created.
Since:
0.9.0

create

public <T> T create(TypeKey typeKey,
                    State... context)
Description copied from interface: ComponentFactory
Creates a typed component.

The context state supplied is used to fill in missing parameters that are not available as default instances or implementations at the factory.

Specified by:
create in interface ComponentFactory
Type Parameters:
T - the component type, has to correspond to the scope of the type key.
Parameters:
typeKey - the type key for which to create the component.
context - additional state to inject to the component created.
Returns:
the component created.
Since:
0.9.0

canCreate

public boolean canCreate(TypeKey typeKey)
Description copied from interface: ComponentFactory
Check if this factory can create components of the given type.

Specified by:
canCreate in interface ComponentFactory
Parameters:
typeKey - the type key for which to check if the factory can create an instance.
Returns:
true if the factory can provide an instance, false otherwise.
Since:
0.9.0

instances

public <T> List<T> instances(Class<T> type)
Description copied from interface: ComponentFactory
Returns a list of all instances of a specific type stored at the factory.

Take care to use this method only to retrieve cached instances otherwise this factory will create an instance for each of the registered implementation types that are assignable to the type specified.

Specified by:
instances in interface ComponentFactory
Type Parameters:
T - the instance type to retrieve.
Parameters:
type - the class of the instance type to retrieve.
Returns:
the list of all known instances, never null but may be empty.
Since:
0.9.0


OpenPermis Role Based Access Control 0.9.0 (Build 16)
2009/08/13 07:17:21
Copyright (c) 2002-2007 Ergon Informatik AG