org.apache.felix.ipojo.util
Class Property

java.lang.Object
  extended by org.apache.felix.ipojo.util.Property
All Implemented Interfaces:
FieldInterceptor

public class Property
extends java.lang.Object
implements FieldInterceptor

Property class managing a property. This class allows storing property value and calling setter method too.

Author:
Felix Project Team

Constructor Summary
Property(java.lang.String name, java.lang.String field, java.lang.String method, java.lang.String value, java.lang.String type, InstanceManager manager, Handler handler)
          Configurable Property Constructor.
 
Method Summary
static java.lang.Class computeType(java.lang.String type, org.osgi.framework.BundleContext context)
          The set type method computes and returns the property type according to the given type name.
static java.lang.Object create(java.lang.Class type, java.lang.String strValue)
          Create an object of the given type with the given String value.
static java.lang.Object createArrayObject(java.lang.Class interntype, java.lang.String[] values)
          Create an array object containing the type 'interntype' from the String array 'values'.
 java.lang.String getField()
           
 java.lang.String getMethod()
          Get method name, null if no method.
 java.lang.String getName()
           
 java.lang.Object getValue()
           
 boolean hasField()
          Check if the property has a field.
 boolean hasMethod()
          Check if the property has a method callback.
 void invoke(java.lang.Object instance)
          Invoke the setter method on the given pjo object.
static boolean isAssignable(java.lang.Class type, java.lang.Object value)
          Test if the given value is assignable to the given type.
 java.lang.Object onGet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)
          A field value is required by the object 'pojo'.
 void onSet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)
          The field 'field' receives a new value.
 void setValue(java.lang.Object value)
          Fix the value of the property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Property

public Property(java.lang.String name,
                java.lang.String field,
                java.lang.String method,
                java.lang.String value,
                java.lang.String type,
                InstanceManager manager,
                Handler handler)
         throws ConfigurationException
Configurable Property Constructor. At least the method or the field need to be referenced.

Parameters:
name - : name of the property (optional)
field - : name of the field
method - : method name
value - : initial value of the property (optional)
type - : the type of the property
manager - : instance manager
handler - : handler object which manage this property.
Throws:
ConfigurationException - : occurs when the property value cannot be set.
Method Detail

computeType

public static java.lang.Class computeType(java.lang.String type,
                                          org.osgi.framework.BundleContext context)
                                   throws ConfigurationException
The set type method computes and returns the property type according to the given type name.

Parameters:
type - : the type name
context - : bundle context (used to load classes)
Returns:
the class of the given type
Throws:
ConfigurationException - if an error occurs when loading the type class for non-primitive types.

getName

public java.lang.String getName()

getField

public java.lang.String getField()

getMethod

public java.lang.String getMethod()
Get method name, null if no method.

Returns:
the method name.

hasMethod

public boolean hasMethod()
Check if the property has a method callback.

Returns:
true if the property has a method.

hasField

public boolean hasField()
Check if the property has a field.

Returns:
true if the property has a field.

getValue

public java.lang.Object getValue()

setValue

public void setValue(java.lang.Object value)
Fix the value of the property.

Parameters:
value - : the new value.

isAssignable

public static boolean isAssignable(java.lang.Class type,
                                   java.lang.Object value)
Test if the given value is assignable to the given type.

Parameters:
type - : class of the type
value - : object to check
Returns:
true if the object is assignable in the property of type 'type'.

create

public static java.lang.Object create(java.lang.Class type,
                                      java.lang.String strValue)
                               throws ConfigurationException
Create an object of the given type with the given String value.

Parameters:
type - : type of the returned object
strValue - : String value.
Returns:
the object of type 'type' created from the String 'value'
Throws:
ConfigurationException - occurs when the object cannot be created.

createArrayObject

public static java.lang.Object createArrayObject(java.lang.Class interntype,
                                                 java.lang.String[] values)
                                          throws ConfigurationException
Create an array object containing the type 'interntype' from the String array 'values'.

Parameters:
interntype - : internal type of the array.
values - : String array
Returns:
the array containing objects created from the 'values' array
Throws:
ConfigurationException - occurs when the array cannot be created correctly

invoke

public void invoke(java.lang.Object instance)
Invoke the setter method on the given pjo object. If no specified pojo object, will call on each created pojo object.

Parameters:
instance - : the created object (could be null
See Also:
org.apache.felix.ipojo.Handler#onCreation(java.lang.Object)

onGet

public java.lang.Object onGet(java.lang.Object pojo,
                              java.lang.String fieldName,
                              java.lang.Object value)
A field value is required by the object 'pojo'.

Specified by:
onGet in interface FieldInterceptor
Parameters:
pojo - : POJO object
fieldName - : field
value - : last value
Returns:
the value if the handler want to inject this value.
See Also:
FieldInterceptor.onGet(java.lang.Object, java.lang.String, java.lang.Object)

onSet

public void onSet(java.lang.Object pojo,
                  java.lang.String fieldName,
                  java.lang.Object value)
The field 'field' receives a new value.

Specified by:
onSet in interface FieldInterceptor
Parameters:
pojo - : pojo
fieldName - : field name
value - : new value
See Also:
FieldInterceptor.onSet(java.lang.Object, java.lang.String, java.lang.Object)