org.apache.felix.ipojo.composite.instance
Class InstanceHandler

java.lang.Object
  extended by org.apache.felix.ipojo.Handler
      extended by org.apache.felix.ipojo.composite.CompositeHandler
          extended by org.apache.felix.ipojo.composite.instance.InstanceHandler
All Implemented Interfaces:
InstanceStateListener

public class InstanceHandler
extends CompositeHandler
implements InstanceStateListener

Composite Instance Handler. This handler allows creating an instance inside a composite. This instance is determine by its type and a configuration.

Author:
Felix Project Team

Nested Class Summary
(package private)  class InstanceHandler.ManagedConfiguration
          This structure aims to manage a configuration.
 
Field Summary
private  InstanceHandler.ManagedConfiguration[] m_configurations
          Configurations to create and maintains.
private  InstanceHandlerDescription m_description
          Handler description.
private  Factory[] m_factories
          Available factories.
private  ServiceContext m_scope
          Internal context.
 
Fields inherited from class org.apache.felix.ipojo.composite.CompositeHandler
HANDLER_TYPE
 
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
InstanceHandler()
           
 
Method Summary
 void bindFactory(Factory factory)
          A new valid factory appears.
private  void checkValidity()
          Check handler validity.
 void configure(Element metadata, java.util.Dictionary configuration)
          Configure method.
private  void createInstance(Factory fact, InstanceHandler.ManagedConfiguration config)
          Create an instance using the given factory and the given configuration.
 HandlerDescription getDescription()
          Return the handler description, i.e.
 java.lang.Object getObjectFromInstance(java.lang.String type)
          Method returning an instance object of the given component type.
 java.util.List getUsedType()
          Get the list of used component type.
static java.util.Dictionary parseInstance(Element instance)
          Parse an Element to get a dictionary.
static void parseProperty(Element prop, java.util.Dictionary dict)
          Parse a property.
 void start()
          Start method.
 void stateChanged(ComponentInstance instance, int newState)
          Instance state listener.
 void stop()
          Stop all created instances.
 void unbindFactory(Factory factory)
          An existing factory disappears or becomes invalid.
 
Methods inherited from class org.apache.felix.ipojo.composite.CompositeHandler
attach, getCompositeManager, getHandler, getLogger, setFactory
 
Methods inherited from class org.apache.felix.ipojo.Handler
debug, error, error, getHandlerManager, getValidity, info, initializeComponentFactory, isValid, reconfigure, setValidity, stateChanged, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_scope

private ServiceContext m_scope
Internal context.


m_factories

private Factory[] m_factories
Available factories.


m_description

private InstanceHandlerDescription m_description
Handler description.


m_configurations

private InstanceHandler.ManagedConfiguration[] m_configurations
Configurations to create and maintains.

Constructor Detail

InstanceHandler

public InstanceHandler()
Method Detail

createInstance

private void createInstance(Factory fact,
                            InstanceHandler.ManagedConfiguration config)
Create an instance using the given factory and the given configuration.

Parameters:
fact - : the factory name to used.
config - : the configuration.

bindFactory

public void bindFactory(Factory factory)
A new valid factory appears.

Parameters:
factory - : factory.

unbindFactory

public void unbindFactory(Factory factory)
An existing factory disappears or becomes invalid.

Parameters:
factory - : factory

stop

public void stop()
Stop all created instances.

Specified by:
stop in class Handler

configure

public void configure(Element metadata,
                      java.util.Dictionary configuration)
               throws ConfigurationException
Configure method.

Specified by:
configure in class Handler
Parameters:
metadata - : component type metadata.
configuration - : instance configuration.
Throws:
ConfigurationException - : occurs an instance cannot be parsed correctly.
See Also:
org.apache.felix.ipojo.CompositeHandler#configure(org.apache.felix.ipojo.CompositeManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)

parseInstance

public static java.util.Dictionary parseInstance(Element instance)
                                          throws ParseException
Parse an Element to get a dictionary.

Parameters:
instance - : the Element describing an instance.
Returns:
: the resulting dictionary
Throws:
ParseException - : occurs when a configuration cannot be parse correctly.

parseProperty

public static void parseProperty(Element prop,
                                 java.util.Dictionary dict)
                          throws ParseException
Parse a property.

Parameters:
prop - : the current element to parse
dict - : the dictionary to populate
Throws:
ParseException - : occurs if the property cannot be parsed correctly

start

public void start()
Start method.

Specified by:
start in class Handler
See Also:
org.apache.felix.ipojo.CompositeHandler#start()

checkValidity

private void checkValidity()
Check handler validity. The method update the validaity of the handler.


stateChanged

public void stateChanged(ComponentInstance instance,
                         int newState)
Instance state listener. This method listens when managed instance states change.

Specified by:
stateChanged in interface InstanceStateListener
Parameters:
instance - : instance
newState - : the now state of the given instance
See Also:
InstanceStateListener.stateChanged(org.apache.felix.ipojo.ComponentInstance, int)

getObjectFromInstance

public java.lang.Object getObjectFromInstance(java.lang.String type)
Method returning an instance object of the given component type. This method must be called only on 'primitive' type.

Parameters:
type - : type.
Returns:
an instance object or null if not found.

getDescription

public HandlerDescription getDescription()
Return the handler description, i.e. the state of created instances.

Overrides:
getDescription in class Handler
Returns:
the handler description.
See Also:
org.apache.felix.ipojo.CompositeHandler#getDescription()

getUsedType

public java.util.List getUsedType()
Get the list of used component type.

Returns:
the list containing the used component type


Copyright © 2006-2010 The Apache Software Foundation. All Rights Reserved.