summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/java-sca-extension-guide.html
blob: ddd87b18d992e5b82d4c793676a0b3823c23a36b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <HEAD>
    <LINK type="text/css" rel="stylesheet" href="resources/space.css">
    <STYLE type="text/css">
      .footer {
        background-image:      url('http://cwiki.apache.org/confluence/images/border/border_bottom.gif');
        background-repeat:     repeat-x;
        background-position:   left top;
        padding-top:           4px;
        color:                 #666;
      }
    </STYLE>
    <SCRIPT type="text/javascript" language="javascript">
      var hide = null;
      var show = null;
      var children = null;

      function init() {
        /* Search form initialization */
        var form = document.forms['search'];
        if (form != null) {
          form.elements['domains'].value = location.hostname;
          form.elements['sitesearch'].value = location.hostname;
        }

        /* Children initialization */
        hide = document.getElementById('hide');
        show = document.getElementById('show');
        children = document.all != null ?
                   document.all['children'] :
                   document.getElementById('children');
        if (children != null) {
          children.style.display = 'none';
          show.style.display = 'inline';
          hide.style.display = 'none';
        }
      }

      function showChildren() {
        children.style.display = 'block';
        show.style.display = 'none';
        hide.style.display = 'inline';
      }

      function hideChildren() {
        children.style.display = 'none';
        show.style.display = 'inline';
        hide.style.display = 'none';
      }
    </SCRIPT>
    <TITLE>Java SCA Extension Guide</TITLE>
  <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
  <BODY onload="init()">
    <TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
      <TR class="topBar">
        <TD align="left" valign="middle" class="topBarDiv" nowrap="">
          &nbsp;<A href="home.html" title="Apache Tuscany">Apache Tuscany</A>&nbsp;&gt;&nbsp;<A href="home.html" title="Home">Home</A>&nbsp;&gt;&nbsp;<A href="java-sca-subproject.html" title="Java SCA Subproject">Java SCA Subproject</A>&nbsp;&gt;&nbsp;<A href="java-sca-menu.html" title="Java SCA Menu">Java SCA Menu</A>&nbsp;&gt;&nbsp;<A href="" title="Java SCA Extension Guide">Java SCA Extension Guide</A>
        </TD>
        <TD align="right" valign="middle" nowrap="">
          <FORM name="search" action="http://www.google.com/search" method="get">
            <INPUT type="hidden" name="ie" value="UTF-8">
            <INPUT type="hidden" name="oe" value="UTF-8">
            <INPUT type="hidden" name="domains" value="">
            <INPUT type="hidden" name="sitesearch" value="">
            <INPUT type="text" name="q" maxlength="255" value="">        
            <INPUT type="submit" name="btnG" value="Google Search">
          </FORM>
        </TD>
      </TR> 
    </TABLE>

    <DIV id="PageContent">
      <DIV class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <DIV style="margin: 0px 10px 0px 10px" class="smalltext">Apache Tuscany</DIV>
        <DIV style="margin: 0px 10px 8px 10px" class="pagetitle">Java SCA Extension Guide</DIV>

        <DIV class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
          <A href="http://cwiki.apache.org/confluence/pages/editpage.action?pageId=51879">
            <IMG src="http://cwiki.apache.org/confluence/images/icons/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
            <A href="http://cwiki.apache.org/confluence/pages/editpage.action?pageId=51879">Edit Page</A>
          &nbsp;
          <A href="http://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANY">
            <IMG src="http://cwiki.apache.org/confluence/images/icons/browse_space.gif" height="16" width="16" border="0" align="absmiddle" title="Browse Space"></A>
            <A href="http://cwiki.apache.org/confluence/pages/listpages.action?key=TUSCANY">Browse Space</A>
          &nbsp;
          <A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANY&fromPageId=51879">
            <IMG src="http://cwiki.apache.org/confluence/images/icons/add_page_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add Page"></A>
          <A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANY&fromPageId=51879">Add Page</A>
          &nbsp;
          <A href="http://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANY&fromPageId=51879">
            <IMG src="http://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif" height="16" width="16" border="0" align="absmiddle" title="Add News"></A>
          <A href="http://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=TUSCANY&fromPageId=51879">Add News</A>
        </DIV>
      </DIV>
      <DIV class="pagesubheading" style="margin: 0px 10px 0px 10px;">
                    Added by     <A href="http://cwiki.apache.org/confluence/display/~rfeng/Index">Raymond Feng</A>, last edited by     <A href="http://cwiki.apache.org/confluence/users/viewuserprofile.action?username=edwardsmj">Mike Edwards</A> on May 03, 2007
                      &nbsp;(<A href="http://cwiki.apache.org/confluence/pages/diffpages.action?pageId=51879&originalId=53223">view change</A>)
              
      </DIV>

      <DIV class="pagecontent">
        <DIV class="wiki-content">
          <DIV class="panel" style="border-style: solid; border-color: #6699ff; "><DIV class="panelHeader" style="border-bottom-style: solid; border-bottom-color: #6699ff; background-color: #D5EFFF; "><B>Apache Tuscany SCA Java Extension Guide</B></DIV><DIV class="panelContent" style="background-color: #ffffff; ">
