org.apache.felix.ipojo

## Class PrimitiveHandler

- java.lang.Object
- - org.apache.felix.ipojo.Handler
  - - org.apache.felix.ipojo.PrimitiveHandler

All Implemented Interfaces:
  ConstructorInjector, FieldInterceptor, MethodInterceptor

Direct Known Subclasses:
  ArchitectureHandler, BundleContextHandler, ConfigurationHandler, ControllerHandler, DependencyHandler, LifecycleCallbackHandler, ProvidedServiceHandler

    public abstract class PrimitiveHandler
    extends Handler
    implements FieldInterceptor, MethodInterceptor, ConstructorInjector

This class defines common mechanisms of primitive handlers. Primitive handlers are handler composing the container of primitive component instances (declared by the 'component' element inside the iPOJO descriptor). Note that this class also defines default method implementation. Classes overriding this class can change the behavior of those methods.

Author:
  Felix Project Team

### Field Summary

Fields
`static java.lang.String` `HANDLER_TYPE` The "Primitive" Handler type (value).

### Fields inherited from class org.apache.felix.ipojo.Handler

`HANDLER_LEVEL_PROPERTY, HANDLER_NAME_PROPERTY, HANDLER_NAMESPACE_PROPERTY, HANDLER_TYPE_PROPERTY, m_instance, m_isValid`

### Constructor Summary

