com.planetalia.dynject.injection
Class Shell

java.lang.Object
  extended by com.planetalia.dynject.injection.Shell

public class Shell
extends java.lang.Object

The Shell class represents the processed configuration for all annotated fields and methods of a class whose instances will be subject to injection/validation. Usually all instances of a class share the same shell to avoid processing delays and memory impact

Author:
Alexander Hristov

Method Summary
 void addProperty(Property property)
          Adds a new property with an empty data path.
static ErrorMap assign(java.lang.Object instance, Environment env, IValueSource valueProvider)
          Convenience method that performs an assignment of a source of values to an instance, making all conversions and validations along the way.
static
<T> ErrorMap
assign(java.lang.Object instance, Environment env, java.util.Map<java.lang.String,T> values)
          Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.
static ErrorMap assign(java.lang.Object instance, IValueSource valueProvider)
          Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.
static
<T> ErrorMap
assign(java.lang.Object instance, java.util.Map<java.lang.String,T> values)
          Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.
static ErrorMap assign(java.lang.Object instance, java.lang.String name, Environment env, java.lang.Object sourceValue)
          Convenience method to assign a value to a single property
static ErrorMap assign(java.lang.Object instance, java.lang.String name, java.lang.Object sourceValue)
          Convenience method to assign a value to a single property
 void dump(java.io.PrintStream out)
          Dumps (for debugging purposes) the configurtion of this shell
 DataPath getClasswideDataPath()
          Returns the data path applicable to all properties of this class
 DataPath getDataPathFor(java.lang.String propertyName)
          Returns the data path of a specific property
 Property getProperty(java.lang.String name)
          Returns the property information associated with a specific property
 java.util.Set<java.lang.String> getPropertyNames()
          Returns the property names registered with this shell
static Shell getShell(java.lang.Class clazz)
          Returns the injection shell for a specified class.
static Shell getShell(java.lang.Object o)
          Returns the injection shell for a specified object.
 ErrorMap performAssignment(boolean setFinalValue, java.lang.Object instance, Environment env, IValueSource valueProvider)
          Peforms an object-wide assignment of all properties.
 ErrorMap performSingleAssignment(java.lang.Object instance, java.lang.String name, Environment env, java.lang.Object sourceValue)
          Performs a single property assignment
static void registerBinder(IClassBinder binder)
          Registers a new extension for the binding process
 void removeProperty(Property property)
          Removes a property from the shell.
 void setClasswideDataPath(DataPath classwideDataPath)
          Sets the data path applicable to all properties of this class
static boolean unregisterBinder(IClassBinder binder)
          Removes a new extension for the binding process
static ErrorMap validate(Environment env, java.lang.Object instance)
          Performs a validation of the data in the current instance
static ErrorMap validate(java.lang.Object instance)
          Performs a validation of the data in the current instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDataPathFor

public DataPath getDataPathFor(java.lang.String propertyName)
Returns the data path of a specific property

Parameters:
propertyName - Property name
Returns:
Data path of that property

addProperty

public void addProperty(Property property)
Adds a new property with an empty data path. Does nothing if the property already exists

Parameters:
property - Property to add

removeProperty

public void removeProperty(Property property)
Removes a property from the shell. Does nothing if the property does not exist

Parameters:
property - Property to be removed

registerBinder

public static void registerBinder(IClassBinder binder)
Registers a new extension for the binding process

Parameters:
binder - Instance that will participate in the binding process

unregisterBinder

public static boolean unregisterBinder(IClassBinder binder)
Removes a new extension for the binding process

Parameters:
binder - Instance that will be removed binding process
Returns:
true if the object was removed, false if it was not present

dump

public void dump(java.io.PrintStream out)
Dumps (for debugging purposes) the configurtion of this shell

Parameters:
out - Stream where to dump the shell

performAssignment

public ErrorMap performAssignment(boolean setFinalValue,
                                  java.lang.Object instance,
                                  Environment env,
                                  IValueSource valueProvider)
Peforms an object-wide assignment of all properties.

Parameters:
setFinalValue - Specifies whether to assign the final values resulting from the datapath to the properties (if set to true), or whether only to perform validation of the values and nothing more (if set to false)
instance - Instace holding the properties to assign
env - Environment
valueProvider - Provider of property values
Returns:
Map of errors that occurred during the assignment.

