felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > iPOJO FAQ
Date Wed, 25 May 2011 14:27:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ">iPOJO FAQ</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~heavy@ungoverned.org">Richard S. Hall</a>
    </h4>
        <br/>
                         <h4>Changes (10)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{html} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">h1.<span class="diff-added-chars"style="background-color: #dfd;"> </span>Apache</span> Felix iPOJO FAQ <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{div:class=toc} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Callbacks order. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;"> <br></td></tr>
            <tr><td class="diff-unchanged" >A lot of handlers define callbacks to notify the implementation class. The &#39;core&#39; callbacks are called in the following order: <br>{code:java} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h2. Disabling proxies in iPOJO <span class="diff-changed-words">1.6<span class="diff-added-chars"style="background-color: #dfd;">\</span>+</span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;"> <br></td></tr>
            <tr><td class="diff-unchanged" >iPOJO 1.6.0 has generalized the proxy usage. However this mechanism can be disabled. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >To disable the proxies on the entire framework, just set the property {{ipojo.proxy}} to {{disabled}} (this set the default &#39;proxy&#39; value). This property is either a system property <span class="diff-changed-words">({{<span class="diff-added-chars"style="background-color: #dfd;">\</span>-Dipojo.proxy=disabled}}</span> in the command line) or a framework property (given to the framework during its initialization). <br></td></tr>
            <tr><td class="diff-unchanged" > <br>You can also disable proxies for specific dependencies by using the {{proxy}} attribute: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. iPOJO handler _start_ level <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">iPOJO Handlers have a _start_ level. This is *not* the {{OSGi Start Level}}. This level is used to determine in which order handler are configured, started and stopped. Handlers with a low level are configured and started before handlers with a high level. Moreover they are stopped after handlers with a high level. By default, handlers have no level. It means that they have the maximum level ({{Integer.MAX}}).  <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">iPOJO Handlers have a _start_ level. This is *not* the {{OSGi Start Level}}. This level is used to determine in which order handler are configured, started and stopped. Handlers with a low level are configured and started before handlers with a high level. Moreover they are stopped after handlers with a high level. By default, handlers have no level. It means that they have the maximum level ({{Integer.MAX}}). <br> <br></td></tr>
            <tr><td class="diff-unchanged" >Here are the levels of core handlers: <br>* Service Dependency: 0 (minimum level) <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. Why does my bundle import unused packages? <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">If you check iPOJO bundle imported packages, you will see that some packages where added:  <br> * org.apache.felix.ipojo;version= 1.2.0 <br> * org.apache.felix.ipojo.architecture;version= 1.2.0 <br> * org.osgi.service.cm;version=1.2 <br> * org.osgi.service.log;version=1.3  <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If you check iPOJO bundle imported packages, you will see that some packages where added: <br>* org.apache.felix.ipojo;version= 1.2.0 <br>* org.apache.felix.ipojo.architecture;version= 1.2.0 <br>* org.osgi.service.cm;version=1.2 <br>* org.osgi.service.log;version=1.3 <br> <br></td></tr>
            <tr><td class="diff-unchanged" >The {{org.apache.felix.ipojo}} package is the main iPOJO package. Manipulated class use it to get access to injected values. The {{org.apache.felix.ipojo.architecture}} package is used to expose _Architecture_ service (allowing instance introspection). This service is exposed with the bundle context from the bundle declaring the component type.
The {{org.osgi.service.cm}} package is imported to publish _ManagedService_ and _ManagedServiceFactory_ with the bundle context from the bundle declaring the component type. So, if you look for services exposed by a bundle declaring component types, you will see _ManagedServiceFactory_ services. <br>Finally, the {{org.osgi.service.log}} is imported because iPOJO delegates log to a log service (if available). This service is get from the bundle context from the bundle declaring the component type. So, to get this service, the package of the service interface is imported.  Then, according to implementations, log services may get the bundle logging the message. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>h2. How does iPOJO compare to Declarative Services or Blueprint? <br> <br>The following table highlights some of the features of each system, it does not attempt to highlight every feature of each. <br> <br>|| Dependency injection || Declarative Services || Blueprint || iPOJO || <br>| Callback injection | Yes | Yes (public method only) | Yes | <br>| Constructor injection | No | Yes | No | <br>| Field injection | No | No | Yes | <br>| Setter injection | Yes | Yes | Yes | <br>| Proxy injection | No | Yes | Yes | <br>| List injection | No | Yes | Yes | <br>| Nullable injection | No | No | Yes | <br>|| Lifecycle || Declarative Services || Blueprint || iPOJO || <br>| Callbacks (activate/deactivate) | Yes | Yes | Yes | <br>| Factory pattern | Yes | Yes | Yes | <br>| Lazy initialization | Yes | Yes | Yes | <br>| Damping | No | Yes | Yes | <br>| Field synchronization | No | No | Yes | <br>| Component lifecycle control | Yes | Partial | Yes | <br>| Service lifecycle control | No | No | Yes | <br>|| Configuration || Declarative Services || Blueprint || iPOJO || <br>| Property configuration | No | Yes | Yes | <br>| Field configuration | No | No | Yes | <br>| Configuration Admin | Yes | No | Yes | <br>|| Services || Declarative Services || Blueprint || iPOJO || <br>| Custom attribute type | No | Yes | Yes | <br>| Lazy initialization | Yes | Yes | Yes | <br>| Composite services | No | No | Yes | <br>|| Component description || Declarative Services || Blueprint || iPOJO || <br>| XML | Yes | Yes | Yes | <br>| Java annotations | No | No | Yes | <br>| API | No | No | Yes | <br>|| Nonfunctional || Declarative Services || Blueprint || iPOJO || <br>| Multiple providers | Yes | Yes | No | <br></td></tr>
            <tr><td class="diff-unchanged" >\\ <br>\\ <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/superfish.css); 
