org.apache.felix.ipojo
Class PrimitiveHandler

java.lang.Object
  extended by org.apache.felix.ipojo.Handler
      extended by org.apache.felix.ipojo.PrimitiveHandler
All Implemented Interfaces:
FieldInterceptor, MethodInterceptor
Direct Known Subclasses:
ArchitectureHandler, ConfigurationHandler, ControllerHandler, DependencyHandler, LifecycleCallbackHandler, ProvidedServiceHandler

public abstract class PrimitiveHandler
extends Handler
implements FieldInterceptor, MethodInterceptor

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
static 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
PrimitiveHandler()
           
 
Method Summary
protected  void attach(ComponentInstance manager)
          Attaches the current handler to the given instance.
 ComponentFactory getFactory()
          Gets the factory which creates the managed instance.
 Handler getHandler(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(Object instance)
          Callback method called when an instance of the component is created, but before someone can use it.
 void onEntry(Object pojo, Method method, Object[] args)
          Callback method called when a method will be invoked.
 void onError(Object pojo, Method method, Throwable throwable)
          Callback method called when an error occurs.
 void onExit(Object pojo, Method method, Object returnedObj)
          Callback method called when a method ends.
 void onFinally(Object pojo, Method method)
          Callback method called when the execution of a method will terminate : just before to throw an exception or before to return.
 Object onGet(Object pojo, String fieldName, Object value)
          Callback method called when a managed field asks for a value.
 void onSet(Object pojo, String fieldName, 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 String HANDLER_TYPE
The "Primitive" Handler type (value).

See Also:
Constant Field Values
Constructor Detail

PrimitiveHandler

public PrimitiveHandler()
Method Detail

attach

protected final void attach(ComponentInstance manager)
Attaches the current handler to the given instance.

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.

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(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(Object pojo,
                  String fieldName,
                  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 Object onGet(Object pojo,
                    String fieldName,
                    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)

onEntry

public void onEntry(Object pojo,
                    Method method,
                    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, Method, Object[])

onExit

public void onExit(Object pojo,
                   Method method,
                   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, Method, Object)

onError

public void onError(Object pojo,
                    Method method,
                    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(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)

onFinally

public void onFinally(Object pojo,
                      Method method)
Callback method called when the execution of a method will terminate : just before to throw an exception or before to return. MethodInterceptor.onExit(Object, Method, Object) or MethodInterceptor.onError(Object, Method, Throwable) were already called. 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(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


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.