performSingleAssignment

public ErrorMap performSingleAssignment(java.lang.Object instance,
                                        java.lang.String name,
                                        Environment env,
                                        java.lang.Object sourceValue)
Performs a single property assignment

Parameters:
instance - Instance holding the property
name - Name of the property to assign
env - Environment
sourceValue - Value to assign
Returns:
Map of errors that occurred during the assignment.

getShell

public static Shell getShell(java.lang.Class clazz)
Returns the injection shell for a specified class. If no such shell exists, one is created.

Parameters:
clazz - The class for which to fetch the injection shell. It must be non-null.
Returns:
Injection shell. Guaranteed to be non-null.

getShell

public static Shell getShell(java.lang.Object o)
Returns the injection shell for a specified object. If no such shell exists, one is created.

Parameters:
o - The object for which to fetch the injection shell. It must be non-null.
Returns:
Injection shell. Guaranteed to be non-null.

assign

public static ErrorMap assign(java.lang.Object instance,
                              Environment env,
                              IValueSource valueProvider)
Convenience method that performs an assignment of a source of values to an instance, making all conversions and validations along the way.

Parameters:
instance - Instance to assign the values to.
env - Environment to use
valueProvider - Provider of property values
Returns:
Map of errors that occurred during the assignment.

assign

public static <T> ErrorMap assign(java.lang.Object instance,
                                  Environment env,
                                  java.util.Map<java.lang.String,T> values)
Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.

Type Parameters:
T - Type of the properties that will be provided by the map source
Parameters:
instance - Instance to assign the values to.
env - Environment to use
values - Map containing the values of the properties
Returns:
Map of errors that occurred during the assignment.

assign

public static ErrorMap assign(java.lang.Object instance,
                              IValueSource valueProvider)
Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.

Parameters:
instance - Instance to assign the values to.
valueProvider - Provider of property values
Returns:
Map of errors that occurred during the assignment.

assign

public static <T> ErrorMap assign(java.lang.Object instance,
                                  java.util.Map<java.lang.String,T> values)
Convenience method that performs an assignment of a map of values to an instance, making all conversions and validations along the way.

Type Parameters:
T - Type of the properties that will be provided by the map source
Parameters:
instance - Instance to assign the values to.
values - Map containing the values of the properties
Returns:
Map of errors that occurred during the assignment.

assign

public static ErrorMap assign(java.lang.Object instance,
                              java.lang.String name,
                              Environment env,
                              java.lang.Object sourceValue)
Convenience method to assign a value to a single property

Parameters:
instance - Instance holding the property
name - Property name
env - Environment to use
sourceValue - Value to assign
Returns:
Map of errors that ocurred during the assignment

assign

public static ErrorMap assign(java.lang.Object instance,
                              java.lang.String name,
                              java.lang.Object sourceValue)
Convenience method to assign a value to a single property

Parameters:
instance - Instance holding the property
name - Property name
sourceValue - Value to assign
Returns:
Map of errors that ocurred during the assignment

getClasswideDataPath

public DataPath getClasswideDataPath()
Returns the data path applicable to all properties of this class

Returns:
data path applicable to all properties of this class

setClasswideDataPath

public void setClasswideDataPath(DataPath classwideDataPath)
Sets the data path applicable to all properties of this class

Parameters:
classwideDataPath - data path applicable to all properties of this class

validate

public static ErrorMap validate(java.lang.Object instance)
Performs a validation of the data in the current instance

Parameters:
instance - Instance to validate
Returns:
Map of errors

validate

public static ErrorMap validate(Environment env,
                                java.lang.Object instance)
Performs a validation of the data in the current instance

Parameters:
env - Runtime environment to use
instance - Instance to validate
Returns:
Map of errors

getProperty

public Property getProperty(java.lang.String name)
Returns the property information associated with a specific property

Parameters:
name - Property name
Returns:
Property information, or null if the property does not exist or is not registered in the shell

getPropertyNames

public java.util.Set<java.lang.String> getPropertyNames()
Returns the property names registered with this shell

Returns:
Set of registered property names