org.jboss.jca.core.util
Class Injection

java.lang.Object
  extended by org.jboss.jca.core.util.Injection

public class Injection
extends Object

Injection utility which can inject values into objects. This file is a copy of the com.github.fungal.api.util.Injection class.

Author:
Jesper Pedersen

Constructor Summary
Injection()
          Constructor
 
Method Summary
protected  Field findField(Class<?> clz, String fieldName, String fieldType)
          Find a field
protected  Method findMethod(Class<?> clz, String methodName, String propertyType)
          Find a method
protected  String getSubstitutionValue(String input)
          System property substitution
protected  Object getValue(String name, Class<?> clz, Object v, ClassLoader cl)
          Get the value
 void inject(Object object, String propertyName, Object propertyValue)
          Inject a value into an object property
 void inject(Object object, String propertyName, Object propertyValue, String propertyType)
          Inject a value into an object property
 void inject(Object object, String propertyName, Object propertyValue, String propertyType, boolean includeFields)
          Inject a value into an object property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Injection

public Injection()
Constructor

Method Detail

inject

public void inject(Object object,
                   String propertyName,
                   Object propertyValue)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   InvocationTargetException
Inject a value into an object property

Parameters:
object - The object
propertyName - The property name
propertyValue - The property value
Throws:
NoSuchMethodException - If the property method cannot be found
IllegalAccessException - If the property method cannot be accessed
InvocationTargetException - If the property method cannot be executed

inject

public void inject(Object object,
                   String propertyName,
                   Object propertyValue,
                   String propertyType)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   InvocationTargetException
Inject a value into an object property

Parameters:
object - The object
propertyName - The property name
propertyValue - The property value
propertyType - The property type as a fully quilified class name
Throws:
NoSuchMethodException - If the property method cannot be found
IllegalAccessException - If the property method cannot be accessed
InvocationTargetException - If the property method cannot be executed

inject

public void inject(Object object,
                   String propertyName,
                   Object propertyValue,
                   String propertyType,
                   boolean includeFields)
            throws NoSuchMethodException,
                   IllegalAccessException,
                   InvocationTargetException
Inject a value into an object property

Parameters:
object - The object
propertyName - The property name
propertyValue - The property value
propertyType - The property type as a fully quilified class name
includeFields - Should fields be included for injection if a method can't be found
Throws:
NoSuchMethodException - If the property method cannot be found
IllegalAccessException - If the property method cannot be accessed
InvocationTargetException - If the property method cannot be executed

findMethod

protected Method findMethod(Class<?> clz,
                            String methodName,
                            String propertyType)
Find a method

Parameters:
clz - The class
methodName - The method name
propertyType - The property type; can be null
Returns:
The method; null if not found

findField

protected Field findField(Class<?> clz,
                          String fieldName,
                          String fieldType)
Find a field

Parameters:
clz - The class
fieldName - The field name
fieldType - The field type; can be null
Returns:
The field; null if not found

getValue

protected Object getValue(String name,
                          Class<?> clz,
                          Object v,
                          ClassLoader cl)
                   throws Exception
Get the value

Parameters:
name - The value name
clz - The value class
v - The value
cl - The class loader
Returns:
The substituted value
Throws:
Exception - Thrown in case of an error

getSubstitutionValue

protected String getSubstitutionValue(String input)
System property substitution

Parameters:
input - The input string
Returns:
The output


Copyright © 2008 Red Hat Middleware LLC (http://www.jboss.com/)