felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John E. Conlon" <jcon...@verticon.com>
Subject Re: iPOJO and Configuration Admin Service
Date Wed, 14 Jun 2006 15:03:07 GMT
Hi,


> In fact, at packaging, iPOJO look for the used namespace of your 
> component an import the corresponding packages. Then, at runtime, iPOJO 
> creates an new instance of the needed handler. This handler is managed 
> like the others handlers.

Beautiful! 

So one may declare multiple handlers in the metadata with each having
it's own namespace.

I'll have to think about how I can utilize this with my components.

> I am writing a more completed documentation about this new feature (the 
> actual documentation refers to the 2.5 version).

Please explain in the documentation that one can specify multiple components within
the parent iPOJO metadata element. Couldn't figure it out from the original documentation
but my experiments confirmed it to be so.

cheers,

John



 On Wed, 2006-06-14 at 08:57 +0200, Clement Escoffier wrote:
> Hello,
> 
> > It seems the only way to add handlers is to edit the IPojoConfiguration
> > class and compile them in. 
> >
> > Is there a way for a iPOJO bundle to submit a custom handler to the
> > componentManager at runtime?
> >   
> In fact, this was true for the 2.5 version. But in the 2.6, handlers can 
> be deployed without changing the iPOJO core runtime.
> An handler is a class implementing the Handler interface like the 
> following one (who is a very simple handler) :
> 
> package fr.imag.adele.escoffier.handler.log;
> 
> import org.apache.felix.ipojo.ComponentManager;
> import org.apache.felix.ipojo.Handler;
> import org.apache.felix.ipojo.metadata.Element;
> 
> public class LogHandler implements Handler {   
> 
>     public static final String NAMESPACE = "fr.imag.adele.escoffier.handler.log.LogHandler";
>     private ComponentManager m_manager;
> 
>     public void configure(ComponentManager arg0, Element arg1) {
>         m_manager = arg0;
>         Element log = arg1.getElements("log", NAMESPACE)[0];
>         if(log.getAttribute("enable", NAMESPACE).equals("true")) {arg0.register(this);}
>     }
>     public Object getterCallback(String arg0, Object arg1) { return arg1; }
>     public boolean isValid() { return true; }
>     public void setterCallback(String arg0, Object arg1) {    }
>     public void start() { System.out.println("[LogHandler] Start the LogHandler on "
+ m_manager.getComponentMetatada().getClassName());  }
>     public void stateChanged(int arg0) {
>         String state;
>         if (arg0 == ComponentManager.INVALID) { state = "INVALID"; }
>         else { state = "VALID"; }
>         System.out.println("[LogHandler] State Changes to " + state + " of the component
" + m_manager.getComponentMetatada().getClassName());
>     }
>     public void stop() { System.out.println("[LogHandler] Stop the LogHandler on " +
m_manager.getComponentMetatada().getClassName()); }
> 
> }
> 
> Note that the configure method looks for element of a special namespace. 
> This namespace is the class name of your handler.
> This class is packaged in a bundle exporting the package containing this 
> class.
> 
> Then when a component want use your new handler, the component's 
> description should be something like :
> 
>     <iPOJO xmlns:log="fr.imag.adele.escoffier.handler.log.LogHandler">
>         <component className="fr.imag.adele.escoffier.hello.impl.HelloServiceImpl"
architecture="true">
>            <provides/>
>            <log:log log:enable="true"/>
>         </component>
>     </iPOJO>
> 
> 
> This description declares a namespace (log) pointing on the namespace of 
> your handler (i.e. the handler's class name). Then, the description can 
> contains the log element of the log namespace.
> 
> In fact, at packaging, iPOJO look for the used namespace of your 
> component an import the corresponding packages. Then, at runtime, iPOJO 
> creates an new instance of the needed handler. This handler is managed 
> like the others handlers.
> 
> By using this method, you don't need to change the iPOJOConfiguration 
> class, declaring only "core" handler.
> 
> I am writing a more completed documentation about this new feature (the 
> actual documentation refers to the 2.5 version).
> 
> Clement
> 
> 


Mime
View raw message