to.etc.iocular.def
Class ComponentBuilder

java.lang.Object
  extended by to.etc.iocular.def.ComponentBuilder

public class ComponentBuilder
extends java.lang.Object

Thingy which helps with building a component definition. This contains all definition-time data related to a single component object.

Author:
Frits Jalvingh Created on Mar 27, 2007

Method Summary
 ComponentBuilder destroy(java.lang.Class<?> wh, java.lang.String methodName)
          Define a "close" or "discard" method on another class for a given object.
 ComponentBuilder destroy(java.lang.String methodName)
          Define a "close" or "discard" method on the instance that was created.
 ComponentBuilder factory(java.lang.Class<?> clz, java.lang.String method)
          A basic object builder defining an object to be returned from a static factory method on a class.
 ComponentBuilder factory(java.lang.String id, java.lang.String method)
          A basic object builder defining an object to be returned from a container object identified by a name, by calling a method on that object.
 ComponentBuilder factoryStart(java.lang.Class<?> clz, java.lang.String methodName, java.lang.Class<?>... arguments)
          Only used for static factories, this allows you to call a static method on whatever static class to get it to initialize.
 ComponentBuilder factoryStart(java.lang.String methodName, java.lang.Class<?>... arguments)
          Only used for static factories, this allows you to call a static method on the container class itself to get it to initialize.
 BasicContainerBuilder getBuilder()
           
 java.lang.String getDefinitionLocation()
           
 java.lang.String getIdent()
           
 BindingScope getScope()
           
 ComponentBuilder implement(java.lang.Class<?> clz)
          Define an explicit type for this class.
 ComponentBuilder name(java.lang.String name)
          When called this adds a name for the component.
 ComponentBuilder parameter(java.lang.Class<?> ptype)
          Create the specified class by getting a parameter that is set, in runtime, when the container is constructed.
 ComponentBuilder scope(BindingScope scope)
          Defines the scope for this object.
 ComponentBuilder setAllProperties()
          This defines that all properties on the instance must be set; it aborts if it cannot find a proper instance for a given property.
 ComponentBuilder setKnownProperties()
          This sets all properties on this components for which a value can be determined.
 ComponentBuilder setProperties(java.lang.String... names)
          Define a set of properties on this component that must be set using default wiring for the properties.
 ComponentBuilder setProperty(java.lang.String name, java.lang.Class<?> componentClass)
          Inject the specified property with the component registered with the specified class.
 ComponentBuilder setProperty(java.lang.String name, java.lang.String componentId)
          Inject the specified property with the component with the given name.
 ComponentBuilder start(java.lang.String methodName, java.lang.Class<?>... arguments)
          Add a start method to an object being retrieved.
 java.lang.String toString()
           
 ComponentBuilder type(java.lang.Class<?> clz)
          Create the specified class using it's constructor, followed by setter injection where needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getDefinitionLocation

public java.lang.String getDefinitionLocation()

getBuilder

public BasicContainerBuilder getBuilder()

type

public ComponentBuilder type(java.lang.Class<?> clz)
Create the specified class using it's constructor, followed by setter injection where needed. This defines a base creation method and so it forbids the other creation methods.


parameter

public ComponentBuilder parameter(java.lang.Class<?> ptype)
Create the specified class by getting a parameter that is set, in runtime, when the container is constructed. This defines the type of the parameter; it can be augmented by a name. The parameter is assumed to be present at runtime. If it is not set the runtime code will abort as soon as the parameter is needed to fulfil a build plan. If a parameter is really unknown at runtime this can be prevented by explicitly assigning null to the container's parameter.

Parameters:
ptype -
Returns:

factory

public ComponentBuilder factory(java.lang.Class<?> clz,
                                java.lang.String method)

A basic object builder defining an object to be returned from a static factory method on a class. The method passed must be resolvable to a static method on the class passed, and it's parameters must be fillable from the container. After this call we'll have a "method" current so the calls to set method parameters work and will define parameters for this method.

