org.apache.felix.ipojo.util

## Class Property

- java.lang.Object
- - org.apache.felix.ipojo.util.Property

All Implemented Interfaces:
  ConstructorInjector, FieldInterceptor

    public class Property
    extends java.lang.Object
    implements FieldInterceptor, ConstructorInjector

Property class managing a managed value. This class managed the method invocation, field injection and constructor injection.

Author:
  Felix Project Team

### Field Summary

Fields
`static java.lang.Object` `NO_VALUE` Object used for an unvalued property.
`static java.lang.String` `UNVALUED` String value returned for property without values.

### Constructor Summary

Constructors
Constructor and Description
`Property(java.lang.String name, java.lang.String field, java.lang.String method, int index, java.lang.String value, java.lang.String type, InstanceManager manager, Handler handler)`
`Property(java.lang.String name, java.lang.String field, java.lang.String method, java.lang.Object value, InstanceManager manager, Handler handler)` Creates a property.
`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)` Creates a property.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static java.lang.Class` `computeType(java.lang.String type, org.osgi.framework.BundleContext context)` 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)` Creates an object of the given type with the given String value.
`static java.lang.Object` `createArrayObject(java.lang.Class interntype, java.lang.String[] values)` Creates an array object containing the type component type from the String array 'values'.
`java.lang.Object` `getConstructorParameter(int index)` Gets the object to inject as constructor parameter.
`java.lang.Class` `getConstructorParameterType(int index)` Gets the type of the constructor parameter to inject.
`java.lang.Object` `getDefaultValue()` Gets the initial value of the property.
`java.lang.String` `getField()`
`Handler` `getHandler()` Gets the handler managing the property.
`java.lang.String` `getMethod()` Gets the method name, `null` if no method.
`java.lang.String` `getName()`
`int` `getParameterIndex()` Gets the parameter index.
`java.lang.String` `getType()`
`java.lang.Object` `getValue()`
`boolean` `hasField()` Checks if the property has a field.
`boolean` `hasMethod()` Checks if the property has a method callback.
`void` `invoke(java.lang.Object instance)` Invokes the setter method on the given pojo object.
`static boolean` `isAssignable(java.lang.Class type, java.lang.Object value)` Checks 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` `reset()` Clears the invoked flag.
`void` `setValue(java.lang.Object value)` Sets the value of the property.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NO_VALUE

    public static final java.lang.Object NO_VALUE

Object used for an unvalued property.

#### UNVALUED

    public static final java.lang.String UNVALUED

String value returned for property without values.

See Also:
  Constant Field Values

### 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

Creates a property. At least the method or the field need to be specified.

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

#### Property

    public Property(java.lang.String name,
                    java.lang.String field,
                    java.lang.String method,
                    java.lang.Object value,
                    InstanceManager manager,
                    Handler handler)
             throws ConfigurationException

Creates a property. At least the method or the field need to be specified.

Parameters:
  `name` - the name of the property (optional)
  `field` - the name of the field
  `method` - the method name
  `value` - the initial value of the property (optional)
  `manager` - the instance manager
  `handler` - the handler object which manage this property.
Throws:
  `ConfigurationException` - if the property value cannot be set.

#### Property

    public Property(java.lang.String name,
                    java.lang.String field,
                    java.lang.String method,
                    int index,
                    java.lang.String value,
                    java.lang.String type,
                    InstanceManager manager,
                    Handler handler)
             throws ConfigurationException

Throws:
  `ConfigurationException`

### Method Detail

#### computeType

    public static java.lang.Class computeType(java.lang.String type,
                                              org.osgi.framework.BundleContext context)
                                       throws ConfigurationException

Computes and returns the property type according to the given type name.

Parameters:
  `type` - the the type name
  `context` - the 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()

#### getType

    public java.lang.String getType()

#### getMethod

    public java.lang.String getMethod()

Gets the method name, `null` if no method.

Returns:
  the method name.

#### hasMethod

    public boolean hasMethod()

Checks if the property has a method callback.

Returns:
  `true` if the property has a method.

#### getParameterIndex

    public int getParameterIndex()

Gets the parameter index.

Returns:
  the parameter index or `-1` if this property is not injected using constructor parameter.

#### hasField

    public boolean hasField()

Checks if the property has a field.

Returns:
  `true` if the property has a field.

#### getValue

    public java.lang.Object getValue()

#### getDefaultValue

    public java.lang.Object getDefaultValue()

Gets the initial value of the property.

Returns:
  the default value.

#### setValue

    public void setValue(java.lang.Object value)

Sets the value of the property.

Parameters:
  `value` - the new value.

#### isAssignable

    public static boolean isAssignable(java.lang.Class type,
                                       java.lang.Object value)

Checks if the given value is assignable to the given type.

Parameters:
  `type` - the class of the type
  `value` - the 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

Creates an object of the given type with the given String value.

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

#### createArrayObject

    public static java.lang.Object createArrayObject(java.lang.Class interntype,
                                                     java.lang.String[] values)
                                              throws ConfigurationException

Creates an array object containing the type component type from the String array 'values'.

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

#### reset

    public void reset()

Clears the invoked flag. Then, despite the setter was already called, it will be invoked another times.

#### invoke

    public void invoke(java.lang.Object instance)

Invokes the setter method on the given pojo object. If no specified pojo object, it calls on each created pojo object.

Parameters:
  `instance` - the created object (could be `null`)

#### 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` - the POJO object
  `fieldName` - the field
  `value` - the 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` - the pojo
  `fieldName` - the field name
  `value` - the new value
See Also:
  `FieldInterceptor.onSet(java.lang.Object, java.lang.String, java.lang.Object)`

#### getConstructorParameter

    public java.lang.Object getConstructorParameter(int index)

Gets the object to inject as constructor parameter.

Specified by:
  `getConstructorParameter` in interface `ConstructorInjector`
Parameters:
  `index` - the constructor parameter index
Returns:
  the object to inject, so the property value.
See Also:
  `ConstructorInjector.getConstructorParameter(int)`

#### getConstructorParameterType

    public java.lang.Class getConstructorParameterType(int index)

Gets the type of the constructor parameter to inject.

Specified by:
  `getConstructorParameterType` in interface `ConstructorInjector`
Parameters:
  `index` - the parameter index
Returns:
  the Class of the property.
See Also:
  `ConstructorInjector.getConstructorParameterType(int)`

#### getHandler

    public Handler getHandler()

Gets the handler managing the property.

Returns:
  the configuration handler.