blob: 5ceb87cc9674a38e1ca99ffd8d1eeefd98434506 [file] [log] [blame]
Clement Escoffier373a57d2009-07-21 12:06:46 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html><head>
3
4
5
6 <title>Apache Felix - apache-felix-ipojo-api</title>
7 <link rel="stylesheet" href="apache-felix-ipojo-api_files/site.css" type="text/css" media="all">
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 </head><body>
10 <div class="title"><div class="logo"><a href="http://felix.apache.org/site/index.html"><img alt="Apache Felix" src="apache-felix-ipojo-api_files/logo.png" border="0"></a></div><div class="header"><a href="http://www.apache.org/"><img alt="Apache" src="apache-felix-ipojo-api_files/apache.png" border="0"></a></div></div>
11 <div class="menu">
12<ul>
13 <li><a href="http://felix.apache.org/site/news.html" title="news">news</a></li>
14 <li><a href="http://felix.apache.org/site/license.html" title="license">license</a></li>
15 <li><a href="http://felix.apache.org/site/downloads.cgi" rel="nofollow">downloads</a></li>
16 <li><a href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</a></li>
17 <li><a href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</a></li>
18 <li><a href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</a></li>
19 <li><a href="http://www.apache.org/" rel="nofollow">asf</a></li>
20 <li><a href="http://www.apache.org/foundation/sponsorship.html" rel="nofollow">sponsorship</a></li>
21 <li><a href="http://www.apache.org/foundation/thanks.html" rel="nofollow">sponsors</a>
22<!-- ApacheCon Ad -->
23<iframe src="apache-felix-ipojo-api_files/button.html" style="border-width: 0pt; float: left;" scrolling="no" frameborder="0" height="135" width="135"></iframe>
24<p style="height: 100px;">
25<!-- ApacheCon Ad -->
26</p></li></ul> </div>
27 <div class="main">
28<style type="text/css">
29 @import url(http://people.apache.org/~clement/ipojo/site/superfish.css);
30</style>
31
32<style type="text/css">
33 @import url(http://people.apache.org/~clement/ipojo/site/style.css);
34</style>
35
36<p>
37<script class="javascript" src="apache-felix-ipojo-api_files/shCore.js"></script>
38<script class="javascript" src="apache-felix-ipojo-api_files/shBrushCSharp.js"></script>
39<script class="javascript" src="apache-felix-ipojo-api_files/shBrushPhp.js"></script>
40<script class="javascript" src="apache-felix-ipojo-api_files/shBrushJScript.js"></script>
41<script class="javascript" src="apache-felix-ipojo-api_files/shBrushVb.js"></script>
42<script class="javascript" src="apache-felix-ipojo-api_files/shBrushSql.js"></script>
43<script class="javascript" src="apache-felix-ipojo-api_files/shBrushXml.js"></script>
44<script class="javascript" src="apache-felix-ipojo-api_files/shBrushShell.js"></script>
45<script class="javascript" src="apache-felix-ipojo-api_files/shBrushDelphi.js"></script>
46<script class="javascript" src="apache-felix-ipojo-api_files/shBrushPython.js"></script>
47<script class="javascript" src="apache-felix-ipojo-api_files/shBrushJava.js"></script>
48
49<script type="text/javascript" src="apache-felix-ipojo-api_files/jquery-1.js"></script>
50<script type="text/javascript" src="apache-felix-ipojo-api_files/hoverIntent.js"></script>
51<script type="text/javascript" src="apache-felix-ipojo-api_files/superfish.js"></script>
52<script type="text/javascript" src="apache-felix-ipojo-api_files/supersubs.js"></script>
53
54<script type="text/javascript">
55
56 $(document).ready(function(){
57 $("ul.sf-menu").supersubs({
58 minWidth: 14, // minimum width of sub-menus in em units
59 maxWidth: 30, // maximum width of sub-menus in em units
60 extraWidth: 1 // extra width can ensure lines don't sometimes turn over
61 // due to slight rounding differences and font-family
62 }).superfish(); // call supersubs first, then superfish, so that subs are
63 // not display:none when measuring. Call before initialising
64 // containing tabs for same reason.
65 });
66
67</script>
68</p><div class="main">
69<div class="page-header">
70<img src="apache-felix-ipojo-api_files/header.png" class="header">
71<a href="http://ipojo.org/"><img src="apache-felix-ipojo-api_files/ipojo.png" class="header-logo" width="225"></a>
72<ul class="sf-menu sf-js-enabled sf-shadow" id="ipojo-menu">
73<li class="current">
74<!-- Menu Overview -->
75<a href="" class="sf-with-ul">Overview<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
76<ul style="float: none; width: 14em; display: none; visibility: hidden;">
77 <li style="white-space: normal; float: left; width: 100%;">
78 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo.html" title="Apache Felix iPOJO">Home</a>
79 </li>
80 <li style="white-space: normal; float: left; width: 100%;">
81 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-why-choose-ipojo.html" title="apache-felix-ipojo-why-choose-ipojo">Why choose iPOJO</a>
82 </li>
83 <li style="white-space: normal; float: left; width: 100%;">
84 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-successstories.html" title="apache-felix-ipojo-successstories">Success stories</a>
85 </li>
86 <li style="white-space: normal; float: left; width: 100%;">
87 <a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-feature-overview.html" title="Apache Felix iPOJO Feature Overview">Features</a>
88 </li>
89</ul>
90</li>
91
92<li class="">
93<!-- Menu download -->
94</li><li>
95<a href="http://felix.apache.org/site/download.html" title="Download">Download </a>
96</li>
97
98<li class="">
99<!-- Menu Documentation -->
100<a href="" class="sf-with-ul">Documentation<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
101<ul style="float: none; width: 14em; display: none; visibility: hidden;">
102 <!-- sub- menu : getting started -->
103 <li style="white-space: normal; float: left; width: 100%;" class="">
104 <a style="float: none; width: auto;" href="" class="sf-with-ul">Getting Started<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
105 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
106 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-in-10-minutes.html" title="iPOJO in 10 minutes">iPOJO in 10 minutes</a></li>
107 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-use-ipojo-annotations.html" title="How to use iPOJO Annotations">Using Annotations</a></li>
108 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html" title="iPOJO Hello Word (Maven-Based) tutorial">Maven tutorial</a></li>
109 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-advanced-tutorial.html" title="iPOJO Advanced Tutorial">Advanced tutorial</a></li>
110 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-dosgi.html" title="apache-felix-ipojo-dosgi">Using Distributed OSGi</a></li>
111 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-composition-tutorial.html" title="iPOJO Composition Tutorial">Application Composition</a></li>
112 </ul>
113 </li> <!-- end of getting started -->
114 <!-- sub menu : Describing Components -->
115 <li style="white-space: normal; float: left; width: 100%;" class="">
116 <a style="float: none; width: auto;" 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><span class="sf-sub-indicator"> »</span></a>
117 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
118 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/service-requirement-handler.html" title="Service Requirement Handler">Requiring a service</a></li>
119 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/providing-osgi-services.html" title="Providing OSGi services">Providing a service</a></li>
120 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/lifecycle-callback-handler.html" title="Lifecycle Callback Handler">Lifecycle management</a></li>
121 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/configuration-handler.html" title="Configuration Handler">Configuration</a></li>
122 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/architecture-handler.html" title="Architecture Handler">Introspection</a></li>
123 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/controller-lifecycle-handler.html" title="Controller Lifecycle Handler">Impacting the lifecycle</a></li>
124 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/event-admin-handlers.html" title="Event Admin Handlers">Asynchronous communication</a></li>
125 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-jmx-handler.html" title="iPOJO JMX Handler">JMX management</a></li>
126 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/extender-pattern-handler.html" title="Extender Pattern Handler">Extender pattern</a></li>
127 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/white-board-pattern-handler.html" title="White Board Pattern Handler">Whiteboard pattern</a></li>
128 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/temporal-service-dependency.html" title="Temporal Service Dependency">Temporal dependencies</a></li>
129 </ul>
130 </li> <!-- End of describing components -->
131 <!-- sub- menu : User Guide -->
132 <li style="white-space: normal; float: left; width: 100%;" class="">
133 <a style="float: none; width: auto;" href="" class="sf-with-ul">User Guide<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
134 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
135 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/using-xml-schemas.html" title="Using XML Schemas">XML Schemas</a></li>
136 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="" title="apache-felix-ipojo-api">API</a></li>
137 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-testing-components.html" title="apache-felix-ipojo-testing-components">Testing components</a></li>
138 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-eclipse-integration.html" title="apache-felix-ipojo-eclipse-integration">Eclipse Integration</a></li>
139 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-faq.html" title="iPOJO FAQ">FAQ</a></li>
140 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-reference-card.html" title="iPOJO-Reference-Card">Reference Card</a></li>
141 </ul>
142 </li> <!-- end of user guide -->
143 <!-- sub- menu : Dev Guide -->
144 <li class="" style="white-space: normal; float: left; width: 100%;">
145 <a style="float: none; width: auto;" href="" class="sf-with-ul">Advanced Topics<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
146 <ul style="left: 14em; float: none; width: 14em; display: none; visibility: hidden;">
147 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/ipojo/api/1.2.0" rel="nofollow">Javadoc</a></li>
148 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-write-your-own-handler.html" title="How to write your own handler">Handler guide</a></li>
149 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/how-to-use-ipojo-manipulation-metadata.html" title="How to use iPOJO Manipulation Metadata">Manipulation Metadata </a></li>
150 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/dive-into-the-ipojo-manipulation-depths.html" title="Dive into the iPOJO Manipulation depths">Dive into the iPOJO Manipulation depths</a></li>
151 </ul>
152 </li> <!-- End of Dev guide -->
153</ul>
154</li> <!-- End of doc -->
155<!-- Menu 4 : Tools -->
156<li class="">
157<a href="" class="sf-with-ul">Tools<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
158<ul style="float: none; width: 14em; display: none; visibility: hidden;">
159 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-ant-task.html" title="iPOJO Ant Task">Ant Task</a></li>
160 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-eclipse-plug-in.html" title="iPOJO Eclipse Plug-in">Eclipse Plugin</a></li>
161 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-maven-plug-in.html" title="iPOJO Maven Plug-in">Maven Plugin</a></li>
162 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-online-manipulator.html" title="apache-felix-ipojo-online-manipulator">Online Manipulator</a></li>
163 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/ipojo-webconsole-plugin.html" title="iPOJO Webconsole Plugin">Webconsole plugin</a></li>
164 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-junit4osgi.html" title="apache-felix-ipojo-junit4osgi">Junit4OSGi</a></li>
165</ul>
166</li><!-- End of tools -->
167<!-- Menu 5 : Misc -->
168<li class="">
169<a href="" class="sf-with-ul">Misc<span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span><span class="sf-sub-indicator"> »</span></a>
170<ul style="float: none; width: 14em; display: none; visibility: hidden;">
171 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-issuestracker.html" title="apache-felix-ipojo-issuestracker">Issues Tracker</a></li>
172 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-supportedvms.html" title="apache-felix-ipojo-supportedVMs">Supported JVMs</a></li>
173 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/apache-felix-ipojo-supportedosgi.html" title="apache-felix-ipojo-supportedOSGi">Supported OSGi Implementations</a></li>
174 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://ipojo-dark-side.blogspot.com/" rel="nofollow">iPOJO's Dark Side Blog</a></li>
175 <li style="white-space: normal; float: left; width: 100%;"><a style="float: none; width: auto;" href="http://felix.apache.org/site/article-presentations.html" title="Article &amp; Presentations">Article &amp; Presentations</a></li>
176</ul>
177</li><!-- End of misc -->
178</ul> <!-- End of the menu -->
179</div> <!-- Page header -->
180
181
182<div class="content">
183
184<h1><a name="apache-felix-ipojo-api-iPOJOAPI"></a>iPOJO API</h1>
185
186<p><em>The iPOJO API provides a third way to describe iPOJO components.
187With the API, you can dynamically create new components types and
188create instances from them. Your component types are described with an
189API. To use the API, deploy and start the iPOJO-API bundle and the
190iPOJO core bundle.</em></p>
191
192<div class="toc">
193<ul>
194 <li><a href="#apache-felix-ipojo-api-Asimpleexample">A simple example</a></li>
195 <li><a href="#apache-felix-ipojo-api-PrimitiveComponentTypebasics">Primitive Component Type basics</a></li>
196 <li><a href="#apache-felix-ipojo-api-ImmediateComponent%252CValidateandInvalidateMethod">Immediate Component, Validate and Invalidate Method</a></li>
197 <li><a href="#apache-felix-ipojo-api-Declaringservices">Declaring services</a></li>
198 <li><a href="#apache-felix-ipojo-api-ServiceDependencies">Service Dependencies</a></li>
199 <li><a href="#apache-felix-ipojo-api-Properties">Properties</a></li>
200 <li><a href="#apache-felix-ipojo-api-TemporalDependencies">Temporal Dependencies</a></li>
201 <li><a href="#apache-felix-ipojo-api-Instancecreation">Instance creation</a></li>
202 <li><a href="#apache-felix-ipojo-api-ManagedServiceandPropagation">Managed Service and Propagation</a></li>
203 <li><a href="#apache-felix-ipojo-api-ManagingiPOJOFactory">Managing iPOJO Factory</a></li>
204 <li><a href="#apache-felix-ipojo-api-AccesstotheintrospectionAPI">Access to the introspection API</a></li>
205 <li><a href="#apache-felix-ipojo-api-SingletonComponentType">Singleton Component Type</a></li>
206 <li><a href="#apache-felix-ipojo-api-Usingexternalhandlers">Using external handlers</a></li>
207 <li><a href="#apache-felix-ipojo-api-CreatingcompositionwiththeAPI">Creating composition with the API</a></li>
208</ul></div>
209
210
211<div class="panelMacro"><table class="infoMacro"><colgroup><col width="24"><col></colgroup><tbody><tr><td valign="top"><img src="apache-felix-ipojo-api_files/information.gif" alt="" border="0" align="absmiddle" height="16" width="16"></td><td><b>1.3.0-SNAPSHOT feature</b><br><p>The API is a 1.3.0-SNAPSHOT feature, and is not available in the 1.2.0 release.</p></td></tr></tbody></table></div>
212
213<h2><a name="apache-felix-ipojo-api-Asimpleexample"></a>A simple example</h2>
214
215<p>Let's imagine a simple component providing a service Foo. The following code is the implementation class of our component:</p>
216<div class="code">
217<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">package</span><span>&nbsp;org.example.service.impl;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1"><span class="keyword">import</span><span>&nbsp;org.example.service.Foo;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;FooImpl&nbsp;</span><span class="keyword">implements</span><span>&nbsp;Foo&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;doSomething()&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Do&nbsp;something...</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">package org.example.service.impl;
218
219import org.example.service.Foo;
220
221public class FooImpl implements Foo {
222
223 public void doSomething() {
224 // Do something...
225 }
226
227}</textarea>
228<script class="javascript">
229 if(!window.newcodemacro_initialised)
230 {
231 window.newcodemacro_initialised = true;
232 window.oldonloadmethod = window.onload;
233 window.onload = function(){
234 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
235 if(window.oldonloadmethod)
236 {
237 window.oldonloadmethod();
238 }
239 }
240 }
241
242</script>
243</div>
244
245
246<p>To create the component type and an instance of the component type
247just create a class, get the bundle context (either from a
248Bundle-Activator, or from an iPOJO component), and write the following
249code:</p>
250<div class="code">
251<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(FooImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addService(new&nbsp;Service())&nbsp;<span class="comment">//&nbsp;Provide&nbsp;the&nbsp;Foo&nbsp;service</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;<span class="comment">//&nbsp;Create&nbsp;the&nbsp;instance</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
252 .setBundleContext(context)
253 .setClassName(FooImpl.class.getName())
254 .addService(new Service()) // Provide the Foo service
255 .createInstance(); // Create the instance</textarea>
256<script class="javascript">
257 if(!window.newcodemacro_initialised)
258 {
259 window.newcodemacro_initialised = true;
260 window.oldonloadmethod = window.onload;
261 window.onload = function(){
262 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
263 if(window.oldonloadmethod)
264 {
265 window.oldonloadmethod();
266 }
267 }
268 }
269
270</script>
271</div>
272
273
274<p>So, now let's imagine another component using this service. The
275following code is the implementation class of this component type:</p>
276<div class="code">
277<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">package</span><span>&nbsp;org.example.service.impl;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1"><span class="keyword">import</span><span>&nbsp;org.example.service.Foo;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;MyComponentImpl&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;Foo&nbsp;myFoo;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;start()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myFoo.doSomething();&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2">}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">package org.example.service.impl;
278
279import org.example.service.Foo;
280
281public class MyComponentImpl {
282 private Foo myFoo;
283
284 public void start() {
285 myFoo.doSomething();
286 }
287
288}</textarea>
289<script class="javascript">
290 if(!window.newcodemacro_initialised)
291 {
292 window.newcodemacro_initialised = true;
293 window.oldonloadmethod = window.onload;
294 window.onload = function(){
295 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
296 if(window.oldonloadmethod)
297 {
298 window.oldonloadmethod();
299 }
300 }
301 }
302
303</script>
304</div>
305
306
307<p>It is a regular iPOJO component expecting to get a Foo service in the <tt>myFoo</tt>
308field. It also has a method executed when the instance is valid using
309the Foo service. To describe this component, just write the following
310lines:</p>
311<div class="code">
312<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addDependency(new&nbsp;Dependency().setField(<span class="string">"myFoo"</span><span>))&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setValidateMethod(<span class="string">"start"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
313 .setBundleContext(context)
314 .setClassName(MyComponentImpl.class.getName())
315 .addDependency(new Dependency().setField("myFoo"))
316 .setValidateMethod("start")
317 .createInstance();</textarea>
318<script class="javascript">
319 if(!window.newcodemacro_initialised)
320 {
321 window.newcodemacro_initialised = true;
322 window.oldonloadmethod = window.onload;
323 window.onload = function(){
324 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
325 if(window.oldonloadmethod)
326 {
327 window.oldonloadmethod();
328 }
329 }
330 }
331
332</script>
333</div>
334
335
336<h2><a name="apache-felix-ipojo-api-PrimitiveComponentTypebasics"></a>Primitive Component Type basics</h2>
337
338<p>When you create a new Primitive component type (so, using a Java
339class as implementation), you must set the bundle context and the class
340name. Everything else is optional. </p>
341
342<p>Note about inner classes: iPOJO is based on a bytecode manipulation.
343The API embeds the manipulator. So, when you initialize the component
344type, the specified class name is manipulated (if not already
345manipulated). So, as this force using a customized classloader, inner
346classes cannot be manipulated. So, inner class injection is not
347supported with the API.</p>
348
349<h2><a name="apache-felix-ipojo-api-ImmediateComponent,ValidateandInvalidateMethod"></a>Immediate Component, Validate and Invalidate Method</h2>
350<p>To set the component type as immediate, just call the <tt>setImmediate(immediate)</tt> method on the primitive component type object. <br>
351To set validate and invalidate methods, just call the <tt>setValidate(method)</tt> and <tt>setInvalidate(method)</tt>. Specify the method name that you want to call in argument. </p>
352
353<h2><a name="apache-felix-ipojo-api-Declaringservices"></a>Declaring services</h2>
354<p>To declare that a component provides a service, add a new service to your primitive component type.<br>
355The Service object can be configured. By default, it exposed every implemented interface (regular iPOJO behavior). So, you can:</p>
356<ul>
357 <li>Add service property</li>
358 <li>Set the creation strategy</li>
359 <li>Set the exposed service specifications</li>
360</ul>
361
362
363<div class="code">
364<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(org.example.service.impl.MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addService(new&nbsp;Service()&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addProperty(new&nbsp;ServiceProperty()&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setField(<span class="string">"myServiceProperty"</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setName(<span class="string">"sample.myProperty"</span><span>))&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setCreationStrategy(Service.INSTANCE_STRATEGY))&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
365 .setBundleContext(context)
366 .setClassName(org.example.service.impl.MyComponentImpl.class.getName())
367 .addService(new Service()
368 .addProperty(new ServiceProperty()
369 .setField("myServiceProperty")
370 .setName("sample.myProperty"))
371 .setCreationStrategy(Service.INSTANCE_STRATEGY))
372 .createInstance();</textarea>
373<script class="javascript">
374 if(!window.newcodemacro_initialised)
375 {
376 window.newcodemacro_initialised = true;
377 window.oldonloadmethod = window.onload;
378 window.onload = function(){
379 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
380 if(window.oldonloadmethod)
381 {
382 window.oldonloadmethod();
383 }
384 }
385 }
386
387</script>
388</div>
389
390
391<h2><a name="apache-felix-ipojo-api-ServiceDependencies"></a>Service Dependencies</h2>
392<p>To declare a service dependency, create and add a Dependency object.
393The dependency object offers all the iPOJO service dependency features.
394You can set the injected field and/or bind/unbind methods. Here is an
395example:</p>
396<div class="code">
397<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(org.example.service.impl.MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addDependency(&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;Dependency().setField(<span class="string">"myFoo"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setOptional(<span class="keyword">true</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setDefaultImplementation(<span class="string">"org.sample.FooDefaultImplementation"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
398 .setBundleContext(context)
399 .setClassName(org.example.service.impl.MyComponentImpl.class.getName())
400 .addDependency(
401 new Dependency().setField("myFoo")
402 .setOptional(true)
403 .setDefaultImplementation("org.sample.FooDefaultImplementation")
404 )
405 .createInstance();</textarea>
406<script class="javascript">
407 if(!window.newcodemacro_initialised)
408 {
409 window.newcodemacro_initialised = true;
410 window.oldonloadmethod = window.onload;
411 window.onload = function(){
412 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
413 if(window.oldonloadmethod)
414 {
415 window.oldonloadmethod();
416 }
417 }
418 }
419
420</script>
421</div>
422
423
424<h2><a name="apache-felix-ipojo-api-Properties"></a>Properties</h2>
425<p>Thanks to the <tt>addProperty</tt> method, you can create component properties. Here is some example of properties:</p>
426<div class="code">
427<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addProperty(new&nbsp;Property()&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setField(<span class="string">"myProperty"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setValue(<span class="string">"default-value"</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.addProperty(new&nbsp;Property()&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setMethod(<span class="string">"setMethod"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setName(<span class="string">"prop"</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
428 .setBundleContext(context)
429 .setClassName(MyComponentImpl.class.getName())
430 .addProperty(new Property()
431 .setField("myProperty")
432 .setValue("default-value")
433 )
434 .addProperty(new Property()
435 .setMethod("setMethod")
436 .setName("prop")
437 )
438 .createInstance();</textarea>
439<script class="javascript">
440 if(!window.newcodemacro_initialised)
441 {
442 window.newcodemacro_initialised = true;
443 window.oldonloadmethod = window.onload;
444 window.onload = function(){
445 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
446 if(window.oldonloadmethod)
447 {
448 window.oldonloadmethod();
449 }
450 }
451 }
452
453</script>
454</div>
455
456
457<h2><a name="apache-felix-ipojo-api-TemporalDependencies"></a>Temporal Dependencies</h2>
458<p>Temporal dependencies are also supported: </p>
459<div class="code">
460<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addDependency(&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new&nbsp;TemporalDependency().setField(<span class="string">"myFoo"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setOnTimeoutPolicy(TemporalDependency.NULLABLE)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setTimeout(3000)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setProxy(<span class="keyword">true</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">new PrimitiveComponentType()
461 .setBundleContext(context)
462 .setClassName(MyComponentImpl.class.getName())
463 .addDependency(
464 new TemporalDependency().setField("myFoo")
465 .setOnTimeoutPolicy(TemporalDependency.NULLABLE)
466 .setTimeout(3000)
467 .setProxy(true)
468 )
469 .createInstance();</textarea>
470<script class="javascript">
471 if(!window.newcodemacro_initialised)
472 {
473 window.newcodemacro_initialised = true;
474 window.oldonloadmethod = window.onload;
475 window.onload = function(){
476 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
477 if(window.oldonloadmethod)
478 {
479 window.oldonloadmethod();
480 }
481 }
482 }
483
484</script>
485</div>
486
487
488<h2><a name="apache-felix-ipojo-api-Instancecreation"></a>Instance creation</h2>
489<p>The API allows you to create instances from the component type you described. Three differents methods.<br>
490The <tt>createInstance()</tt> method just creates an instance. The <tt>createInstance(String name)</tt> method allows to set the instance name. Finally, the <tt>createInstance(Dictionary configuration)</tt>
491allows setting the instance configuration. All those methods returns
492the ComponentInstance object allowing to manage the instance (stop,
493start, dispose). </p>
494
495<h2><a name="apache-felix-ipojo-api-ManagedServiceandPropagation"></a>Managed Service and Propagation</h2>
496<p>You can enable/disable the property propagation thanks to the <tt>setPropagation</tt> method on the PrimitiveComponentType object. <br>
497You can also set the the managed service PID with the <tt>setManagedServicePID</tt>
498method. This method should be only use to give a default value of for
499singleton component. In all other case, the managed service pid has to
500be provided inside the instance configuration.</p>
501
502<h2><a name="apache-felix-ipojo-api-ManagingiPOJOFactory"></a>Managing iPOJO Factory</h2>
503<p>Beyond the PrimitiveComponentType, an iPOJO factory is hidden. You can configure this factory to be public or private with the <tt>setPublic</tt> method. You can also set the name of the factory with the <tt>setName</tt> method. </p>
504
505<p>Then, you can access to the Factory object by calling the <tt>getFactory</tt> method.</p>
506
507<h2><a name="apache-felix-ipojo-api-AccesstotheintrospectionAPI"></a>Access to the introspection API</h2>
508<p>The API provides bridge to get access to the iPOJO introspection
509API. The introspection API allows reconfiguring at runtime an instance
510(properties, service dependencies...). From Service and Dependency,
511Property and ServiceProperty objects, call the <tt>getXXXDescription</tt>
512method. You must give the instance that you want to introspect in
513argument. If the lookup success, you get an object allowing
514reconfiguring the service, dependency or property. </p>
515
516<h2><a name="apache-felix-ipojo-api-SingletonComponentType"></a>Singleton Component Type</h2>
517<p>If you are sure to create only one instance of your component type,
518you can use the singleton component type class. This is a kind of
519primitive component type, but when you start it (with the <tt>create</tt> method), it will automatically create an instance.</p>
520<div class="code">
521<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>PrimitiveComponentType&nbsp;type&nbsp;=&nbsp;new&nbsp;SingletonComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(org.example.service.impl.MyComponentImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addDependency(new&nbsp;Dependency().setField(<span class="string">"myFoo"</span><span>))&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setValidateMethod(<span class="string">"start"</span><span>);&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((SingletonComponentType)&nbsp;type)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setObject(new&nbsp;MyComponentImpl(5))&nbsp;<span class="comment">//&nbsp;Inject&nbsp;a&nbsp;pojo&nbsp;object</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.create();<span class="comment">//&nbsp;Create&nbsp;an&nbsp;instance</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">PrimitiveComponentType type = new SingletonComponentType()
522 .setBundleContext(context)
523 .setClassName(org.example.service.impl.MyComponentImpl.class.getName())
524 .addDependency(new Dependency().setField("myFoo"))
525 .setValidateMethod("start");
526
527 ((SingletonComponentType) type)
528 .setObject(new MyComponentImpl(5)) // Inject a pojo object
529 .create();// Create an instance</textarea>
530<script class="javascript">
531 if(!window.newcodemacro_initialised)
532 {
533 window.newcodemacro_initialised = true;
534 window.oldonloadmethod = window.onload;
535 window.onload = function(){
536 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
537 if(window.oldonloadmethod)
538 {
539 window.oldonloadmethod();
540 }
541 }
542 }
543
544</script>
545</div>
546
547
548<p>The type created with the singleton component type are set to <tt>private</tt> by default. Instead of calling the <tt>start</tt> method, you have to call one of the <tt>create</tt> methods to start the type and create the instance.</p>
549
550<p>You can also set the contained POJO object by using the <tt>setObject</tt> method. The given object MUST be compatible with the component implementation class.</p>
551
552<h2><a name="apache-felix-ipojo-api-Usingexternalhandlers"></a>Using external handlers</h2>
553<p>iPOJO is extensible... So, it makes sense that the API is also
554extensible. So component type provides a method allowing to add
555external handler configuration:</p>
556<div class="code">
557<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">return</span><span>&nbsp;new&nbsp;PrimitiveComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setClassName(HostImpl.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addHandler(new&nbsp;Whiteboard()&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.onArrival(<span class="string">"arrival"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.onDeparture(<span class="string">"departure"</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setFilter(<span class="string">"(foo=foo)"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">return new PrimitiveComponentType()
558 .setBundleContext(context)
559 .setClassName(HostImpl.class.getName())
560 .addHandler(new Whiteboard()
561 .onArrival("arrival")
562 .onDeparture("departure")
563 .setFilter("(foo=foo)")
564 );</textarea>
565<script class="javascript">
566 if(!window.newcodemacro_initialised)
567 {
568 window.newcodemacro_initialised = true;
569 window.oldonloadmethod = window.onload;
570 window.onload = function(){
571 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
572 if(window.oldonloadmethod)
573 {
574 window.oldonloadmethod();
575 }
576 }
577 }
578
579</script>
580</div>
581
582
583<p>The <tt>addHandler</tt> method allows you to add any handler description. A handler description is an object of a class implementing <tt>org.apache.felix.ipojo.api.HandlerConfiguration</tt>. Handler provider willing to support the API have to provide this class. For example, the example above uses <tt>Whiteboard</tt> that is the Whiteboard pattern handler description. This class is very simple, and is shown below:</p>
584<div class="code">
585<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span></span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">class</span><span>&nbsp;Whiteboard&nbsp;</span><span class="keyword">implements</span><span>&nbsp;HandlerConfiguration&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">final</span><span>&nbsp;String&nbsp;NAME&nbsp;=&nbsp;</span><span class="string">"wbp"</span><span>;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;</span><span class="keyword">static</span><span>&nbsp;</span><span class="keyword">final</span><span>&nbsp;String&nbsp;NAMESPACE&nbsp;=&nbsp;</span><span class="string">"org.apache.felix.ipojo.whiteboard"</span><span>;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;String&nbsp;arrival;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;String&nbsp;departure;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;String&nbsp;modification;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;String&nbsp;filter;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Whiteboard&nbsp;onArrival(String&nbsp;method)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arrival&nbsp;=&nbsp;method;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Whiteboard&nbsp;onDeparture(String&nbsp;method)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;departure&nbsp;=&nbsp;method;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Whiteboard&nbsp;onModification(String&nbsp;method)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;modification&nbsp;=&nbsp;method;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Whiteboard&nbsp;setFilter(String&nbsp;fil)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter&nbsp;=&nbsp;fil;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;</span><span class="keyword">this</span><span>;&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">public</span><span>&nbsp;Element&nbsp;getElement()&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ensureValidity();&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Create&nbsp;the&nbsp;root&nbsp;element.</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;element&nbsp;=&nbsp;new&nbsp;Element(NAME,&nbsp;NAMESPACE);&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Mandatory&nbsp;attributes</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element.addAttribute(new&nbsp;Attribute(<span class="string">"onArrival"</span><span>,&nbsp;arrival));&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element.addAttribute(new&nbsp;Attribute(<span class="string">"onDeparture"</span><span>,&nbsp;departure));&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element.addAttribute(new&nbsp;Attribute(<span class="string">"filter"</span><span>,&nbsp;filter));&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">//&nbsp;Optional&nbsp;attribute</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(modification&nbsp;!=&nbsp;</span><span class="keyword">null</span><span>)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element.addAttribute(new&nbsp;Attribute(<span class="string">"onModification"</span><span>,&nbsp;modification));&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">return</span><span>&nbsp;element;&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;ensureValidity()&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(arrival&nbsp;==&nbsp;</span><span class="keyword">null</span><span>)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">throw</span><span>&nbsp;new&nbsp;IllegalStateException(</span><span class="string">"The&nbsp;whiteboard&nbsp;pattern&nbsp;configuration&nbsp;must&nbsp;have&nbsp;a&nbsp;onArrival&nbsp;method"</span><span>);&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(departure&nbsp;==&nbsp;</span><span class="keyword">null</span><span>)&nbsp;{&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">throw</span><span>&nbsp;new&nbsp;IllegalStateException(</span><span class="string">"The&nbsp;whiteboard&nbsp;pattern&nbsp;configuration&nbsp;must&nbsp;have&nbsp;a&nbsp;onDeparture&nbsp;method"</span><span>);&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span><span>&nbsp;(filter&nbsp;==&nbsp;</span><span class="keyword">null</span><span>)&nbsp;{&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">throw</span><span>&nbsp;new&nbsp;IllegalStateException(</span><span class="string">"The&nbsp;whiteboard&nbsp;pattern&nbsp;configuration&nbsp;must&nbsp;have&nbsp;a&nbsp;filter"</span><span>);&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">public class Whiteboard implements HandlerConfiguration {
586
587 public static final String NAME = "wbp";
588
589 public static final String NAMESPACE = "org.apache.felix.ipojo.whiteboard";
590
591 private String arrival;
592
593 private String departure;
594
595 private String modification;
596
597 private String filter;
598
599 public Whiteboard onArrival(String method) {
600 arrival = method;
601 return this;
602 }
603
604 public Whiteboard onDeparture(String method) {
605 departure = method;
606 return this;
607 }
608
609 public Whiteboard onModification(String method) {
610 modification = method;
611 return this;
612 }
613
614 public Whiteboard setFilter(String fil) {
615 filter = fil;
616 return this;
617 }
618
619 public Element getElement() {
620 ensureValidity();
621 // Create the root element.
622 Element element = new Element(NAME, NAMESPACE);
623 // Mandatory attributes
624 element.addAttribute(new Attribute("onArrival", arrival));
625 element.addAttribute(new Attribute("onDeparture", departure));
626 element.addAttribute(new Attribute("filter", filter));
627
628 // Optional attribute
629 if (modification != null) {
630 element.addAttribute(new Attribute("onModification", modification));
631 }
632
633 return element;
634 }
635
636 private void ensureValidity() {
637 if (arrival == null) {
638 throw new IllegalStateException("The whiteboard pattern configuration must have a onArrival method");
639 }
640 if (departure == null) {
641 throw new IllegalStateException("The whiteboard pattern configuration must have a onDeparture method");
642 }
643 if (filter == null) {
644 throw new IllegalStateException("The whiteboard pattern configuration must have a filter");
645 }
646
647 }</textarea>
648<script class="javascript">
649 if(!window.newcodemacro_initialised)
650 {
651 window.newcodemacro_initialised = true;
652 window.oldonloadmethod = window.onload;
653 window.onload = function(){
654 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
655 if(window.oldonloadmethod)
656 {
657 window.oldonloadmethod();
658 }
659 }
660 }
661
662</script>
663</div>
664
665
666<p>The only required method is <tt>getElement</tt> returning the
667Element-Attribute structure representing the handler configuration
668(this uses the internal iPOJO data format). If the metadata cannot be
669generated, the class throws IllegalStateExceptions.</p>
670
671<h2><a name="apache-felix-ipojo-api-CreatingcompositionwiththeAPI"></a>Creating composition with the API</h2>
672<p>The API also allows you to create iPOJO compositions in a pretty simple way. So you can create compositions:</p>
673<ul>
674 <li>containing internal instances</li>
675 <li>importing services</li>
676 <li>instantiating sub-services</li>
677 <li>exporting services</li>
678 <li>providing services (by delegation)</li>
679</ul>
680
681
682<p>Here are some examples:</p>
683<div class="code">
684<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>PrimitiveComponentType&nbsp;prov&nbsp;=&nbsp;createAProvider();&nbsp;</span><span class="comment">//&nbsp;Create&nbsp;a&nbsp;primitive&nbsp;type</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;PrimitiveComponentType&nbsp;cons&nbsp;=&nbsp;createAConsumer();&nbsp;<span class="comment">//&nbsp;Create&nbsp;another&nbsp;primitive&nbsp;type</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CompositeComponentType&nbsp;type&nbsp;=&nbsp;new&nbsp;CompositeComponentType()&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setComponentTypeName(<span class="string">"comp1"</span><span>)&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addInstance(new&nbsp;Instance(prov.getFactory().getName()))&nbsp;<span class="comment">//&nbsp;Create&nbsp;an&nbsp;instance&nbsp;in&nbsp;the&nbsp;composite</span><span>&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addInstance(new&nbsp;Instance(cons.getFactory().getName()));&nbsp;&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ComponentInstance&nbsp;ci&nbsp;=&nbsp;type.createInstance();&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">PrimitiveComponentType prov = createAProvider(); // Create a primitive type
685 PrimitiveComponentType cons = createAConsumer(); // Create another primitive type
686
687 CompositeComponentType type = new CompositeComponentType()
688 .setBundleContext(context)
689 .setComponentTypeName("comp1")
690 .addInstance(new Instance(prov.getFactory().getName())) // Create an instance in the composite
691 .addInstance(new Instance(cons.getFactory().getName()));
692
693 ComponentInstance ci = type.createInstance();</textarea>
694<script class="javascript">
695 if(!window.newcodemacro_initialised)
696 {
697 window.newcodemacro_initialised = true;
698 window.oldonloadmethod = window.onload;
699 window.onload = function(){
700 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
701 if(window.oldonloadmethod)
702 {
703 window.oldonloadmethod();
704 }
705 }
706 }
707
708</script>
709</div>
710
711<div class="code">
712<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>CompositeComponentType&nbsp;type&nbsp;=&nbsp;new&nbsp;CompositeComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setComponentTypeName(<span class="string">"comp3"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addSubService(new&nbsp;InstantiatedService()&nbsp;<span class="comment">//&nbsp;Importation</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setSpecification(Foo.<span class="keyword">class</span><span>.getName())&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setOptional(<span class="keyword">true</span><span>));&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">CompositeComponentType type = new CompositeComponentType()
713 .setBundleContext(context)
714 .setComponentTypeName("comp3")
715 .addSubService(new InstantiatedService() // Importation
716 .setSpecification(Foo.class.getName())
717 .setOptional(true));</textarea>
718<script class="javascript">
719 if(!window.newcodemacro_initialised)
720 {
721 window.newcodemacro_initialised = true;
722 window.oldonloadmethod = window.onload;
723 window.onload = function(){
724 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
725 if(window.oldonloadmethod)
726 {
727 window.oldonloadmethod();
728 }
729 }
730 }
731
732</script>
733</div>
734
735<div class="code">
736<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>CompositeComponentType&nbsp;type&nbsp;=&nbsp;new&nbsp;CompositeComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setComponentTypeName(<span class="string">"comp2"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addSubService(new&nbsp;InstantiatedService()&nbsp;&nbsp;<span class="comment">//&nbsp;Instantiated&nbsp;service</span><span>&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setSpecification(Foo.<span class="keyword">class</span><span>.getName()))&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addInstance(new&nbsp;Instance(cons.getFactory().getName()));&nbsp;</td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">CompositeComponentType type = new CompositeComponentType()
737 .setBundleContext(context)
738 .setComponentTypeName("comp2")
739 .addSubService(new InstantiatedService() // Instantiated service
740 .setSpecification(Foo.class.getName()))
741 .addInstance(new Instance(cons.getFactory().getName()));</textarea>
742<script class="javascript">
743 if(!window.newcodemacro_initialised)
744 {
745 window.newcodemacro_initialised = true;
746 window.oldonloadmethod = window.onload;
747 window.onload = function(){
748 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
749 if(window.oldonloadmethod)
750 {
751 window.oldonloadmethod();
752 }
753 }
754 }
755
756</script>
757</div>
758
759<div class="code">
760<div class="dp-highlighter"><table class="dp-c" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="line1"><span>CompositeComponentType&nbsp;type&nbsp;=&nbsp;new&nbsp;CompositeComponentType()&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setBundleContext(context)&nbsp;</td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setComponentTypeName(<span class="string">"compExport"</span><span>)&nbsp;</span></td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addSubService(new&nbsp;InstantiatedService().setSpecification(Foo.<span class="keyword">class</span><span>.getName()))&nbsp;</span></td></tr><tr><td class="line1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.addService(new&nbsp;ExportedService()&nbsp;</td></tr><tr><td class="line2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setSpecification(Foo.<span class="keyword">class</span><span>.getName()));&nbsp;</span><span class="comment">//&nbsp;Exports&nbsp;a&nbsp;service</span><span>&nbsp;</span></td></tr></tbody></table></div><textarea style="display: none;" name="newcodemacro" class="java:nocontrols:nogutter" rows="10" readonly="readonly">CompositeComponentType type = new CompositeComponentType()
761 .setBundleContext(context)
762 .setComponentTypeName("compExport")
763 .addSubService(new InstantiatedService().setSpecification(Foo.class.getName()))
764 .addService(new ExportedService()
765 .setSpecification(Foo.class.getName())); // Exports a service</textarea>
766<script class="javascript">
767 if(!window.newcodemacro_initialised)
768 {
769 window.newcodemacro_initialised = true;
770 window.oldonloadmethod = window.onload;
771 window.onload = function(){
772 dp.SyntaxHighlighter.HighlightAll('newcodemacro');
773 if(window.oldonloadmethod)
774 {
775 window.oldonloadmethod();
776 }
777 }
778 }
779
780</script>
781</div>
782
783<p><br clear="all"></p>
784
785 </div>
786 <img src="apache-felix-ipojo-api_files/footer.png" class="footer">
787</div>
788
789<script type="text/javascript">
790var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
791document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
792</script><script src="apache-felix-ipojo-api_files/ga.js" type="text/javascript"></script>
793<script type="text/javascript">
794try{
795var pageTracker = _gat._getTracker("UA-1518442-4");
796pageTracker._trackPageview();
797} catch(err) {}
798</script>
799
800 </div>
801 </body><div FirebugVersion="1.4.0" style="display: none;" id="_firebugConsole"></div></html>