org.apache.felix.ipojo
Class Handler

java.lang.Object
  extended by org.apache.felix.ipojo.Handler
Direct Known Subclasses:
PrimitiveHandler

public abstract class Handler
extends Object

Handler Abstract Class. A handler is a 'piece' of

Author:
Felix Project Team

Field Summary
static String HANDLER_LEVEL_PROPERTY
          The handler priority.
static String HANDLER_NAME_PROPERTY
          The handler name property.
static String HANDLER_NAMESPACE_PROPERTY
          The handler namespace property.
static String HANDLER_TYPE_PROPERTY
          The handler type property.
protected  HandlerManager m_instance
          The HandlerManager managing the current handler.
protected  boolean m_isValid
          The current handler validity.
 
Constructor Summary
Handler()
           
 
Method Summary
protected abstract  void attach(ComponentInstance instance)
          Attaches the current handler object to the given component instance.
abstract  void configure(Element metadata, Dictionary configuration)
          Configures the handler.
 void debug(String message)
          Log method (debug).
 void error(String message)
          Log method (error).
 void error(String message, Throwable exception)
          Log method (error).
 HandlerDescription getDescription()
          Returns the current handler description.
abstract  Handler getHandler(String name)
          Get a plugged handler of the same container.
 HandlerManager getHandlerManager()
          Gets the component instance of the current handler.
abstract  Logger getLogger()
          Gets the logger to use in the handler.
 boolean getValidity()
          Is the current handler valid.
 void info(String message)
          Log method (info).
 void initializeComponentFactory(ComponentTypeDescription typeDesc, Element metadata)
          Initializes the component factory.
 boolean isValid()
          Checks if the current handler is valid.
 void reconfigure(Dictionary configuration)
          Reconfigures the instance.
abstract  void setFactory(Factory factory)
          Sets the factory attached to this handler object.
 void setValidity(boolean isValid)
          Sets the validity of the current handler.
abstract  void start()
          Starts the handler This method starts the management.
 void stateChanged(int state)
          This method is called when the component state changed.
abstract  void stop()
          Stops the handler This method stops the management.
 void warn(String message)
          Log method (warning).
 void warn(String message, Throwable exception)
          Log method (warning).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HANDLER_NAMESPACE_PROPERTY

public static final String HANDLER_NAMESPACE_PROPERTY
The handler namespace property.

See Also:
Constant Field Values

HANDLER_NAME_PROPERTY

public static final String HANDLER_NAME_PROPERTY
The handler name property.

See Also:
Constant Field Values

HANDLER_TYPE_PROPERTY

public static final String HANDLER_TYPE_PROPERTY
The handler type property.

See Also:
Constant Field Values

HANDLER_LEVEL_PROPERTY

public static final String HANDLER_LEVEL_PROPERTY
The handler priority.

See Also:
Constant Field Values

m_isValid

protected boolean m_isValid
The current handler validity. This impacts directly the instance state.


m_instance

protected HandlerManager m_instance
The HandlerManager managing the current handler.

Constructor Detail

Handler

public Handler()
Method Detail

setFactory

public abstract void setFactory(Factory factory)
Sets the factory attached to this handler object. This method must be override to depend on each component factory type.

Parameters:
factory - the factory to attach.

getLogger

public abstract Logger getLogger()
Gets the logger to use in the handler. This method must be override to depend on each component factory type logging policy.

Returns:
the logger.

warn

public final void warn(String message)
Log method (warning). Log a warning message to the handler logger.

Parameters:
message - the message to log

error

public final void error(String message)
Log method (error). Log an error message to the handler logger.

Parameters:
message - the message to log

info

public final void info(String message)
Log method (info). Log an info message to the handler logger.

Parameters:
message - the message to log

debug

public final void debug(String message)
Log method (debug). Log a debug message to the handler logger.

Parameters:
message - the message to log

warn

public final void warn(String message,
                       Throwable exception)
Log method (warning). Log a warning message to the handler logger. The message is sent with an attached exception.

Parameters:
message - the message to log
exception - the exception to attach with the message

error

public final void error(String message,
                        Throwable exception)
Log method (error). Log an error message to the handler logger. The message is sent with an attached exception.

Parameters:
message - the message to log
exception - the exception to attach to the message

getHandler

public abstract Handler getHandler(String name)
Get a plugged handler of the same container. This method must be call only in the start method (or after). In the configure method, this method can not return a consistent result as all handlers are not plugged.

Parameters:
name - : 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.

attach

protected abstract void attach(ComponentInstance instance)
Attaches the current handler object to the given component instance. An attached handler becomes a part of the instance container.

Parameters:
instance - the component instance on which the current handler will be attached.

isValid

public final boolean isValid()
Checks if the current handler is valid. This check tests the handler validity. This method must not be override.

Returns:
true if the handler is valid.

setValidity

public final void setValidity(boolean isValid)
Sets the validity of the current handler.

Parameters:
isValid - if true the handler becomes valid, else it becomes invalid.

getValidity

public final boolean getValidity()
Is the current handler valid.

Returns:
true if the handler is valid, false otherwise.

getHandlerManager

public final HandlerManager getHandlerManager()
Gets the component instance of the current handler.

Returns:
the component instance.

initializeComponentFactory

public void initializeComponentFactory(ComponentTypeDescription typeDesc,
                                       Element metadata)
                                throws ConfigurationException
Initializes the component factory. This method aims to collect component factory properties. Each handler wanting to contribute needs to override this method and adds properties to the given component description. By default, this method does nothing.

Parameters:
typeDesc - the component description.
metadata - the component type metadata.
Throws:
ConfigurationException - if the metadata are not correct (early detection).

configure

public abstract void configure(Element metadata,
                               Dictionary configuration)
                        throws ConfigurationException
Configures the handler.

Parameters:
metadata - the metadata of the component
configuration - the instance configuration
Throws:
ConfigurationException - if the metadata are not correct.

stop

public abstract void stop()
Stops the handler This method stops the management.


start

public abstract void start()
Starts the handler This method starts the management.


stateChanged

public void stateChanged(int state)
This method is called when the component state changed. By default, this method does nothing.

Parameters:
state - the new instance state ComponentInstance

getDescription

public HandlerDescription getDescription()
Returns the current handler description. The simplest description contains only the name and the validity of the handler. If the handler override this method, it can customize the description. By default, this method returns the simplest description.

Returns:
the description of the handler.

reconfigure

public void reconfigure(Dictionary configuration)
Reconfigures the instance. This method is called, when the instance is under reconfiguration. The reconfiguration does not stops the instance, and so the handler supporting the reconfiguration must override this method and handles this case. By default, this method does nothing.

Parameters:
configuration - the new instance configuration.


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