<P><B>This page is work in progress. Thanks for your contribution</B> <IMG class="emoticon" src="http://cwiki.apache.org/confluence/images/icons/emoticons/smile.gif" height="20" width="20" align="absmiddle" alt="" border="0"><BR>
This is a guide for developers who would like to extend Tuscany SCA Java.</P>
<UL>
	<LI><A href="#JavaSCAExtensionGuide-extension" title="extension on Java SCA Extension Guide">What is an extension?</A></LI>
	<LI><A href="#JavaSCAExtensionGuide-component" title="component on Java SCA Extension Guide">How to add a new component implementation? </A></LI>
	<LI><A href="#JavaSCAExtensionGuide-binding" title="binding on Java SCA Extension Guide">How to add a new binding? </A></LI>
	<LI><A href="#JavaSCAExtensionGuide-interface" title="interface on Java SCA Extension Guide">How to add a new interface binding? </A></LI>
</UL>


<UL>
	<LI><A href="#JavaSCAExtensionGuide-databinding" title="databinding on Java SCA Extension Guide">How to add a databinding </A></LI>
	<LI><A href="#JavaSCAExtensionGuide-generalguide" title="general guide on Java SCA Extension Guide">General guide for developing extensions</A></LI>
	<LI><A href="#JavaSCAExtensionGuide-details" title="details on Java SCA Extension Guide">Details on extension architecture</A> <B>can move to architecture doc</B>
<BR clear="all">
&nbsp;</LI>
</UL>
</DIV></DIV>
<TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR></TR></TBODY></TABLE>

<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-extension"></A><FONT color="#0099cc">What is an extension?</FONT></H3>

<P>Extension is a module (or a set of modules),when built with Tuscany SCA, can extend it to work with additional bindings, language implementations, programming models or databindings.</P>

<P>SCA assembly model is defined such that extensions can be added for new interface types or for new implementation types such as ruby and python, or new binding types such as CXF. However, the definition of extension SPIs is left to the implementor. Tuscany SCA Java provides a simple set of SPIs for implementing extensions. It also defines additional extension points such as data binding, for example support for SDO and JAXB.</P>

<P>This guide explains the steps to add each of these extension types. Please help us refine the guide as you go through the steps of adding extensions.</P>

<H4><A name="JavaSCAExtensionGuide-Namespacesusedbyextensions"></A>Name spaces used by extensions</H4>


<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-component"></A><FONT color="#0099cc">How to add a new component implementation?</FONT></H3>

<P><A href="mike-edwards-ramble-through-adding-a-new-component-type.html" title="Mike Edwards Ramble through Adding a New Component Type">Musings on Adding a New Component Type by Mike E</A>&nbsp;</P>

