|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.yan.containers.SimpleContainer
public class SimpleContainer
A simple implementation of interface Container.
It forwards all method call to the delegated Registrar object,
which makes it handy for customizing a Registrar object by subclassing.
Plus, SimpleContainer implements Container interface,
which provides convenient API's.
In this implementation,
registerStaticMethod and registerConstructor use singleton pattern.
Override these methods or the defaultTransform(Component) method to
disable the singleton or get a different transformation.
| Constructor Summary | |
|---|---|
SimpleContainer(Registrar target)
Create a new SimpleContainer object. |
|
| Method Summary | ||
|---|---|---|
boolean |
containsKey(java.lang.Object key)
Whether a Component with a certain key is contained in the map. |
|
boolean |
containsType(java.lang.Class type)
Whether a Component of a certain type or its sub-type is contained in the map. |
|
protected Component |
defaultTransform(Component comp)
Transforms a component by calling singleton(). |
|
boolean |
equals(java.lang.Object other)
|
|
Component |
getComponent(java.lang.Object key)
Gets a Component identified by a key. |
|
|
getComponentOfType(java.lang.Class<T> type)
Gets a Component object of a certain type. |
|
java.util.Collection |
getComponents()
Gets all components stored in this map. |
|
|
getComponentsOfType(java.lang.Class<T> type)
Gets all component objects that are of a certain type. |
|
java.lang.Class |
getComponentType(java.lang.Object key)
Get the type of a component identified by a key. |
|
protected Registrar |
getDelegateTarget()
Gets the Registrar object being delegated. |
|
Dependency |
getDependency(java.lang.Object key)
Get the dependency for a component key. |
|
Dependency |
getDependency(java.lang.Object key,
ComponentMap cmap)
Gets the Dependency object for a component key. |
|
Dependency |
getDependencyOfType(java.lang.Class type)
Get the dependency for a component type. |
|
Dependency |
getDependencyOfType(java.lang.Class type,
ComponentMap cmap)
Gets the Dependency object for a component instance 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. |
|
|
getFactoryOfType(java.lang.Class<T> type)
Create an instance of Factory for a component of the provided type. |
|
|
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. |
|
|
getInstanceOfType(java.lang.Class<T> type)
Create component instance of the provided type. |
|
|
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. |
|
|
getInstancesOfType(java.lang.Class<T> type)
Create component instances of a provided type. |
|
|
getInstancesOfType(java.lang.Class<T> type,
ComponentMap cmap)
Create component instances of a provided type. |
|
int |
hashCode()
|
|
Container |
inherit(Registrar parent)
Create a new Container object which represents "this inherits parent" relationship. |
|
|
instantiateComponent(Creator<T> cc)
Instantiate component instance. |
|
|
instantiateComponent(Creator<T> cc,
ComponentMap cmap)
|
|
|
instantiateComponent(java.lang.Object key,
Creator<T> cc)
Instantiate component instance. |
|
|
instantiateComponent(java.lang.Object key,
Creator<T> cc,
ComponentMap cmap)
|
|
java.util.Set |
keys()
Get all the component keys. |
|
void |
registerComponent(Component cc)
Register a Component object in the container. |
|
void |
registerComponent(java.lang.Object key,
Component cc)
Register a Component identified by a key. |
|
void |
registerConstructor(java.lang.Class c)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerConstructor(java.lang.Class c,
java.lang.Class[] param_types)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerConstructor(java.lang.Object key,
java.lang.Class c)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerConstructor(java.lang.Object key,
java.lang.Class c,
java.lang.Class[] param_types)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerStaticMethod(java.lang.Class c,
java.lang.String name)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerStaticMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerStaticMethod(java.lang.Object key,
java.lang.Class c,
java.lang.String name)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
void |
registerStaticMethod(java.lang.Object key,
java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
The component is transformed by defaultTransform(Component),
which makes it singleton. |
|
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. |
|
java.lang.String |
toString()
|
|
void |
unregisterComponent(java.lang.Object key)
Unregister a component identified by a key. |
|
void |
unregisterComponentsOfType(java.lang.Class type)
Unregister components of a certain type. |
|
void |
verify()
Verifies the components in this container. |
|
void |
verify(ComponentMap cmap)
Verifies that all the registered components can be satisfied. |
|
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 class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SimpleContainer(Registrar target)
target - the Registrar object.| Method Detail |
|---|
public void registerComponent(java.lang.Object key,
Component cc)
Registrar
registerComponent in interface Registrarkey - the component key.cc - the component.public void registerComponent(Component cc)
Container
registerComponent in interface Containercc - the component.public void unregisterComponent(java.lang.Object key)
Registrar
unregisterComponent in interface Registrarkey - the component key.public void unregisterComponentsOfType(java.lang.Class type)
Registrar
unregisterComponentsOfType in interface Registrartype - the component instance type.public boolean containsKey(java.lang.Object key)
ComponentMap
containsKey in interface ComponentMapkey - the component key.
public boolean containsType(java.lang.Class type)
ComponentMap
containsType in interface ComponentMaptype - the type of the component.
public Component getComponent(java.lang.Object key)
ComponentMap
getComponent in interface ComponentMapkey - the component key.
public <T> Component<T> getComponentOfType(java.lang.Class<T> type)
ComponentMap
getComponentOfType in interface ComponentMaptype - the component instance type.
public <T> java.util.List<Component<T>> getComponentsOfType(java.lang.Class<T> type)
ComponentMap
getComponentsOfType in interface ComponentMaptype - the component instance type.
public <T> T getInstanceOfType(java.lang.Class<T> type,
ComponentMap cmap)
Container
getInstanceOfType in interface Containertype - the type.cmap - the container to resolve dependency.
public <T> java.util.List<T> getInstancesOfType(java.lang.Class<T> type,
ComponentMap cmap)
Container
getInstancesOfType in interface Containertype - the type.cmap - the container to resolve dependency.
public <T> T getInstanceOfType(java.lang.Class<T> type)
Container
getInstanceOfType in interface Containertype - the type.
public <T> java.util.List<T> getInstancesOfType(java.lang.Class<T> type)
Container
getInstancesOfType in interface Containertype - the type.
public Dependency getDependencyOfType(java.lang.Class type,
ComponentMap cmap)
ComponentMap
getDependencyOfType in interface ComponentMaptype - The component instance type.cmap - The ComponentMap object from which the parts of
the component should be obtained.
This parameter is typically passed as 'this' so that the parts are
created in the same container.
When implementing container interaction such as inheritance,
this parameter may be passed as a different ComponentMap object.
public Dependency getDependency(java.lang.Object key,
ComponentMap cmap)
ComponentMap
getDependency in interface ComponentMapkey - The component key.cmap - The ComponentMap object from which the parts of
the component should be obtained.
This parameter is typically passed as 'this' so that the parts are
created in the same container.
When implementing container interaction such as inheritance,
this parameter may be passed as a different ComponentMap object.
public Dependency getDependency(java.lang.Object key)
Container
getDependency in interface Containerkey - the component key.
public Dependency getDependencyOfType(java.lang.Class type)
Container
getDependencyOfType in interface Containertype - the component type.
public void verify(ComponentMap cmap)
Registrar
verify in interface Registrarcmap - the ComponentMap from which
the parts of the registered components are obtained.public void verify()
Container
verify in interface Containerpublic java.lang.Class verifyComponent(Component cc)
Container
verifyComponent in interface Containercc - the component to verify.
public java.lang.Class verifyKey(java.lang.Object key)
Container
verifyKey in interface Containerkey - the component key.
public java.lang.Class verifyType(java.lang.Class type)
Container
verifyType in interface Containertype - the component type.
public java.lang.Class getComponentType(java.lang.Object key)
Container
getComponentType in interface Containerkey - the component key.
public <T> T instantiateComponent(Creator<T> cc,
ComponentMap cmap)
throws AmbiguousComponentResolutionException,
ComponentInstantiationException,
CyclicDependencyException,
UnresolvedComponentException,
UnsatisfiedComponentException,
YanException
AmbiguousComponentResolutionException
ComponentInstantiationException
CyclicDependencyException
UnresolvedComponentException
UnsatisfiedComponentException
YanException
public <T> T instantiateComponent(java.lang.Object key,
Creator<T> cc,
ComponentMap cmap)
throws AmbiguousComponentResolutionException,
ComponentInstantiationException,
CyclicDependencyException,
UnresolvedComponentException,
UnsatisfiedComponentException,
YanException
AmbiguousComponentResolutionException
ComponentInstantiationException
CyclicDependencyException
UnresolvedComponentException
UnsatisfiedComponentException
YanException
public <T> T instantiateComponent(Creator<T> cc)
throws AmbiguousComponentResolutionException,
ComponentInstantiationException,
CyclicDependencyException,
UnresolvedComponentException,
UnsatisfiedComponentException,
YanException
Container
instantiateComponent in interface Containercc - the component to instantiate.
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.
public <T> T instantiateComponent(java.lang.Object key,
Creator<T> cc)
throws AmbiguousComponentResolutionException,
ComponentInstantiationException,
CyclicDependencyException,
UnresolvedComponentException,
UnsatisfiedComponentException,
YanException
Container
instantiateComponent in interface Containerkey - the key of the component.cc - the component to instantiate.
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.
public java.lang.Object getInstance(java.lang.Object key,
ComponentMap cmap)
Container
getInstance in interface Containerkey - the component key.cmap - the container to resolve dependency.
public java.lang.Object getInstance(java.lang.Object key)
Container
getInstance in interface Containerkey - the component key.
public void registerValue(java.lang.Object key,
java.lang.Object v)
Container
registerValue in interface Containerkey - the key of the value.v - the value.public void registerValue(java.lang.Object v)
Container
registerValue in interface Containerv - the value.public void registerConstructor(java.lang.Class c)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerConstructor in interface Containerc - the class containing the constructor.protected Component defaultTransform(Component comp)
comp - the component.
public void registerConstructor(java.lang.Object key,
java.lang.Class c)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerConstructor in interface Containerkey - the component key.c - the class containing the constructor.
public void registerConstructor(java.lang.Class c,
java.lang.Class[] param_types)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerConstructor in interface Containerc - the class containing the constructor.param_types - the parameter types of the constructor.
public void registerConstructor(java.lang.Object key,
java.lang.Class c,
java.lang.Class[] param_types)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerConstructor in interface Containerkey - the component key.c - the class containing the constructor.param_types - the parameter types of the constructor.
public void registerStaticMethod(java.lang.Class c,
java.lang.String name)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerStaticMethod in interface Containerc - the class containing the static method.name - the method name.
public void registerStaticMethod(java.lang.Object key,
java.lang.Class c,
java.lang.String name)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerStaticMethod in interface Containerkey - the component key.c - the class containing the static method.name - the method name.
public void registerStaticMethod(java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerStaticMethod in interface Containerc - the class containing the static method.name - the method name.
public void registerStaticMethod(java.lang.Object key,
java.lang.Class c,
java.lang.String name,
java.lang.Class[] param_types)
defaultTransform(Component),
which makes it singleton.
Override defaultTransform(Component) if a different default behavior
is desired.
registerStaticMethod in interface Containerkey - the component key.c - the class containing the static method.name - the method name.param_types - the parameter types.public Container inherit(Registrar parent)
Container
inherit in interface Containerparent - the parent registrar.
public boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Set keys()
ComponentMap
keys in interface ComponentMappublic java.util.Collection getComponents()
ComponentMap
getComponents in interface ComponentMappublic void getInstances(java.util.Map store)
Container
getInstances in interface Containerstore - the java.util.Map object to save the component instances.public java.util.List getInstances()
Container
getInstances in interface Container
public void getInstances(java.util.Map store,
ComponentMap cmap)
ContainerThe dependencies are resolved in the current container.
getInstances in interface Containerstore - the java.util.Map object to save the component instances.cmap - the container in which to resolve dependency.public java.util.List getInstances(ComponentMap cmap)
ContainerThe dependencies are resolved in the current container.
getInstances in interface Containercmap - the container in which to resolve dependency.
public Factory getFactory(java.lang.Object key,
ComponentMap cmap)
throws UnresolvedComponentException,
YanException
ContainerFactory for a component identified by a key.
when Factory.create() is called, the component is instantiated.
getFactory in interface Containerkey - the component key.cmap - the container to resolve dependency.
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.
public Factory getFactory(java.lang.Object key)
throws UnresolvedComponentException,
YanException
ContainerFactory for a component identified by a key.
when Factory.create() is called, the component is instantiated.
getFactory in interface Containerkey - the component key.
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.
public <T> Factory<T> getFactoryOfType(java.lang.Class<T> type,
ComponentMap cmap)
throws AmbiguousComponentResolutionException,
UnresolvedComponentException,
YanException
ContainerFactory for a component of the provided type.
when Factory.create() is called, the component is instantiated.
getFactoryOfType in interface Containertype - the type.cmap - the container to resolve dependency.
AmbiguousComponentResolutionException - if ambiguity happens.
UnresolvedComponentException - if this component cannot be resolved.
YanException - for any other exception.
public <T> Factory<T> getFactoryOfType(java.lang.Class<T> type)
throws AmbiguousComponentResolutionException,
UnresolvedComponentException,
YanException
ContainerFactory for a component of the provided type.
when Factory.create() is called, the component is instantiated.
getFactoryOfType in interface Containertype - the type.
AmbiguousComponentResolutionException - if ambiguity happens.
UnresolvedComponentException - if this component or any dependent component cannot be resolved.
YanException - for any other exception.protected final Registrar getDelegateTarget()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||