</style>

<style type="text/css">
 @import url(http://felix.apache.org/ipojo/site/style.css); 
</style>

<p>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shCore.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushCSharp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPhp.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJScript.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushVb.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushSql.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushXml.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushShell.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushDelphi.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushPython.js"></script>
<script class="javascript" src="http://cwiki.apache.org/confluence/download/resources/confluence.ext.code:code/shBrushJava.js"></script>

<script type="text/javascript" src="http://felix.apache.org/ipojo/site/jquery-1.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/hoverIntent.js"></script>
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/superfish.js"></script> 
<script type="text/javascript" src="http://felix.apache.org/ipojo/site/supersubs.js"></script> 

<script type="text/javascript"> 
 
    $(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    14,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 
 
</script>
<div class="main">
<div class="page-header"/>
<img src="http://felix.apache.org/ipojo/site/header.png" class="header">
<a href="http://ipojo.org"><img src="http://felix.apache.org/ipojo/site/ipojo.png" width="225" class="header-logo"></a>
<ul class="sf-menu sf-js-enabled sf-shadow" id="ipojo-menu">
<li class="current">
<!-- Menu Overview -->
<a href="#" class="sf-with-ul">Overview<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
<ul>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO" title="Apache Felix iPOJO">Home</a>							
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-why-choose-ipojo" title="apache-felix-ipojo-why-choose-ipojo">Why choose iPOJO</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/apache-felix-ipojo-successstories" title="apache-felix-ipojo-successstories">Success stories</a>
	</li>
	<li>
	<a href="/confluence/display/FELIX/Apache+Felix+iPOJO+Feature+Overview" title="Apache Felix iPOJO Feature Overview">Features</a>
	</li>
</ul>
</li>	

<li class="">			
<!-- Menu download -->
<li>
<a href="/confluence/display/FELIX/Download" title="Download">Download </a>
</li>

<li class="">					
<!-- Menu Documentation -->
<a href="#" class="sf-with-ul">Documentation<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
<ul>
    <!-- sub-menu : getting started -->
    <li class="">
    <a href="#" class="sf-with-ul">Getting Started<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
    <ul>
     <li><a href="/confluence/display/FELIX/iPOJO+in+10+minutes" title="iPOJO in 10 minutes">iPOJO in 10 minutes</a></li>
     <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Annotations" title="How to use iPOJO Annotations">Using Annotations</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Hello+Word+%28Maven-Based%29+tutorial" title="iPOJO Hello Word (Maven-Based) tutorial">Maven tutorial</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Advanced+Tutorial" title="iPOJO Advanced Tutorial">Advanced tutorial</a></li>
     <li><a href="/confluence/display/FELIX/apache-felix-ipojo-dosgi" title="apache-felix-ipojo-dosgi">Using Distributed OSGi</a></li>
     <li><a href="/confluence/display/FELIX/iPOJO+Composition+Tutorial" title="iPOJO Composition Tutorial">Application Composition</a></li>
    </ul>
    </li> <!-- end of getting started -->
    <!-- sub menu : Describing Components -->
     <li class="">
        <a href="http://felix.apache.org/site/describing-components.html" class="sf-with-ul">Describing components<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Service+Requirement+Handler" title="Service Requirement Handler">Requiring a service</a></li>
        <li><a href="/confluence/display/FELIX/Providing+OSGi+services" title="Providing OSGi services">Providing a service</a></li>
        <li><a href="/confluence/display/FELIX/Lifecycle+Callback+Handler" title="Lifecycle Callback Handler">Lifecycle management</a></li>
        <li><a href="/confluence/display/FELIX/Configuration+Handler" title="Configuration Handler">Configuration</a></li>
        <li><a href="/confluence/display/FELIX/Architecture+Handler" title="Architecture Handler">Introspection</a></li>
        <li><a href="/confluence/display/FELIX/Controller+Lifecycle+Handler" title="Controller Lifecycle Handler">Impacting the lifecycle</a></li>
        <li><a href="/confluence/display/FELIX/Event+Admin+Handlers" title="Event Admin Handlers">Asynchronous communication</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+JMX+Handler" title="iPOJO JMX Handler">JMX management</a></li>
        <li><a href="/confluence/display/FELIX/Extender+Pattern+Handler" title="Extender Pattern Handler">Extender pattern</a></li>
        <li><a href="/confluence/display/FELIX/White+Board+Pattern+Handler" title="White Board Pattern Handler">Whiteboard pattern</a></li>
        <li><a href="/confluence/display/FELIX/Temporal+Service+Dependency" title="Temporal Service Dependency">Temporal dependencies</a></li>
        </ul>
     </li> <!-- End of describing components -->
    <!-- sub-menu : User Guide -->
    <li class="">
    <a href="" class="sf-with-ul">User Guide<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
        <ul>
        <li><a href="/confluence/display/FELIX/Combining+iPOJO+and+Configuration+Admin" title="Combining iPOJO and Configuration Admin">iPOJO and config admin</a></li>
        <li><a href="/confluence/display/FELIX/How-to+use+iPOJO+factories" title="How-to use iPOJO factories">Factories and Instances</a></li>
        <li><a href="/confluence/display/FELIX/Using+XML+Schemas" title="Using XML Schemas">XML Schemas</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-api" title="apache-felix-ipojo-api">API</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-testing-components" title="apache-felix-ipojo-testing-components">Testing components</a></li>
        <li><a href="/confluence/display/FELIX/apache-felix-ipojo-eclipse-integration" title="apache-felix-ipojo-eclipse-integration">Eclipse Integration</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO+FAQ" title="iPOJO FAQ">FAQ</a></li>
        <li><a href="/confluence/display/FELIX/iPOJO-Reference-Card" title="iPOJO-Reference-Card">Reference Card</a></li>
        </ul>
    </li> <!-- end of user guide -->
    <!-- sub-menu : Dev Guide -->
    <li> 
    <a href="#" class="sf-with-ul">Advanced Topics<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
       <ul>
        <li><a href="http://felix.apache.org/ipojo/api/1.6.0" class="external-link" rel="nofollow">Javadoc</a></li>
        <li><a href="/confluence/display/FELIX/How+to+write+your+own+handler" title="How to write your own handler">Handler development</a></li>
        <li><a href="/confluence/display/FELIX/How+to+use+iPOJO+Manipulation+Metadata" title="How to use iPOJO Manipulation Metadata">Manipulation Metadata </a></li>
        <li><a href="/confluence/display/FELIX/Dive+into+the+iPOJO+Manipulation+depths" title="Dive into the iPOJO Manipulation depths">Dive into the iPOJO Manipulation depths</a></li>
       </ul>
    </li> <!-- End of Dev guide -->
</ul> 
</li> <!-- End of doc -->
<!-- Menu 4 : Tools -->
<li class="">
<a href="#" class="sf-with-ul">Tools<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/iPOJO+Ant+Task" title="iPOJO Ant Task">Ant Task</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Eclipse+Plug-in" title="iPOJO Eclipse Plug-in">Eclipse Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Maven+Plug-in" title="iPOJO Maven Plug-in">Maven Plugin</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO-Arch-Command" title="iPOJO-Arch-Command"><tt>arch</tt> shell command</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-online-manipulator" title="apache-felix-ipojo-online-manipulator">Online Manipulator</a></li>
   <li><a href="/confluence/display/FELIX/iPOJO+Webconsole+Plugin" title="iPOJO Webconsole Plugin">Webconsole plugin</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-junit4osgi" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li>
</ul>   
</li><!-- End of tools -->	
<!-- Menu 5 : Support -->
<li>
<a href="/confluence/display/FELIX/ipojo-support" title="ipojo-support">Support </a>
</li>
<!-- End of the menu 5 -->			
<!-- Menu 6 : Misc -->
<li class="">
<a href="#" class="sf-with-ul">Misc<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
<ul>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedVMs" title="apache-felix-ipojo-supportedVMs">Supported JVMs</a></li>
   <li><a href="/confluence/display/FELIX/apache-felix-ipojo-supportedOSGi" title="apache-felix-ipojo-supportedOSGi">Supported OSGi Implementations</a></li>
   <li><a href="http://ipojo-dark-side.blogspot.com" class="external-link" rel="nofollow">iPOJO's Dark Side Blog</a></li>
   <li><a href="/confluence/pages/viewpage.action?pageId=54954" title="Article &amp; Presentations">Article &amp; Presentations</a></li>
   <li><a href="http://www.apache.org/">ASF</a></li>
   <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
   <li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li>
</ul>
</li><!-- End of misc -->
</ul> <!-- End of the menu -->
</div> <!-- Page header -->
</p>

<div class="content">


<h1><a name="iPOJOFAQ-ApacheFelixiPOJOFAQ"></a>Apache Felix iPOJO FAQ</h1>

<div class="toc"><div>
<ul>
    <li><a href='#iPOJOFAQ-InjectingthebundlecontextinaPOJO'>Injecting the bundle context in a POJO</a></li>
    <li><a href='#iPOJOFAQ-Accessingservicesinsideinnerandanonymousclasses'>Accessing services inside inner and anonymous classes</a></li>
    <li><a href='#iPOJOFAQ-Usingadifferentversionofthemanipulatorduringthemanipulation'>Using a different version of the manipulator during the manipulation</a></li>
    <li><a href='#iPOJOFAQ-Callbacksorder.'>Callbacks order.</a></li>
    <li><a href='#iPOJOFAQ-DisablingproxiesiniPOJO1.6%5C'>Disabling proxies in iPOJO 1.6+</a></li>
    <li><a href='#iPOJOFAQ-Usedynamicproxiesinsteadofsmartproxies'>Use dynamic proxies instead of smart proxies</a></li>
    <li><a href='#iPOJOFAQ-CanIuseiPOJOwithotherOSGiimplementations%3F'>Can I use iPOJO with other OSGi implementations?</a></li>
    <li><a href='#iPOJOFAQ-Detectingoptionalserviceunavailability'>Detecting optional service unavailability</a></li>
    <li><a href='#iPOJOFAQ-SettingtheiPOJOloglevel'>Setting the iPOJO log level</a></li>
    <li><a href='#iPOJOFAQ-InstallingiPOJOinServiceMixKernel'>Installing iPOJO in Service Mix Kernel</a></li>
    <li><a href='#iPOJOFAQ-iPOJOandFileInstall'>iPOJO and File Install</a></li>
    <li><a href='#iPOJOFAQ-iPOJOhandlerstartlevel'>iPOJO handler <em>start</em> level</a></li>
    <li><a href='#iPOJOFAQ-Whydoesmybundleimportunusedpackages%3F'>Why does my bundle import unused packages?</a></li>
    <li><a href='#iPOJOFAQ-HowdoesiPOJOcomparetoDeclarativeServicesorBlueprint%3F'>How does iPOJO compare to Declarative Services or Blueprint?</a></li>
</ul></div></div>

<h2><a name="iPOJOFAQ-InjectingthebundlecontextinaPOJO"></a>Injecting the bundle context in a POJO</h2>

<p>It is sometimes useful to inject the bundle context in your POJO. Then, your POJO is able to deal with the OSGi environment as <em>regular</em> OSGi applications. It is possible to a POJO to get its <tt>BundleContext</tt>. A POJO can receive its bundle context as an argument of its constructor. The next code snippet shows an example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class ASimplePOJO{
	<span class="code-keyword">private</span> BundleContext context;
	<span class="code-keyword">public</span> ASimplePOJO(BundleContext bc) {
		context = bc;
		<span class="code-comment">// <span class="code-keyword">do</span> something...
</span>	}}
</pre>
</div></div>
<p>As you see on the previous snippet, the bundle context is injected in the POJO. Then the POJO can use it as a 'normal' bundle context. The POJO code can:</p>
<ul>
	<li>load classes</li>
	<li>register / unregister services</li>
	<li>discover, track and use services</li>
</ul>


<p>However, all these interactions are no more managed by the iPOJO container. So, be careful to manage the dynamism, synchronization, listeners...</p>

<h2><a name="iPOJOFAQ-Accessingservicesinsideinnerandanonymousclasses"></a>Accessing services inside inner and anonymous classes</h2>

<p>An inner class is a class defined inside another class.  This mechanism is useful in order to avoid creating a bunch of small files. So, it is common when creating threads, Swing listeners ... Generally speaking, inner classes are regular classes treated as separate classes. However this is an oversimplification. Some of the information about an inner class is not in its class file.  See section 4.7.5 for further details:<br/>
<a href="http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html" class="external-link" rel="nofollow">http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html</a></p>


<p>An inner class can access fields of its outer class. Since the iPOJO 1.0.0 version, fields managed by iPOJO, such as a service dependencies and properties, are also available from the inner class. Indeed, iPOJO manipulation also manipulates inner and nested classes, and accesses to outer class fields are correctly managed.</p>

<h2><a name="iPOJOFAQ-Usingadifferentversionofthemanipulatorduringthemanipulation"></a>Using a different version of the manipulator during the manipulation</h2>

<p>You can configure the version of the manipulator that you want to use when you're using the maven-ipojo-plugin or the iPOJO ant task. This allows to benefit latest improvements.</p>

<p>For Maven, Just declare a dependency on the manipulator that you want to use in the maven-ipojo-plugin plugin section:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Maven</b></div><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;plugin&gt;</span>
        <span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
        <span class="code-tag">&lt;artifactId&gt;</span>maven-ipojo-plugin<span class="code-tag">&lt;/artifactId&gt;</span>
        <span class="code-tag">&lt;executions&gt;</span>
          <span class="code-tag">&lt;execution&gt;</span>
            <span class="code-tag">&lt;goals&gt;</span>
              <span class="code-tag">&lt;goal&gt;</span>ipojo-bundle<span class="code-tag">&lt;/goal&gt;</span>
            <span class="code-tag">&lt;/goals&gt;</span>
          <span class="code-tag">&lt;/execution&gt;</span>
        <span class="code-tag">&lt;/executions&gt;</span>
        <span class="code-tag">&lt;dependencies&gt;</span>
        	<span class="code-tag">&lt;dependency&gt;</span>
        		<span class="code-tag">&lt;groupId&gt;</span>org.apache.felix<span class="code-tag">&lt;/groupId&gt;</span>
        		<span class="code-tag">&lt;artifactId&gt;</span>org.apache.felix.ipojo.manipulator<span class="code-tag">&lt;/artifactId&gt;</span>
        		<span class="code-tag">&lt;version&gt;</span>1.6.2<span class="code-tag">&lt;/version&gt;</span>
        	<span class="code-tag">&lt;/dependency&gt;</span>
        <span class="code-tag">&lt;/dependencies&gt;</span>
      <span class="code-tag">&lt;/plugin&gt;</span>
</pre>
</div></div>

<p>For Ant, just configure the classpath of the iPOJO ant task with the Manipulator that you want to use:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Ant</b></div><div class="codeContent panelContent">
<pre class="code-xml">&lt;taskdef name=<span class="code-quote">"ipojo"</span>
        classname=<span class="code-quote">"org.apache.felix.ipojo.task.IPojoTask"</span>
                classpath=<span class="code-quote">"../ipojo/manipulator/org.apache.felix.ipojo.manipulator-1.7.0-SNAPSHOT.jar; lib/org.apache.felix.ipojo.ant-1.7.0-SNAPSHOT.jar;"</span> /&gt;
 /&gt;
</pre>
</div></div>


<h2><a name="iPOJOFAQ-Callbacksorder."></a>Callbacks order.</h2>

<p>A lot of handlers define callbacks to notify the implementation class. The 'core' callbacks are called in the following order:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Component
@Provides
<span class="code-keyword">public</span> class CallbacksOrder <span class="code-keyword">implements</span> MyService {

	<span class="code-keyword">public</span> CallbacksOrder() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"1 Constructor"</span>);
	}

	@Bind
	<span class="code-keyword">public</span> void bind(LogService log) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"2 Bind "</span> + log);
	}

	@Property(name=<span class="code-quote">"prop"</span>)
	<span class="code-keyword">public</span> void setProp(<span class="code-object">String</span> v) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"3 Set prop "</span> + v);
	}


	@Validate
	<span class="code-keyword">public</span> void validate() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"4 Validate"</span>);
	}

	@PostRegistration
	<span class="code-keyword">public</span> void registered(ServiceReference ref) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"5 Registered"</span>);
	}

	<span class="code-comment">// --- On Service Departure ---