This method defines creation so it throws up if another creation method is already defined.

Parameters:
clz -
method -
Returns:

factory

public ComponentBuilder factory(java.lang.String id,
                                java.lang.String method)
A basic object builder defining an object to be returned from a container object identified by a name, by calling a method on that object.

Parameters:
id -
method -
Returns:

name

public ComponentBuilder name(java.lang.String name)
When called this adds a name for the component. A single component can have more than one name, but the name must be unique within the container it gets stored in.

Parameters:
name -

scope

public ComponentBuilder scope(BindingScope scope)
Defines the scope for this object. This defaults to "SINGLETON"

Parameters:
scope -
Returns:

destroy

public ComponentBuilder destroy(java.lang.Class<?> wh,
                                java.lang.String methodName)
Define a "close" or "discard" method on another class for a given object. When added, this adds a method on some class which gets called when the object is being destroyed at container destroy time. Objects are destroyed in the reverse order of creation. This pertains to the actual object (the result of a getObject call). The method being called must have that object or one of it's base classes as parameter. The method passed must be a static method on the specified class currently.

Parameters:
wh -
what -
Returns:

destroy

public ComponentBuilder destroy(java.lang.String methodName)
Define a "close" or "discard" method on the instance that was created. The method must be a non-static method without arguments.

Parameters:
methodName -
Returns:

implement

public ComponentBuilder implement(java.lang.Class<?> clz)
Define an explicit type for this class. This overrides the "actual" type as found by the creation method. Typical use is to define that a creation method should be seen as returning the specified interface, not the actual object type. If the created object implements multiple interfaces you can call this method multiple times, for each interface supported. When used the actual class returned by the creation method must implement this or have this as a base class.

Parameters:
clz -
Returns:

factoryStart

public ComponentBuilder factoryStart(java.lang.String methodName,
                                     java.lang.Class<?>... arguments)
Only used for static factories, this allows you to call a static method on the container class itself to get it to initialize.

Parameters:
methodName -
arguments -
Returns:

factoryStart

public ComponentBuilder factoryStart(java.lang.Class<?> clz,
                                     java.lang.String methodName,
                                     java.lang.Class<?>... arguments)
Only used for static factories, this allows you to call a static method on whatever static class to get it to initialize.

Parameters:
methodName -
arguments -
Returns:

start

public ComponentBuilder start(java.lang.String methodName,
                              java.lang.Class<?>... arguments)
Add a start method to an object being retrieved.

Parameters:
methodName -
arguments -
Returns:

setAllProperties

public ComponentBuilder setAllProperties()
This defines that all properties on the instance must be set; it aborts if it cannot find a proper instance for a given property. This does skip all properties that refer to dumb classes like all primitives and wrappers and String.

Returns:

setKnownProperties

public ComponentBuilder setKnownProperties()
This sets all properties on this components for which a value can be determined. It skips properties with silly types like all primitives and wrappers and String. Properties for which no bound can be found in the container set are not set (they are explicitly not set to null).

Returns:

setProperties

public ComponentBuilder setProperties(java.lang.String... names)
Define a set of properties on this component that must be set using default wiring for the properties. Each property is set by retrieving it's instance from the container set. This works for uniquely-typed properties only.

Parameters:
names -
Returns:

setProperty

public ComponentBuilder setProperty(java.lang.String name,
                                    java.lang.String componentId)
Inject the specified property with the component with the given name. This requires that another component has a name and a type compatibe with the specified type.

Parameters:
name -
componentId -
Returns:

setProperty

public ComponentBuilder setProperty(java.lang.String name,
                                    java.lang.Class<?> componentClass)
Inject the specified property with the component registered with the specified class. This is usually the same as using setProperties() using only the property name, since the property's type should be compatible with the component's type.

Parameters:
name -
componentClass -
Returns:

getIdent

public java.lang.String getIdent()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getScope

public BindingScope getScope()