jfun.yan
Interface Container

All Superinterfaces:
ComponentMap, Registrar, java.io.Serializable
All Known Implementing Classes:
DefaultContainer, DelegatingContainer, ImmutablePreferredContainer, ManualContainer, ManualWiringContainer, MonitoringContainer, ProxyContainer, SimpleContainer, SingletonContainer, SingletonProxyContainer, TransformingContainer

public interface Container
extends Registrar

The facade interface which provides the full functionality of yan container.

Codehaus.org.

Author:
Ben Yu

Method Summary
 java.lang.Class getComponentType(java.lang.Object key)
          Get the type of a component identified by a key.
 Dependency getDependency(java.lang.Object key)
          Get the dependency for a component key.
 Dependency getDependencyOfType(java.lang.Class type)
          Get the dependency for a component type.
 Factory getFactory(java.lang.Object key)
          Create an instance of Factory for a component identified by a key.
 Factory getFactory(java.lang.Object key, ComponentMap cmap)
          Create an instance of Factory for a component identified by a key.
<T> Factory<T>
getFactoryOfType(java.lang.Class<T> type)
          Create an instance of Factory for a component of the provided type.
<T> Factory<T>
getFactoryOfType(java.lang.Class<T> type, ComponentMap cmap)
          Create an instance of Factory for a component of the provided type.
 java.lang.Object getInstance(java.lang.Object key)
          Create instance for a component identified by a key.
 java.lang.Object getInstance(java.lang.Object key, ComponentMap cmap)
          Create instance for a component identified by a key.
<T> T
getInstanceOfType(java.lang.Class<T> type)
          Create component instance of the provided type.
<T> T
getInstanceOfType(java.lang.Class<T> type, ComponentMap cmap)
          Create component instance of the provided type.
 java.util.List getInstances()
          Create instances of all the components stored in this container.
 java.util.List getInstances(ComponentMap cmap)
          Create instances of all the components stored in this container.
 void getInstances(java.util.Map store)
          Create instances of all the components stored in this container.
 void getInstances(java.util.Map store, ComponentMap cmap)
          Create instances of all the components stored in this container.
<T> java.util.List<T>
getInstancesOfType(java.lang.Class<T> type)
          Create component instances of a provided type.
<T> java.util.List<T>
getInstancesOfType(java.lang.Class<T> type, ComponentMap cmap)
          Create component instances of a provided type.
 Container inherit(Registrar parent)
          Create a new Container object which represents "this inherits parent" relationship.
<T> T
instantiateComponent(Creator<T> cc)
          Instantiate component instance.
<T> T
instantiateComponent(java.lang.Object key, Creator<T> cc)
          Instantiate component instance.
 void registerComponent(Component cc)
          Register a Component object in the container.
 void registerConstructor(java.lang.Class c)
          Register a constructor in the container.
 void registerConstructor(java.lang.Class c, java.lang.Class[] param_types)
          Register a constructor in the container.
 void registerConstructor(java.lang.Object key, java.lang.Class c)
          Register a constructor in the container.
 void registerConstructor(java.lang.Object key, java.lang.Class c, java.lang.Class[] param_types)
          Register a constructor in the container.
 void registerStaticMethod(java.lang.Class c, java.lang.String name)
          Register a component that uses a static method to create component instance.
 void registerStaticMethod(java.lang.Class c, java.lang.String name, java.lang.Class[] param_types)
          Register a component that uses a static method to create component instance.
 void registerStaticMethod(java.lang.Object key, java.lang.Class c, java.lang.String name)
          Register a component that uses a static method to create component instance.
 void registerStaticMethod(java.lang.Object key, java.lang.Class c, java.lang.String name, java.lang.Class[] param_types)
          Register a component that uses a static method to create component instance.
 void registerValue(java.lang.Object v)
          Register a value in the container.
 void registerValue(java.lang.Object key, java.lang.Object v)
          Register a value in the container.
 void verify()
          Verifies the components in this container.
 java.lang.Class verifyComponent(Component cc)
          Verifies that a Component is valid using the current container in resolving dependency.
 java.lang.Class verifyKey(java.lang.Object key)
          Verifies a component identified by key.
 java.lang.Class verifyType(java.lang.Class type)
          Verifies a component for a type.
 