<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-binding"></A><FONT color="#0099cc">How to add a new binding?</FONT></H3>


<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-interface"></A><FONT color="#0099cc">How to add a new interface binding?</FONT></H3>


<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-databinding"></A><FONT color="#0099cc">How to add a new databinding?</FONT></H3>


<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-generalguide"></A><FONT color="#0099cc">General guide for developing extensions</FONT></H3>

<UL>
	<LI>Familiarize yourself with SCA 1.0 Assembly and the SCA Java 1.0 programming model. Specifications can be found at www.osoa.org.</LI>
	<LI>Never reference any classes in core. These classes are implementation-specific and subject to change; they are not part of the public SPI contract.</LI>
	<LI>Use autowire when assembling extension components.</LI>
	<LI>Do not play with classloaders such as setting the current context classloader unless it is absolutely necessary, i.e. a library used by an extension makes assumptions about context classloaders. Ideally the library can be refactored to not make these assumptions. If not, make sure the extension properly resets the current context classloader.</LI>
</UL>


<H3><A name="JavaSCAExtensionGuide-"></A><A name="JavaSCAExtensionGuide-details"></A><FONT color="#0099cc">Detail on extension architecture</FONT></H3>


<H4><A name="JavaSCAExtensionGuide-TheExtensionPointRegistry"></A>The ExtensionPointRegistry</H4>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java"><SPAN class="code-keyword">package</SPAN> org.apache.tuscany.core;

/**
 * The registry <SPAN class="code-keyword">for</SPAN> the Tuscany core extension points.
 *
 * @version $Rev: 529327 $ $Date: 2007-04-16 10:10:43 -0700 (Mon, 16 Apr 2007) $
 */
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> ExtensionPointRegistry {

    /**
     * Add an extension point to the registry
     * @param &lt;T&gt;
     * @param extensionPointType The <SPAN class="code-keyword">interface</SPAN> of the extension point
     * @param extensionPoint The instance of the extension point
     */
    &lt;T&gt; void addExtensionPoint(<SPAN class="code-object">Class</SPAN>&lt;T&gt; extensionPointType, T extensionPoint);

    /**
     * Get the extension point by the <SPAN class="code-keyword">interface</SPAN>
     * @param &lt;T&gt;
     * @param extensionPointType
     * @<SPAN class="code-keyword">return</SPAN>
     */
    &lt;T&gt; T getExtensionPoint(<SPAN class="code-object">Class</SPAN>&lt;T&gt; extensionPointType);

    /**
     * Remove an extension point
     * @param extensionPoint
     */
    void removeExtensionPoint(<SPAN class="code-object">Class</SPAN> extensionPoint);
}</PRE>
</DIV></DIV>

<H4><A name="JavaSCAExtensionGuide-TheModuleActivator"></A>The ModuleActivator</H4>

<DIV class="code"><DIV class="codeContent">
<PRE class="code-java"><SPAN class="code-keyword">package</SPAN> org.apache.tuscany.core;

<SPAN class="code-keyword">import</SPAN> java.util.Map;