</span>
	@Unbind
	<span class="code-keyword">public</span> void unbind(LogService log) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"6 Unbind "</span> + log);
	}

	<span class="code-comment">// Remaining of the flow
</span>

	@PostUnregistration
	<span class="code-keyword">public</span> void unregistered(ServiceReference ref) {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"7 Unregistered"</span>);
	}

	@Invalidate
	<span class="code-keyword">public</span> void invalidate() {
		<span class="code-object">System</span>.out.println(<span class="code-quote">"8 Invalidate"</span>);
	}

        <span class="code-comment">// --- End of the callback order
</span>
	<span class="code-keyword">public</span> void doNothing() {
		<span class="code-comment">// Do nothing...
</span>	}

}
</pre>
</div></div>

<h2><a name="iPOJOFAQ-DisablingproxiesiniPOJO1.6%5C"></a>Disabling proxies in iPOJO 1.6&#43;</h2>

<p>iPOJO 1.6.0 has generalized the proxy usage. However this mechanism can be disabled.</p>

<p>To disable the proxies on the entire framework, just set the property <tt>ipojo.proxy</tt> to <tt>disabled</tt> (this set the default 'proxy' value). This property is either a system property (<tt>&#45;Dipojo.proxy=disabled</tt> in the command line) or a framework property (given to the framework during its initialization).</p>

<p>You can also disable proxies for specific dependencies by using the <tt>proxy</tt> attribute:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Requires(proxy=<span class="code-keyword">false</span>)
<span class="code-keyword">private</span> LogService log
</pre>
</div></div>
<p>or</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;requires field=<span class="code-quote">"log"</span> proxy=<span class="code-quote">"false"</span>/&gt;</span>
</pre>
</div></div>

<p>The default value of the <tt>proxy</tt> attribute is the value of the <tt>ipojo.proxy</tt> property.</p>

<h2><a name="iPOJOFAQ-Usedynamicproxiesinsteadofsmartproxies"></a>Use dynamic proxies instead of smart proxies</h2>

<p>Smart proxies are generated on the fly using bytecode generation. However this mechanism may not be always supported by the VM (like Dalvik (Android)). To disabled smart proxies (used by default) and use dynamic proxy instead, set the property <tt>ipojo.proxy.type</tt> to <tt>dynamic-proxy</tt>. This property is either a system property or a framework property.</p>

<h2><a name="iPOJOFAQ-CanIuseiPOJOwithotherOSGiimplementations%3F"></a>Can I use iPOJO with other OSGi implementations?</h2>

<p>iPOJO relies on the OSGi R4.1 specification, so works on any compliant implementation. Moreover, iPOJO is weekly tested on Apache Felix, Eclipse Equinox and Knopflerfish..<br/>
For further information, refer to the <a href="/confluence/display/FELIX/apache-felix-ipojo-supportedOSGi" title="apache-felix-ipojo-supportedOSGi">supported OSGi implementations</a> page and on this <a href="http://ipojo-dark-side.blogspot.com/2008/11/lessons-learned-from-ipojo-testing.html" class="external-link" rel="nofollow">blog</a> post.</p>

<h2><a name="iPOJOFAQ-Detectingoptionalserviceunavailability"></a>Detecting optional service unavailability</h2>

<p>Sometimes it is useful to check if an optional service dependency is fulfilled or not. In order to propose a pretty simple development model, iPOJO injects proxies by default which avoid such check (Because proxies hide such details). By disabling proxies, you can easily check to unavailability.</p>

<ul>
	<li>First, disable the proxy injection:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Requires(proxy=<span class="code-keyword">false</span>)
<span class="code-keyword">private</span> LogService log;
</pre>
</div></div></li>
</ul>


<ul>
	<li>The injected object will be a direct reference. By default, iPOJO injects a <tt>Nullable</tt> object, on which you can call service method without checking for <tt>null</tt>. To detect Nullable objects, just use <tt>instanceof</tt>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Requires(proxy=<span class="code-keyword">false</span>)
<span class="code-keyword">private</span> LogService log;

<span class="code-keyword">public</span> void doSomething() {
    <span class="code-keyword">if</span> (log <span class="code-keyword">instanceof</span> Nullable) {
        <span class="code-comment">// Service unavailable
</span>    } <span class="code-keyword">else</span> {
       <span class="code-comment">// Service available
</span>    }
}
</pre>
</div></div></li>
</ul>


<ul>
	<li>If you prefer injecting <tt>null</tt> instead of a <tt>Nullable</tt>, just disable Nullable injection too. However, be care to check for <tt>null</tt> before each invocation.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@Requires(proxy=<span class="code-keyword">false</span>, nullable=<span class="code-keyword">false</span>)
<span class="code-keyword">private</span> LogService log;

<span class="code-keyword">public</span> void doSomething() {
    <span class="code-keyword">if</span> (log == <span class="code-keyword">null</span>) {
        <span class="code-comment">// Service unavailable
</span>    } <span class="code-keyword">else</span> {
       <span class="code-comment">// Service available
</span>    }
}
</pre>
</div></div></li>
</ul>


<h2><a name="iPOJOFAQ-SettingtheiPOJOloglevel"></a>Setting the iPOJO log level</h2>

<p>By default, iPOJO logs only warning and error messages. There are two different methods to configure the log level. First, you can set the global log level by setting the <em>ipojo.log.level</em> system property. This replaces the default log level (warning). All iPOJO instances will be impacted.  However, each bundle containing component types can specify a different log level. To set this level, add the <em>ipojo-log-level</em> header in your manifest. The possible values for these two properties are:</p>
<ul>
	<li>info</li>
	<li>debug</li>
	<li>warning (default)</li>
	<li>error</li>
</ul>


<h2><a name="iPOJOFAQ-InstallingiPOJOinServiceMixKernel"></a>Installing iPOJO in Service Mix Kernel</h2>

<p>You can use iPOJO in Service Mix Kernel. To deploy and start it, just execute the following command line in the ServiceMix Kernel Shell.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">osgi install -s mvn:org.apache.felix/org.apache.felix.ipojo/1.2.0
</pre>
</div></div>

<p>The iPOJO bundle is downloaded from the central maven repository.</p>

<h2><a name="iPOJOFAQ-iPOJOandFileInstall"></a>iPOJO and File Install</h2>

<p>Thanks to File install you can create, disposed and reconfigure instances from <em>cfg</em> files. You can also reconfiguring a creatged instance (configured to expose a <a href="http://felix.apache.org/site/configuration-handler.html#ConfigurationHandler-ExposingaManagedService" class="external-link" rel="nofollow">ManagedService</a>) with <em>cfg</em> files too. More information about this topic is available <a href="http://ipojo-dark-side.blogspot.com/2009/04/ipojo-and-file-install-configuring.html" class="external-link" rel="nofollow">here</a>.</p>

<h2><a name="iPOJOFAQ-iPOJOhandlerstartlevel"></a>iPOJO handler <em>start</em> level</h2>

<p>iPOJO Handlers have a <em>start</em> level. This is <b>not</b> the <tt>OSGi Start Level</tt>. This level is used to determine in which order handler are configured, started and stopped. Handlers with a low level are configured and started before handlers with a high level. Moreover they are stopped after handlers with a high level. By default, handlers have no level. It means that they have the maximum level (<tt>Integer.MAX</tt>).</p>

<p>Here are the levels of core handlers:</p>
<ul>
	<li>Service Dependency: 0 (minimum level)</li>
	<li>Lifecycle Callback: 1</li>
	<li>Configuration Properties: 1</li>
	<li>Service Providing: 3</li>
	<li>Controller Handler: no level (Integer.MAX)</li>
	<li>Architecture Handler: no level (Integer.MAX)</li>
</ul>


<p>From these levels, we can see that bind methods will be called before set methods from configuration properties. So, when a POJO objects, callback are called in this order:</p>
<ol>
	<li>bind methods</li>
	<li>validate method</li>
	<li>setter methods from instance configuration</li>
</ol>


<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Changes in the 1.3.0-SNAPSHOT</b><br />iPOJO 1.3.0-SNAPSHOT sets the lifecycle callback handler level to 2. So, setter methods from instance properties are called before the validate method.</td></tr></table></div>

<h2><a name="iPOJOFAQ-Whydoesmybundleimportunusedpackages%3F"></a>Why does my bundle import unused packages?</h2>

<p>If you check iPOJO bundle imported packages, you will see that some packages where added:</p>
<ul>
	<li>org.apache.felix.ipojo;version= 1.2.0</li>
	<li>org.apache.felix.ipojo.architecture;version= 1.2.0</li>
	<li>org.osgi.service.cm;version=1.2</li>
	<li>org.osgi.service.log;version=1.3</li>
</ul>


<p>The <tt>org.apache.felix.ipojo</tt> package is the main iPOJO package. Manipulated class use it to get access to injected values. The <tt>org.apache.felix.ipojo.architecture</tt> package is used to expose <em>Architecture</em> service (allowing instance introspection). This service is exposed with the bundle context from the bundle declaring the component type.<br/>
The <tt>org.osgi.service.cm</tt> package is imported to publish <em>ManagedService</em> and <em>ManagedServiceFactory</em> with the bundle context from the bundle declaring the component type. So, if you look for services exposed by a bundle declaring component types, you will see <em>ManagedServiceFactory</em> services.<br/>
Finally, the <tt>org.osgi.service.log</tt> is imported because iPOJO delegates log to a log service (if available). This service is get from the bundle context from the bundle declaring the component type. So, to get this service, the package of the service interface is imported.  Then, according to implementations, log services may get the bundle logging the message.</p>

<h2><a name="iPOJOFAQ-HowdoesiPOJOcomparetoDeclarativeServicesorBlueprint%3F"></a>How does iPOJO compare to Declarative Services or Blueprint?</h2>

<p>The following table highlights some of the features of each system, it does not attempt to highlight every feature of each.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Dependency injection </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> Callback injection </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes (public method only) </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Constructor injection </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> No </td>
</tr>
<tr>
<td class='confluenceTd'> Field injection </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Setter injection </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Proxy injection </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> List injection </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Nullable injection </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<th class='confluenceTh'> Lifecycle </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> Callbacks (activate/deactivate) </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Factory pattern </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Lazy initialization </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Damping </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Field synchronization </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Component lifecycle control </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Partial </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Service lifecycle control </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<th class='confluenceTh'> Configuration </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> Property configuration </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Field configuration </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Configuration Admin </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<th class='confluenceTh'> Services </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> Custom attribute type </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Lazy initialization </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Composite services </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<th class='confluenceTh'> Component description </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> XML </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> Java annotations </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<td class='confluenceTd'> API </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Yes </td>
</tr>
<tr>
<th class='confluenceTh'> Nonfunctional </th>
<th class='confluenceTh'> Declarative Services </th>
<th class='confluenceTh'> Blueprint </th>
<th class='confluenceTh'> iPOJO </th>
</tr>
<tr>
<td class='confluenceTd'> Multiple providers </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> Yes </td>
<td class='confluenceTd'> No </td>
</tr>
</tbody></table>
</div>

<p><br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>

 </div>
        <img src="http://felix.apache.org/ipojo/site/footer.png" class="footer">
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-1518442-4");
pageTracker._trackPageview();
} catch(err) {}
</script>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=82868&revisedVersion=33&originalVersion=32">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/FELIX/iPOJO+FAQ?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message