Methods inherited from interface jfun.yan.Registrar
registerComponent, unregisterComponent, unregisterComponentsOfType, verify
 
Methods inherited from interface jfun.yan.ComponentMap
containsKey, containsType, getComponent, getComponentOfType, getComponents, getComponentsOfType, getDependency, getDependencyOfType, keys
 

Method Detail

instantiateComponent

<T> T instantiateComponent(Creator<T> cc)
                       throws AmbiguousComponentResolutionException,
                              ComponentInstantiationException,
                              CyclicDependencyException,
                              UnresolvedComponentException,
                              UnsatisfiedComponentException,
                              YanException
Instantiate component instance. The dependencies are resolved in the current container.

Parameters:
cc - the component to instantiate.
Returns:
the component instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

instantiateComponent

<T> T instantiateComponent(java.lang.Object key,
                           Creator<T> cc)
                       throws AmbiguousComponentResolutionException,
                              ComponentInstantiationException,
                              CyclicDependencyException,
                              UnresolvedComponentException,
                              UnsatisfiedComponentException,
                              YanException
Instantiate component instance. The dependencies are resolved in the current container.

Parameters:
key - the key of the component.
cc - the component to instantiate.
Returns:
the component instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstanceOfType

<T> T getInstanceOfType(java.lang.Class<T> type,
                        ComponentMap cmap)
                    throws AmbiguousComponentResolutionException,
                           ComponentInstantiationException,
                           CyclicDependencyException,
                           UnresolvedComponentException,
                           UnsatisfiedComponentException,
                           YanException
Create component instance of the provided type.

Parameters:
type - the type.
cmap - the container to resolve dependency.
Returns:
the component instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getFactoryOfType

<T> Factory<T> getFactoryOfType(java.lang.Class<T> type,
                                ComponentMap cmap)
                            throws AmbiguousComponentResolutionException,
                                   UnresolvedComponentException,
                                   YanException
Create an instance of Factory for a component of the provided type. when Factory.create() is called, the component is instantiated.

Parameters:
type - the type.
cmap - the container to resolve dependency.
Returns:
the factory instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.

getInstancesOfType

<T> java.util.List<T> getInstancesOfType(java.lang.Class<T> type,
                                         ComponentMap cmap)
                                     throws ComponentInstantiationException,
                                            CyclicDependencyException,
                                            UnresolvedComponentException,
                                            UnsatisfiedComponentException,
                                            YanException
Create component instances of a provided type. If more than one components are found for the same type, both are invoked and the results are collected in the list.

Parameters:
type - the type.
cmap - the container to resolve dependency.
Returns:
the list containing all the component instances.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstanceOfType

<T> T getInstanceOfType(java.lang.Class<T> type)
                    throws AmbiguousComponentResolutionException,
                           ComponentInstantiationException,
                           CyclicDependencyException,
                           UnresolvedComponentException,
                           UnsatisfiedComponentException,
                           YanException
Create component instance of the provided type. The dependencies are resolved in the current container.

Parameters:
type - the type.
Returns:
the component instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getFactoryOfType

<T> Factory<T> getFactoryOfType(java.lang.Class<T> type)
                            throws AmbiguousComponentResolutionException,
                                   UnresolvedComponentException,
                                   YanException
Create an instance of Factory for a component of the provided type. when Factory.create() is called, the component is instantiated.

Parameters:
type - the type.
Returns:
the factory instance.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
YanException - for any other exception.

getInstancesOfType

<T> java.util.List<T> getInstancesOfType(java.lang.Class<T> type)
                                     throws ComponentInstantiationException,
                                            CyclicDependencyException,
                                            UnresolvedComponentException,
                                            UnsatisfiedComponentException,
                                            YanException
Create component instances of a provided type. If more than one components are found for the same type, both are invoked and the results are collected in the list.
The dependencies are resolved in the current container.

Parameters:
type - the type.
Returns:
the list containing all the component instances.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstances

java.util.List getInstances()
                            throws ComponentInstantiationException,
                                   CyclicDependencyException,
                                   UnresolvedComponentException,
                                   UnsatisfiedComponentException,
                                   YanException