/**
 * ModuleActivator represents a module that plugs into the Tuscany system. Each module should
 * provide an implementation of <SPAN class="code-keyword">this</SPAN> <SPAN class="code-keyword">interface</SPAN> and registry the implementation class by defining
 * a file named as <SPAN class="code-quote">&quot;META-INF/services/org.apache.tuscany.spi.bootstrp.ModuleActivator&quot;</SPAN>. The
 * content of the file is the class name of the implementation. The implementation class must
 * have a no-arg constructor. The same instance will be used to invoke all the methods during
 * different phases of the module activation.
 *
 * @version $Rev: 529327 $ $Date: 2007-04-16 10:10:43 -0700 (Mon, 16 Apr 2007) $
 */
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">interface</SPAN> ModuleActivator {
    /**
     * Get a map of the extension points defined by <SPAN class="code-keyword">this</SPAN> module. The key is the
     * java <SPAN class="code-keyword">interface</SPAN> to represent the extension point and the the value is the
     * instance of the implementation of the <SPAN class="code-keyword">interface</SPAN>.
     *
     * @<SPAN class="code-keyword">return</SPAN> All the extension points defined by <SPAN class="code-keyword">this</SPAN> module
     */
    Map&lt;<SPAN class="code-object">Class</SPAN>, <SPAN class="code-object">Object</SPAN>&gt; getExtensionPoints();

    /**
     * This method is invoked when the module is started by the Tuscany system.
     * It can be used by <SPAN class="code-keyword">this</SPAN> module to registr extensions against extension
     * points.
     *
     * @param registry The extension point registry
     */
    void start(ExtensionPointRegistry registry);

    /**
     * This method is invoked when the module is stopped by the Tuscany system.
     * It can be used by <SPAN class="code-keyword">this</SPAN> module to unregister extensions against the
     * extension points.
     *
     * @param registry The extension point registry
     */
    void stop(ExtensionPointRegistry registry);
}</PRE>
</DIV></DIV>
<P>The ModuleActivator represents a module that plugs into the Tuscany system.<BR>
Each module should provide an implementation <SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANY&title=3&linkCreation=true&fromPageId=51879" title="Create Page: 3" class="createlink">3<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN> of this interface and<BR>
registry the implementation class by defining a file named as<BR>
&quot;META-INF/services/org.apache.tuscany.spi.bootstrp.ModuleActivator&quot; <SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=TUSCANY&title=4&linkCreation=true&fromPageId=51879" title="Create Page: 4" class="createlink">4<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN>. The<BR>
content of the file is the class name of the implementation. The<BR>
implementation class must have a no-arg constructor. The same instance will<BR>
be used to invoke all the methods during different phases of the module<BR>
activation.</P>

<P>During bootstraping, the following sequence will happen:</P>

<P>1) All the module activators will be discovered by the presence of<BR>
META-INF/services/org.apache.tuscany.spi.bootstrp.ModuleActivator<BR>
2) The activator class is instantiated using the no-arg constructor.<BR>
3) ModuleActivator.getExtensionPoints() is invoked for all modules and the<BR>
extension points contributed by each module are added to the<BR>
ExtensionRegistry.<BR>
4) ModuleActivator.start(ExtensionRegistry) is invoked for all the modules.<BR>
The module can then get interested extension points and contribute<BR>
extensions to them. The contract bwteen the extension and extension point is<BR>
private to the extension point. The extension point can follow similar<BR>
patterns such as Registry. If it happens that one extension point has a<BR>
dependency on another extension point, they can linked at this phase.</P>

<P>During shutting down, the stop() method is invoked for all the modules to<BR>
perform cleanups. A module can choose to unregister the extension from the<BR>
extension points.</P>
        </DIV>

                  <DIV class="tabletitle">
            Children
            <SPAN class="smalltext" id="show" style="display: inline;">
              <A href="javascript:showChildren()">Show Children</A></SPAN>
            <SPAN class="smalltext" id="hide" style="display: none;">
              <A href="javascript:hideChildren()">Hide Children</A></SPAN>
          </DIV>
          <DIV class="greybox" id="children" style="display: none;">
                                      <A href="mike-edwards-ramble-through-adding-a-new-component-type.html" title="Mike Edwards Ramble through Adding a New Component Type">Mike Edwards Ramble through Adding a New Component Type</A>
              <SPAN class="smalltext">(Apache Tuscany)</SPAN>
              <BR>
                      </DIV>
        
      </DIV>
    </DIV>
    <DIV class="footer">
      Generated by
      <A href="http://www.atlassian.com/confluence/">Atlassian Confluence</A> (Version: 2.2.9 Build: 527 Sep 07, 2006)
      <A href="http://could.it/autoexport/">AutoExport Plugin</A> (Version: Unknown - PluginManager Error)
    </DIV>
  </BODY>
</HTML>