| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Chapter 6. OSGi 4.2 Blueprint Container</title><link rel="stylesheet" href="css/html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="index.html" title="Eclipse Gemini Blueprint Reference Guide"><link rel="up" href="reference.html" title="Part II. Reference Documentation"><link rel="prev" href="reference.html" title="Part II. Reference Documentation"><link rel="next" href="bnd-app-ctx.html" title="Chapter 7. Bundles and Application Contexts"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="blueprint"></a>Chapter 6. OSGi 4.2 Blueprint Container</h2></div></div></div><p>Based on the Gemini Blueprint programming model, the OSGi Alliance introduced in OSGi 4.2 Release |
| the Blueprint Container specification (part of the Compendium Service). Gemini Blueprint 1.0 serves as |
| the Blueprint Reference <a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://en.wikipedia.org/wiki/Reference_implementation" target="_top">Implementation</a> |
| - the official, complete implementation of the spec. |
| </p><p>Existing and new users have the freedom to mix and match the programming model they want, since Eclipse Gemini Blueprint supports |
| both the Spring DM 1.x declarations and the Blueprint one, inside the same application, provided the default namespace is Blueprint |
| and the Blueprint files are stored in the folder <code class="literal">META-INF/spring</code>. |
| </p><p>Please note that this documentation will focus on Gemini Blueprint specific configurations and options; for Blueprint specific |
| behaviour please refer to the OSGi 4.2 Compendium spec, section 121.</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="blueprint:requirements"></a>6.1. Blueprint Requirements</h2></div></div></div><p>The Blueprint Container spec is part of the OSGi 4.2 release and relies on it, in its API. Thus, |
| in order to use Blueprint, one must use an OSGi 4.2 compatible platform as a runtime environment. Gemini Blueprint itself |
| requires only an OSGi 4.0 framework so if 4.2 is not an option, one can safely downgrade at the loss of the Blueprint |
| model which can be built on top of Spring/Gemini Blueprint. |
| </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/admons/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top">On environments prior to OSGi 4.2, Gemini Blueprint will disable the Blueprint functionality automatically - users will be notified |
| through a log message similar to the following: |
| |
| <pre class="screen">Pre-4.2 OSGi platform detected; disabling Blueprint Container functionality</pre></td></tr></table></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="blueprint:differences"></a>6.2. Blueprint/Gemini Blueprint Differences</h2></div></div></div><p>There are a lot of similarities in terms of functionality and configuration between Gemini Blueprint 1.x and Blueprint which should be |
| no surprise considering that Spring DM was the basis of the Blueprint spec. In addition to fully supporting the Blueprint configuration schema, |
| DM 2.x enhanced its declarations by providing option that allow for Blueprint specific behaviour. The table below aggregates the most |
| important user facing differences between Spring/Gemini Blueprint configurations and Blueprint. Additional comparison information is available |
| throughout the documentation (such as <a href="app-deploy.html#app-deploy:headers:blueprint" title="8.2. Blueprint Manifest Configuration Comparison">Section 8.2, “Blueprint Manifest Configuration Comparison”</a> or <a href="service-registry.html#service-registry:export:blueprint" title="9.1.10.2. Blueprint service Comparison">Section 9.1.10.2, “Blueprint <code class="literal">service</code> Comparison”</a>). |
| Again, one can simply switch between the two definition styles, if need be.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="blueprint:differences:xml"></a>6.2.1. XML Declarations</h3></div></div></div><p>Most of the XML declarations are similar between Spring and Blueprint. Using the Spring |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://static.springsource.org/spring/docs/2.5.x/reference/new-in-2.html#new-in-2-ioc-configuration" target="_top">namespace</a> mechanism, |
| the same configuration can contain both Spring, Gemini Blueprint, Blueprint and other namespaces. Moreover, custom elements can be used for virtually |
| all elements of a Spring configuration (namespace, bean declaration, decoration, etc...). The table below focuses <span class="emphasis"><em>only</em></span> |
| on the usual, standard Spring namespaces and their Blueprint equivalent.</p><div class="table"><a name="spring-vs-blueprint-xml"></a><p class="title"><b>Table 6.1. XML Configuration Differences</b></p><div class="table-contents"><table summary="XML Configuration Differences" width="100%" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Element/Attribute</th><th>Gemini Blueprint</th><th>Blueprint</th></tr></thead><tbody><tr><td>Namespace Declaration</td><td><p><code class="literal">http://www.springframework.org/schema/beans</code></p> |
| <p>or <code class="literal">http://www.springframework.org/schema/osgi</code></p></td><td><code class="literal">http://www.osgi.org/xmlns/blueprint/v1.0.0</code></td></tr><tr><td>Root Element</td><td><code class="literal"><beans></code></td><td><code class="literal"><blueprint></code></td></tr><tr><td>Default Lazy</td><td><code class="literal">default-lazy</code></td><td><code class="literal">default-activation</code></td></tr><tr><td>Default Init Method</td><td><code class="literal">default-init-method</code></td><td><code class="literal">-</code></td></tr><tr><td>Default Destroy Method</td><td><code class="literal">default-destroy-method</code></td><td><code class="literal">-</code></td></tr><tr><td>Default Autowire Strategy</td><td><code class="literal">default-autowire</code>, <code class="literal">default-autowire-candidates</code></td><td><code class="literal">-</code></td></tr><tr><td>Root Element</td><td><code class="literal"><beans></code></td><td><code class="literal"><blueprint></code></td></tr><tr><td>Bean ID</td><td><code class="literal">id</code></td><td><code class="literal">id</code></td></tr><tr><td>Bean Name/Alias</td><td><code class="literal">name</code>/<code class="literal"><alias></code></td><td><code class="literal">-</code></td></tr><tr><td>Bean Class</td><td><code class="literal">class</code></td><td><code class="literal">class</code></td></tr><tr><td>Bean Scope Name</td><td><code class="literal">scope</code></td><td><code class="literal">scope</code></td></tr><tr><td>Built-in Scopes</td><td><code class="literal">singleton</code>, <code class="literal">prototype</code>, <code class="literal">request</code>, <code class="literal">session</code>, <code class="literal">bundle</code></td><td><code class="literal">singleton</code>, <code class="literal">prototype</code></td></tr><tr><td>Lazy Initialization Name/Values</td><td><code class="literal">lazy-init</code>=<code class="literal">true/false</code></td><td><code class="literal">activation</code>=<code class="literal">lazy/eager</code></td></tr><tr><td>Depends</td><td><code class="literal">depends-on</code></td><td><code class="literal">depends-on</code></td></tr><tr><td>Init Method</td><td><code class="literal">init-method</code></td><td><code class="literal">init-method</code></td></tr><tr><td>Destroy Method</td><td><code class="literal">destroy-method</code></td><td><code class="literal">destroy-method</code></td></tr><tr><td>Factory Method</td><td><code class="literal">factory-method</code></td><td><code class="literal">factory-method</code></td></tr><tr><td>Factory Bean</td><td><code class="literal">factory-bean</code></td><td><code class="literal">factory-ref</code></td></tr><tr><td>Bean Inheritance</td><td><code class="literal">parent</code></td><td><code class="literal">-</code></td></tr><tr><td>Autowire Strategy</td><td><code class="literal">autowire</code>, <code class="literal">autowire-candidate</code></td><td><code class="literal">-</code></td></tr><tr><td>Constructor</td><td><code class="literal"><constructor-arg></code></td><td><code class="literal"><argument></code></td></tr><tr><td>Property</td><td><code class="literal"><property></code></td><td><code class="literal"><property></code></td></tr><tr><td>Value</td><td><code class="literal"><value></code></td><td><code class="literal"><value></code></td></tr><tr><td>Service Exporter</td><td><code class="literal"><service></code></td><td><code class="literal"><service></code></td></tr><tr><td>Service Importer</td><td><code class="literal"><reference>/<list>/<set></code></td><td><code class="literal"><reference>/<list></code></td></tr></tbody></table></div></div><br class="table-break"><p>The configurations below are equivalent in terms of functionality:</p><pre class="programlisting"><<span class="hl-tag">?xml version="1.0" encoding="UTF-8"?</span>> |
| <<span class="hl-tag">blueprint</span> <span class="hl-attribute">xmlns</span>=<span class="hl-value">"http://www.osgi.org/xmlns/blueprint/v1.0.0"</span> <span class="hl-attribute">default-activation</span>=<span class="hl-value">"lazy"</span>> |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"object"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.Object"</span>/> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"length"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.Integer"</span>> |
| <<span class="hl-tag">argument</span> <span class="hl-attribute">value</span>=<span class="hl-value">"4"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"buffer"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.StringBuffer"</span> <span class="hl-attribute">depends-on</span>=<span class="hl-value">"simple"</span>> |
| <<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"length"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"length"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"current-time"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.System"</span> <span class="hl-attribute">factory-method</span>=<span class="hl-value">"currentTimeMillis"</span> <span class="hl-attribute">scope</span>=<span class="hl-value">"prototype"</span>/> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"list"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.util.ArrayList"</span> <span class="hl-attribute">destroy-method</span>=<span class="hl-value">"clear"</span> <span class="hl-attribute">activation</span>=<span class="hl-value">"eager"</span>> |
| <<span class="hl-tag">argument</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"length"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| <<span class="hl-tag">/blueprint</span>></pre><pre class="programlisting"><<span class="hl-tag">?xml version="1.0" encoding="UTF-8"?</span>> |
| <<span class="hl-tag">beans</span> <span class="hl-attribute">xmlns</span>=<span class="hl-value">"http://www.springframework.org/schema/beans"</span> |
| <span class="hl-attribute">xmlns:xsi</span>=<span class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span> |
| <span class="hl-attribute">xsi:schemaLocation</span>=<span class="hl-value">"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"</span> |
| <span class="hl-attribute">default-lazy-init</span>=<span class="hl-value">"true"</span>> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"object"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.Object"</span>/> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"length"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.Integer"</span>> |
| <<span class="hl-tag">constructor-arg</span> <span class="hl-attribute">value</span>=<span class="hl-value">"4"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"buffer"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.StringBuffer"</span> <span class="hl-attribute">depends-on</span>=<span class="hl-value">"simple"</span>> |
| <<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"length"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"length"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"current-time"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.System"</span> <span class="hl-attribute">factory-method</span>=<span class="hl-value">"currentTimeMillis"</span> <span class="hl-attribute">scope</span>=<span class="hl-value">"prototype"</span>/> |
| |
| <<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"list"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.util.ArrayList"</span> <span class="hl-attribute">destroy-method</span>=<span class="hl-value">"clear"</span> <span class="hl-attribute">lazy-init</span>=<span class="hl-value">"false"</span>> |
| <<span class="hl-tag">constructor-arg</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"length"</span>/> |
| <<span class="hl-tag">/bean</span>> |
| <<span class="hl-tag">/beans</span>></pre><p>As mentioned before, in Gemini Blueprint one can mix and match the namespaces provided the default namespace is Blueprint |
| and the Blueprint files are stored in the folder <code class="literal">META-INF/spring</code>:</p><pre class="programlisting"><<span class="hl-tag">blueprint</span> <span class="hl-attribute">xmlns</span>=<span class="hl-value">"http://www.osgi.org/xmlns/blueprint/v1.0.0"</span> |
| <span class="hl-attribute">xmlns:beans</span>=<span class="hl-value">"http://www.springframework.org/schema/beans"</span> |
| <span class="hl-attribute">xmlns:xsi</span>=<span class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span> |
| <span class="hl-attribute">xsi:schemaLocation</span>=<span class="hl-value">" |
| http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd |
| http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"</span>> |
| |
| <<span class="hl-tag">beans:bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"anInteger"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"java.lang.Integer"</span>> |
| <<span class="hl-tag">beans:constructor-arg</span> <span class="hl-attribute">value</span>=<span class="hl-value">"10"</span>/> |
| <<span class="hl-tag">/beans:bean</span>> |
| |
| <<span class="hl-tag">service</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"anInteger"</span> <span class="hl-attribute">interface</span>=<span class="hl-value">"java.lang.Comparable"</span> /> |
| <<span class="hl-tag">/blueprint</span>></pre><p>The example above uses the Gemini Blueprint and Spring <code class="literal">beans</code> namespaces.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="blueprint:differences:container"></a>6.2.2. Container Capabilities</h3></div></div></div><p>From a container perspective, the Blueprint spec standardizes the a subset of the Spring container. A high-level view comparison, by no |
| means comprehensive, is summarized in the table below:</p><div class="table"><a name="spring-vs-blueprint-container"></a><p class="title"><b>Table 6.2. Container Capabilities Differences</b></p><div class="table-contents"><table summary="Container Capabilities Differences" width="100%" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Feature</th><th>Gemini Blueprint</th><th>Blueprint</th></tr></thead><tbody><tr><td colspan="3" align="center"><span class="emphasis"><em>Object Instantiation</em></span></td></tr><tr><td>Constructor Instantiation</td><td>Y</td><td>Y</td></tr><tr><td>Static Factory Instantiation</td><td>Y</td><td>Y</td></tr><tr><td>Instance Factory Instantiation</td><td>Y</td><td>Y</td></tr><tr><td colspan="3" align="center"><span class="emphasis"><em>Dependency Injection</em></span></td></tr><tr><td>Constructor Injection</td><td>Y</td><td>Y</td></tr><tr><td>Setter Injection</td><td>Y</td><td>Y</td></tr><tr><td>Field Injection</td><td>Y</td><td>N</td></tr><tr><td>Method Injection</td><td>Y</td><td>N</td></tr><tr><td>Arbitrary Method Injection</td><td>Y</td><td>N</td></tr><tr><td>Autowiring</td><td>Y</td><td>N</td></tr><tr><td colspan="3" align="center"><span class="emphasis"><em>Component Lifecycle</em></span></td></tr><tr><td>Lazy Initialization</td><td>Y</td><td>Y</td></tr><tr><td>Bean Scopes</td><td>Y</td><td>Y</td></tr><tr><td>Custom Bean Scopes</td><td>Y</td><td>N</td></tr><tr><td>Built-in Callbacks</td><td>Y</td><td>N</td></tr><tr><td>Custom Callbacks</td><td>Y</td><td>Y</td></tr><tr><td>Initialization Processing</td><td>Y</td><td>N</td></tr></tbody></table></div></div><br class="table-break"><p>As with the XML configuration, since Gemini Blueprint translates the Blueprint configuration into Spring metadata, one can rely on Spring for features |
| beyond the Blueprint container. For example, one can configure a bean using Blueprint and use annotation on the same instance, for field injection. |
| The same object can implement Spring's <code class="literal">Aware</code> interfaces or rely on other post processors for certain behaviour.</p></div><p>Note that additional information on Blueprint is available through out the documentation. These being said, it is highly recommended to read |
| and use the Blueprint specification as guidance, if the Blueprint Container becomes the programming model of choice.</p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="blueprint:using"></a>6.3. Using Blueprint</h2></div></div></div><p>There are no extra jars or steps that need to be executed to <span class="emphasis"><em>enable</em></span> the Blueprint functionality in Gemini Blueprint. |
| This is built directly into the core, in fact the Blueprint APIs are exported by the Gemini Blueprint core. Please see the next section for |
| information on how to install Gemini Blueprint and the OSGi compendium spec (section 121) for Blueprint related information such as bootstrapping |
| and configuration locations. For those in a hurry, simply install and start the Gemini Blueprint jars (io, core, extender) and their dependencies |
| (namely Spring and slf4j) and you should be all set: Gemini Blueprint will automatically detect the running environment and the types of bundles started. |
| </p></div></div><div xmlns:fo="http://www.w3.org/1999/XSL/Format" class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="reference.html">Prev</a> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right"> <a accesskey="n" href="bnd-app-ctx.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part II. Reference Documentation </td><td width="20%" align="center"><span style="color:white;font-size:90%;"><a href="http://www.SpringSource.com/" title="SpringSource - Spring from the Source">Sponsored by SpringSource |
| </a></span></td><td width="40%" align="right" valign="top"> Chapter 7. Bundles and Application Contexts</td></tr></table></div></body></html> |