Create instances of all the components stored in this container.
The dependencies are resolved in the current container.

Returns:
the list containing all the component instances.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstances

void getInstances(java.util.Map store)
                  throws ComponentInstantiationException,
                         CyclicDependencyException,
                         UnresolvedComponentException,
                         UnsatisfiedComponentException,
                         YanException
Create instances of all the components stored in this container. The component instances are stored into a java.util.Map object under the component key.
The dependencies are resolved in the current container.

Parameters:
store - the java.util.Map object to save the component instances.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstances

java.util.List getInstances(ComponentMap cmap)
                            throws ComponentInstantiationException,
                                   CyclicDependencyException,
                                   UnresolvedComponentException,
                                   UnsatisfiedComponentException,
                                   YanException
Create instances of all the components stored in this container.

The dependencies are resolved in the current container.

Parameters:
cmap - the container in which to resolve dependency.
Returns:
the list containing all the component instances.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getInstances

void getInstances(java.util.Map store,
                  ComponentMap cmap)
                  throws ComponentInstantiationException,
                         CyclicDependencyException,
                         UnresolvedComponentException,
                         UnsatisfiedComponentException,
                         YanException
Create instances of all the components stored in this container. The component instances are stored into a java.util.Map object under the component key.

The dependencies are resolved in the current container.

Parameters:
store - the java.util.Map object to save the component instances.
cmap - the container in which to resolve dependency.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getDependency

Dependency getDependency(java.lang.Object key)
Get the dependency for a component key.

Parameters:
key - the component key.
Returns:
the Dependency object.

getDependencyOfType

Dependency getDependencyOfType(java.lang.Class type)
Get the dependency for a component type.

Parameters:
type - the component type.
Returns:
the Dependency object.

verify

void verify()
            throws AmbiguousComponentResolutionException,
                   CyclicDependencyException,
                   UnresolvedComponentException,
                   UnsatisfiedComponentException,
                   YanException
Verifies the components in this container. Dependencies are resolved in the current container.

Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if any component cannot be resolved.
UnsatisfiedComponentException - if some requirement of a component cannot be satisfied.
YanException - for any other exception.

verifyComponent

java.lang.Class verifyComponent(Component cc)
                                throws AmbiguousComponentResolutionException,
                                       CyclicDependencyException,
                                       UnsatisfiedComponentException,
                                       YanException
Verifies that a Component is valid using the current container in resolving dependency.

Parameters:
cc - the component to verify.
Returns:
the type of the component.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
CyclicDependencyException - if cyclic dependency is detected.
UnsatisfiedComponentException - if some requirement of a component cannot be satisfied.
YanException - for any other exception.

verifyKey

java.lang.Class verifyKey(java.lang.Object key)
                          throws CyclicDependencyException,
                                 UnresolvedComponentException,
                                 UnsatisfiedComponentException,
                                 YanException
Verifies a component identified by key.

Parameters:
key - the component key.
Returns:
the component type.
Throws:
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if the component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

verifyType

java.lang.Class verifyType(java.lang.Class type)
                           throws AmbiguousComponentResolutionException,
                                  CyclicDependencyException,
                                  UnsatisfiedComponentException,
                                  YanException
Verifies a component for a type.

Parameters:
type - the component type.
Returns:
the component type.
Throws:
AmbiguousComponentResolutionException - if ambiguity happens.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if the component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getComponentType

java.lang.Class getComponentType(java.lang.Object key)
Get the type of a component identified by a key.

Parameters:
key - the component key.
Returns:
the type of the component or null if not found.

getInstance

java.lang.Object getInstance(java.lang.Object key,
                             ComponentMap cmap)
                             throws ComponentInstantiationException,
                                    CyclicDependencyException,
                                    UnresolvedComponentException,
                                    UnsatisfiedComponentException,
                                    YanException
Create instance for a component identified by a key.

Parameters:
key - the component key.
cmap - the container to resolve dependency.
Returns:
the component instance.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getFactory

Factory getFactory(java.lang.Object key,
                   ComponentMap cmap)
                   throws UnresolvedComponentException,
                          YanException
Create an instance of Factory for a component identified by a key. when Factory.create() is called, the component is instantiated.

Parameters:
key - the component key.
cmap - the container to resolve dependency.
Returns:
the factory instance.
Throws:
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.