Constructors
Constructor and Description
`PrimitiveHandler()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `attach(ComponentInstance manager)` Attaches the current handler to the given instance.
`java.lang.Object` `getConstructorParameter(int index)` Gets the object to inject as a constructor parameter
`java.lang.Class` `getConstructorParameterType(int index)` Gets the type of the object to inject in the constructor parameter.
`ComponentFactory` `getFactory()` Gets the factory which creates the managed instance.
`Handler` `getHandler(java.lang.String name)` Gets a plugged handler of the same container.
`InstanceManager` `getInstanceManager()` Gets the instance manager managing the instance.
`Logger` `getLogger()` Gets the logger of the managed instance.
`PojoMetadata` `getPojoMetadata()` Gets the PojoMetadata of the content of the managed instance.
`void` `onCreation(java.lang.Object instance)` Callback method called when an instance of the component is created, but before someone can use it.
`void` `onEntry(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Object[] args)` Callback method called when a method will be invoked.
`void` `onError(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Throwable throwable)` Callback method called when an error occurs.
`void` `onExit(java.lang.Object pojo, java.lang.reflect.Member method, java.lang.Object returnedObj)` Callback method called when a method ends.
`void` `onFinally(java.lang.Object pojo, java.lang.reflect.Member method)` Callback method called when the execution of a method will terminate : just before to throw an exception or before to return.
`java.lang.Object` `onGet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)` Callback method called when a managed field asks for a value.
`void` `onSet(java.lang.Object pojo, java.lang.String fieldName, java.lang.Object value)` Callback method called when a managed field receives a new value.
`void` `setFactory(Factory factory)` Sets the factory of the managed instance.

### Methods inherited from class org.apache.felix.ipojo.Handler

`configure, debug, error, error, getDescription, getHandlerManager, getValidity, info, initializeComponentFactory, isValid, reconfigure, setValidity, start, stateChanged, stop, warn, warn`

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

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

### Field Detail

#### HANDLER_TYPE

    public static final java.lang.String HANDLER_TYPE

The "Primitive" Handler type (value).

See Also:
  Constant Field Values

### Constructor Detail

#### PrimitiveHandler

    public PrimitiveHandler()

### Method Detail

#### attach

    protected void attach(ComponentInstance manager)

Attaches the current handler to the given instance. This method must be called only once, and should not be overridden.

Specified by:
  `attach` in class `Handler`
Parameters:
  `manager` - the instance on which the current handler will be attached.
See Also:
  `Handler.attach(org.apache.felix.ipojo.ComponentInstance)`

#### setFactory

    public final void setFactory(Factory factory)

Sets the factory of the managed instance.

Specified by:
  `setFactory` in class `Handler`
Parameters:
  `factory` - the factory
See Also:
  `Handler.setFactory(org.apache.felix.ipojo.Factory)`

#### getLogger

    public Logger getLogger()

Gets the logger of the managed instance. IF no instance attached yet, use the factory logger.

Specified by:
  `getLogger` in class `Handler`
Returns:
  the logger to use to log messages.
See Also:
  `Handler.getLogger()`

#### getInstanceManager

    public InstanceManager getInstanceManager()

Gets the instance manager managing the instance.

Returns:
  the instance manager

#### getFactory

    public ComponentFactory getFactory()

Gets the factory which creates the managed instance.

Returns:
  the factory which creates the managed instance.

#### getPojoMetadata

    public PojoMetadata getPojoMetadata()

Gets the PojoMetadata of the content of the managed instance. This method allows getting manipulation metadata.

Returns:
  the information about the content of the managed instance.

#### getHandler

    public final Handler getHandler(java.lang.String name)

Gets a plugged handler of the same container. This method must be called only in the start method (or after). In the configure method, this method can be inconsistent as all handlers are not initialized.

Specified by:
  `getHandler` in class `Handler`
Parameters:
  `name` - the name of the handler to find (class name or qualified handler name (`ns:name`)).
Returns:
  the handler object or `null` if the handler is not found.

#### onSet

    public void onSet(java.lang.Object pojo,
                      java.lang.String fieldName,
                      java.lang.Object value)

Callback method called when a managed field receives a new value. The given pojo can be null if the new value is set by another handler. This default implementation does nothing.

Specified by:
  `onSet` in interface `FieldInterceptor`
Parameters:
  `pojo` - the pojo object setting the value
  `fieldName` - the field name
  `value` - the value received by the field
See Also:
  `FieldInterceptor.onSet(Object, String, Object)`

#### onGet

    public java.lang.Object onGet(java.lang.Object pojo,
                                  java.lang.String fieldName,
                                  java.lang.Object value)

Callback method called when a managed field asks for a value. The default implementation returned the previously injected value.

Specified by:
  `onGet` in interface `FieldInterceptor`
Parameters:
  `pojo` - the pojo object requiring the value
  `fieldName` - the field name
  `value` - the value passed to the field (by the previous call)
Returns:
  the value to inject, of the previous value if the handler don't want to inject a value.
See Also:
  `FieldInterceptor.onGet(Object, String, Object)`

#### getConstructorParameter

    public java.lang.Object getConstructorParameter(int index)

Gets the object to inject as a constructor parameter

Specified by:
  `getConstructorParameter` in interface `ConstructorInjector`
Parameters:
  `index` - the index of the parameter
Returns:
  the object to inject, or `null` if no objects are injected. This implementation returns `null`
See Also:
  `ConstructorInjector.getConstructorParameter(int)`

#### getConstructorParameterType

    public java.lang.Class getConstructorParameterType(int index)

Gets the type of the object to inject in the constructor parameter. This is the type looked into the Pojo class, so it must match. Returning `null` will try to get the class from the injected object, however this can be wrong (implementation instead of interface, boxed objects...) and error-prone.

Specified by:
  `getConstructorParameterType` in interface `ConstructorInjector`
Parameters:
  `index` - the parameter index
Returns:
  the Class object (must fit for primitive type), this implementation just returns `null`
See Also:
  `ConstructorInjector.getConstructorParameterType(int)`

#### onEntry

    public void onEntry(java.lang.Object pojo,
                        java.lang.reflect.Member method,
                        java.lang.Object[] args)

Callback method called when a method will be invoked. This default implementation does nothing.

Specified by:
  `onEntry` in interface `MethodInterceptor`
Parameters:
  `pojo` - the pojo on which the method is called.
  `method` - the method invoked.
  `args` - the arguments array.
See Also:
  `MethodInterceptor.onEntry(Object, java.lang.reflect.Member, Object[])`

#### onExit

    public void onExit(java.lang.Object pojo,
                       java.lang.reflect.Member method,
                       java.lang.Object returnedObj)

Callback method called when a method ends. This method is called when a thread exits a method (before a return or a throw). If the given returned object is `null`, either the method is `void`, or it returns `null`. You must not modified the returned object. The default implementation does nothing.

Specified by:
  `onExit` in interface `MethodInterceptor`
Parameters:
  `pojo` - the pojo on which the method exits.
  `method` - the exiting method.
  `returnedObj` - the returned object (boxed for primitive type)
See Also:
  `MethodInterceptor.onExit(Object, java.lang.reflect.Member, Object)`

#### onError

    public void onError(java.lang.Object pojo,
                        java.lang.reflect.Member method,
                        java.lang.Throwable throwable)

Callback method called when an error occurs. This method is called when the execution throws an exception in the given method. The default implementation does nothing.

Specified by:
  `onError` in interface `MethodInterceptor`
Parameters:
  `pojo` - the pojo on which the method was accessed.
  `method` - the invoked method.
  `throwable` - the thrown exception
See Also:
  `MethodInterceptor.onError(Object, java.lang.reflect.Member, Throwable)`

#### onFinally

    public void onFinally(java.lang.Object pojo,
                          java.lang.reflect.Member method)

Callback method called when the execution of a method will terminate : just before to throw an exception or before to return. This callback is called after `MethodInterceptor.onExit(Object, java.lang.reflect.Member, Object)` and `MethodInterceptor.onError(Object, java.lang.reflect.Member, Throwable)` This default implementation does nothing.

Specified by:
  `onFinally` in interface `MethodInterceptor`
Parameters:
  `pojo` - the pojo on which the method was accessed.
  `method` - the invoked method.

#### onCreation

    public void onCreation(java.lang.Object instance)

Callback method called when an instance of the component is created, but before someone can use it. The default implementation does nothing.

Parameters:
  `instance` - the created instance