getInstance

java.lang.Object getInstance(java.lang.Object key)
                             throws ComponentInstantiationException,
                                    CyclicDependencyException,
                                    UnresolvedComponentException,
                                    UnsatisfiedComponentException,
                                    YanException
Create instance for a component identified by a key. Dependencies are resolved in the current container.

Parameters:
key - the component key.
Returns:
the component instance.
Throws:
ComponentInstantiationException - wrapper exception for any checked exception thrown out of the actual creation.
CyclicDependencyException - if cyclic dependency is detected.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
UnsatisfiedComponentException - if some requirement of the component cannot be satisfied.
YanException - for any other exception.

getFactory

Factory getFactory(java.lang.Object key)
                   throws UnresolvedComponentException,
                          YanException
Create an instance of Factory for a component identified by a key. when Factory.create() is called, the component is instantiated.

Parameters:
key - the component key.
Returns:
the factory instance.
Throws:
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.

registerValue

void registerValue(java.lang.Object key,
                   java.lang.Object v)
Register a value in the container.

Parameters:
key - the key of the value.
v - the value.

registerValue

void registerValue(java.lang.Object v)
Register a value in the container. Equivalent as registerValue(v.getClass(), v).

Parameters:
v - the value.

registerComponent

void registerComponent(Component cc)
                       throws UnknownComponentTypeException
Register a Component object in the container. Equivalent as registerComponent(cc.getType(), cc). cc.getType() is not allowed to return null.

Parameters:
cc - the component.
Throws:
UnknownComponentTypeException - if cc.getType() == null.

registerConstructor

void registerConstructor(java.lang.Class c)
Register a constructor in the container. Equivalent as registerConstructor(c, c).

Parameters:
c - the class containing the constructor.

registerConstructor

void registerConstructor(java.lang.Object key,
                         java.lang.Class c)
Register a constructor in the container. Equivalent as registerComponent(key, Components.ctor(c)).

Parameters:
key - the component key.
c - the class containing the constructor.

registerConstructor

void registerConstructor(java.lang.Class c,
                         java.lang.Class[] param_types)
Register a constructor in the container. Equivalent as registerConstructor(c, c, param_types).

Parameters:
c - the class containing the constructor.
param_types - the parameter types of the constructor.

registerConstructor

void registerConstructor(java.lang.Object key,
                         java.lang.Class c,
                         java.lang.Class[] param_types)
Register a constructor in the container. Equivalent as registerComponent(key, Components.ctor(c, param_types)).

Parameters:
key - the component key.
c - the class containing the constructor.
param_types - the parameter types of the constructor.

registerStaticMethod

void registerStaticMethod(java.lang.Class c,
                          java.lang.String name)
Register a component that uses a static method to create component instance. Equivalent as registerComponent(Components.static_method(c, name)).

Parameters:
c - the class containing the static method.
name - the method name.

registerStaticMethod

void registerStaticMethod(java.lang.Object key,
                          java.lang.Class c,
                          java.lang.String name)
Register a component that uses a static method to create component instance. Equivalent as registerComponent(key, Components.static_method(c, name)).

Parameters:
key - the component key.
c - the class containing the static method.
name - the method name.

registerStaticMethod

void registerStaticMethod(java.lang.Class c,
                          java.lang.String name,
                          java.lang.Class[] param_types)
Register a component that uses a static method to create component instance. Equivalent as registerComponent(Components.static_method(c, name, param_types));

Parameters:
c - the class containing the static method.
name - the method name.

registerStaticMethod

void registerStaticMethod(java.lang.Object key,
                          java.lang.Class c,
                          java.lang.String name,
                          java.lang.Class[] param_types)
Register a component that uses a static method to create component instance. Equivalent as registerComponent(key, Components.static_method(c, name, param_types)).

Parameters:
key - the component key.
c - the class containing the static method.
name - the method name.
param_types - the parameter types.

inherit

Container inherit(Registrar parent)
Create a new Container object which represents "this inherits parent" relationship. In this new Container, components in the child container are invisible to the ones in the parent container; while components in the parent container are visible to the ones in the child container.

Parameters:
parent - the parent registrar.
Returns:
the new Container.