summaryrefslogtreecommitdiffstats
path: root/site/trunk/site-publish/sdo-project-code-structure.html
blob: b77999d6d2c64d5be6c82eacf73772bd156d8130 (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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE- 2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
    <HEAD>
		<!-- generateKeywords macro -->
	    <META name="description" content="Apache Tuscany">
        <META name="keywords" content="apache, apache tuscany, tuscany, service, services, fabric, soa, service oriented architecture,  sca, service component architecture, das, sdo, csa, ruby, opensource">
		<!-- generateKeywords macro end -->
		
        <LINK type="text/css" rel="stylesheet" href="http://tuscany.apache.org/stylesheets/default.css">
        <LINK rel="SHORTCUT ICON" href="https://cwiki.apache.org/confluence/display/TUSCANY/$images/favicon.ico">   
        <TITLE>Apache Tuscany : SDO Project Code Structure</TITLE>
    <META http-equiv="Content-Type" content="text/html;charset=UTF-8"></HEAD>
    
    <BODY onload="init()">
        <!-- topNav macro -->
		<TABLE valign="top" border="0" cellspacing="0" cellpadding="0" width="100%" background="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg">
			<TR>
				<TD valing="top" align="left">
					<A href="https://cwiki.apache.org/confluence/pages/viewpage.action?spaceKey=TUSCANY&title=$siteroot"><IMG src="http://tuscany.apache.org/images/TuscanyLogoNEW_Text_120px_bg.jpg" height="91" width="25" border="0"></A>
				</TD>
				<TD>
					<A href="http://tuscany.apache.org/"><IMG src="http://tuscany.apache.org/images/TuscanyLogo.jpg" border="0"></A>
				</TD>
				
				<TD width="100%">
					&nbsp;
				</TD>

				<!-- Adds the edit page link to the top banner-->
				<TD valign="bottom">
					<DIV style="padding: 2px 10px; margin: 0px;">
						<A href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=48536">
						<IMG src="http://tuscany.apache.org/images/notep_16.gif" height="16" width="16" border="0" align="absmiddle" title="Edit Page"></A>
					</DIV>
				</TD>

			</TR>
		</TABLE>
        <!-- topNav macro end -->

		<!-- breadCrumbs macro -->
		<TABLE border="0" cellpadding="2" cellspacing="0" width="100%">
			<TR class="topBar">
				<TD align="left" valign="middle" class="topBarDiv" nowrap="true" width="100%">
					&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="sdo-overview.html" title="SDO Overview">SDO Overview</A>&nbsp;&gt;&nbsp;<A href="sdo-java.html" title="SDO Java">SDO Java</A>&nbsp;&gt;&nbsp;<A href="developing-sdo-java.html" title="Developing SDO Java">Developing SDO Java</A>&nbsp;&gt;&nbsp;<A href="" title="SDO Project Code Structure">SDO Project Code Structure</A>
				</TD>
				
				<TD align="right" valign="middle" class="topBarDiv" align="left" nowrap="true">
				<A href="http://mail-archives.apache.org/mod_mbox/tuscany-user">User List</A> | <A href="http://mail-archives.apache.org/mod_mbox/tuscany-dev">Dev List</A> | <A href="http://issues.apache.org/jira/browse/Tuscany">Issue Tracker</A>&nbsp;&nbsp;
				</TD>
			</TR>
		</TABLE>
		<!-- breadCrumbs macro end -->


        <TABLE border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
            <TR>
                <TD align="left" valign="top">

					<!-- pageContent macro -->
					<DIV id="PageContent">
												
						<DIV class="pagecontent">
							<DIV class="wiki-content">
								<TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR>
<TD class="confluenceTd" valign="top" width="15%">
<DIV class="panel" style="background-color: #ECF4D1;border-color: #C3CDA1;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #C3CDA1;background-color: #C3CDA1;"><B>General</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="home.html" title="Home">Home</A><BR>
<A href="http://www.apache.org/licenses/LICENSE-2.0.html" class="external-link" rel="nofollow">License </A><BR>
<A href="sdo-java-get-involved.html" title="SDO Java Get Involved">Get Involved</A><BR>
<A href="sdo-java-found-a-bug.html" title="SDO Java Found a Bug">Found a Bug?</A></P>
</DIV></DIV>

<DIV class="panel" style="background-color: #ECF4D1;border-color: #b4b4b5;border-style: solid;border-width: 1px;"><DIV class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: #b4b4b5;background-color: #C3CDA1;"><B>SDO Java</B></DIV><DIV class="panelContent" style="background-color: #ECF4D1;">
<P><A href="sdo-java.html" title="SDO Java">SDO Java Home</A><BR>
<A href="tuscany-sdo-java-faq.html" title="Tuscany SDO Java - FAQ">FAQ</A><BR>
<A href="sdo-java-releases.html" title="SDO Java Releases">Downloads</A><BR>
<A href="sdo-java-documentation-menu.html" title="SDO Java Documentation Menu">Documentation</A><BR>
<A href="http://svn.apache.org/repos/asf/tuscany/sdo-java/trunk/" class="external-link" rel="nofollow">Source Code</A></P>
</DIV></DIV></TD>
<TD class="confluenceTd" valign="top" width="85%">

<H3><A name="SDOProjectCodeStructure-SDOProjectCodeStructure"></A>SDO Project Code Structure</H3>

<P>The code for the Tuscany Java SDO implementation may be found at <A href="http://svn.apache.org/repos/asf/incubator/tuscany/java/" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/incubator/tuscany/java/</A></P>

<P>The SDO project is divided into seven parts, denoted here by the subdirectories of the above link where the code for the projects may be found:</P>

<UL>
	<LI><B>sdo/sdo-api</B> contains the SDO (commonj) interfaces defined and provided by the SDO 2.1 specification.</LI>
	<LI><B>sdo/lib</B> contains the SDO implementation library</LI>
	<LI><B>sdo/impl</B> provides the runtime implementation of the SDO interfaces.</LI>
	<LI><B>sdo/tools</B> contains import and generator tools.</LI>
	<LI><B>sdo/tools-test</B> contains the tests for the SDO Generator Tools and Tool Outputs</LI>
	<LI><B>sdo/sample</B> contains sample sdo code.</LI>
	<LI><B>sdo/plugin</B> contains code to configure the way in which SDO is build by maven.</LI>
</UL>


<P>For each of these projects the implementation source code is located in a sub-directory of the project directory named src/main/java, and if applicable, test (example) classes are located in src/test/java. The directory src/test/resources contains any data files needed by the test programs.</P>

<P><A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sdo/sdo-api" class="external-link" rel="nofollow">sdo/sdo-api</A></P>

<P>This project contains the interfaces provided with the SDO 2.1 specification. It is essentially an unzipped copy of the SDO Java API sources zip file available at <A href="http://osoa.org/download/attachments/36/SDO_2.1.0_Java_source_FINAL.zip?version=1" class="external-link" rel="nofollow">http://osoa.org/download/attachments/36/SDO_2.1.0_Java_source_FINAL.zip?version=1</A>, but with some errata corrections and a Tuscany-specific implementation of class HelperProvider.</P>

<P>The abstract class, HelperProvider, is used to obtain specific default helpers and other implementation-specific objects used by the Java implementation of SDO. In the Tuscany implementation of this class, there are two ways to specify the implementation of the HelperProvider class.</P>

<UL>
	<LI>Set a System Property named &quot;commonj.sdo.impl.HelperProvider&quot; equal to the fully qualified class name of the implementation class (e.g. &quot;commonj.sdo.impl.HelperProvider=org.apache.tuscany.sdo.help.HelperProviderImpl&quot;).</LI>
</UL>


<UL>
	<LI>In your own jar file, create a text file called &quot;META-INF/services/commonj.sdo.impl.HelperProvider&quot;. In this text file, specify the fully qualified custom HelperProvider implementation class (e.g. org.apache.tuscany.sdo.help.HelperProviderImpl).</LI>
</UL>


<P>In the event that both 1 and 2 are specified, the System Property will take precedence over the text file.</P>

<P>The Tuscany default helper provider implementation class is org.apache.tuscany.sdo.helper.HelperProviderImpl (in the sdo.impl project) and is registered using the second technique (services file), as described in the following section.</P>

<P><A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sdo/lib" class="external-link" rel="nofollow">sdo/lib</A></P>

<P>This project contains the library APIs for Tuscany's SDO Implementation and some utility/helper packages. The actual implementation resides in sdo/impl. The user is supposed to use the APIs from sdo/lib instead of making direct references to sdo/impl. Unlike sdo/impl this projest does not reference EMF packages anywhere.</P>

<P><A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sdo/impl" class="external-link" rel="nofollow">sdo/impl</A></P>

<P>The sdo.impl subproject contains a test package under src/test/java (see the section below entitled Static Code Generator for details) and the following implementation packages under src/main/java:</P>

<P><B>package org.apache.tuscany.sdo</B></P>

<P>Contains a few interfaces used by some of the implementation classes in org.apache.tuscany.sdo.impl. (Note: this package is subject to further cleanup.)</P>

<P><B>package org.apache.tuscany.sdo.helper</B></P>

<P>This package contains implementations of the &quot;helper&quot; interfaces defined in the commonj.sdo.helper package (in the sdo.spec project). Each helper interface in commonj.sdo.helper has a corresponding implementation class in this package. The name of each helper class is the same as the corresponding interface, only with the suffix &quot;Impl&quot; appended. For example class org.apache.tuscany.sdo.helper.TypeHelperImpl implements the interface commonj.sdo.TypeHelper.</P>

<P>The implementation class org.apache.tuscany.sdo.helper.HelperProviderImpl is used to bootstrap an implementation of the default INSTANCEs of the SDO helper (see class commonj.sdo.impl.HelperProvider in sdo.spec). This implementation creates instances of the other helper implementation classes in this package and is registered using the services file src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider.</P>

<P><B>package org.apache.tuscany.sdo.impl</B></P>

<P>This package contains the majority of the SDO runtime implementation code. This includes implementations of all of the commonj.sdo interfaces (see sdo.spec), including several implementations of the DataObject interface. The design and implementation of the most important classes in this package are described below).</P>

<P><B>package org.apache.tuscany.sdo.util</B></P>

<P>Contains some utility classes used by the implementation. <B>One class, SDOUtil, is particularly important</B>. It provides some useful static utility functions which are not included in the SDO specification itself. Although these are not &quot;standard&quot; APIs, use of them is recommended, as opposed to resorting to low-level implementation-specific APIs. The intent of this class is to encapsulate, in a relatively clean way, common functions that are needed, and can potentially be proposed for addition to the specification in a future version of SDO.</P>

<P><B><A href="https://svn.apache.org/repos/asf/incubator/tuscany/java/sdo/tools" class="external-link" rel="nofollow">sdo/tools</A></B></P>

<P>This project contains (command line) tools, such as SDO model importers and generators (Java code, XML schema, etc.). Currently however, there is only a single tool, a Java code generator implemented in class org.apache.tuscany.sdo.generate.XSD2JavaGenerator. This generator can be used to generate static SDO data objects and is described in more detail in below.</P>

<P>The sdo-tools project also contains a test program and sample generated model located in src/test/java and src/test/resources respectively (see the tests section below for more details).</P>

<P><B>Dependent Jars</B></P>

<P>The sdo.impl project requires the following EMF (Eclipse Modeling Framework - www.eclipse.org/emf) runtime jars to build:</P>

<P>emf-common-2.2.1-SNAPSHOT.jar - some common framework utility and base classes<BR>
emf-ecore-2.2.1-SNAPSHOT.jar - the EMF core runtime implementation classes (the Ecore metamodel)<BR>
emf-ecore-change-2.2.1-SNAPSHOT.jar - the EMF change recorder and framework<BR>
emf-ecore-xmi-2.2.1-SNAPSHOT.jar - EMF's default XML (and XMI) serializer and loader<BR>
xsd-2.2.1-SNAPSHOT.jar - the XML Schema model</P>

<P>The sdo.tools project also requires the EMF code generator framework jars:</P>

<P>emf-codegen-2.2.1-SNAPSHOT.jar - template-based codegen framework (JET - Java Emitter Templates)<BR>
emf-codegen-ecore-2.2.1-SNAPSHOT.jar - the EMF code generator<BR>
emf-common-2.2.1-SNAPSHOT.jar - some common framework utility and base classes<BR>
emf-ecore-2.2.1-SNAPSHOT.jar - the EMF core runtime implementation classes (the Ecore metamodel)<BR>
emf-ecore-change-2.2.1-SNAPSHOT.jar - the EMF change recorder and framework<BR>
emf-ecore-xmi-2.2.1-SNAPSHOT.jar - EMF's default XML (and XMI) serializer and loader<BR>
xsd-2.2.1-SNAPSHOT.jar - the XML Schema model</P>

<P>These are simply Maven-friendly versions of corresponding jar files/plugins obtained from Eclipse. SNAPSHOT maps to an EMF weekly integration build (for example, I200602160000). Note that if you are building SDO for a released source code distribution then the dependency jars will not be snapshot jars, but will instead themselves be released versions of the dependencies.</P>


<P><B>Runtime Implementation</B></P>

<P>The primary SDO runtime implementation classes are located in the package org.apache.tuscany.sdo.impl and consist of the following:</P>

<UL>
	<LI>DataObject implementation classes</LI>
	<LI>Implementation of the SDO metamodel interfaces: Type and Property</LI>
	<LI>ChangeSummary and DataGraph implementations</LI>
</UL>


<P>The implementation of the SDO runtime is based on and leverages the EMF runtime model (i.e., EObject and the Ecore metamodel - refer to documentation at www.eclipse.org/emf). It subclasses and specializes the Ecore metamodel, and provides its own DataObject-tuned implementation(s) of the EObject interface. The design is described in more detail in the following sections.</P>

<P><B>DataObject implementation classes</B></P>

<P>SDO provides several DataObject implementation classes as shown in the following diagram:</P>

<P><SPAN class="image-wrap" style=""><IMG src="sdo-project-code-structure.data/do_uml.png" style="border: 0px solid black"></SPAN></P>

<P>Class DataObjectImpl is the most important. It provides a complete base implementation of the SDO DataObject interface. It extends from the EMF base class BasicEObjectImpl, which provides the &quot;scaffolding&quot; needed to easily implement an EObject, but without allocating any storage itself.</P>

<P>DataObjectImpl provides the DataObject implementation while allocating only the minimum storage overhead needed to be a data object (e.g., container pointer and feature, change recorder). It does not, however, allocate any storage for the actual properties of the data object. It instead requires subclasses for this purpose. For example, statically generated SDOs (see the generator section below) directly or indirectly extend from this class, providing their own storage in generated instance variables.</P>

<P>The subclass, DynamicDataObjectImpl serves as a concrete implementation class for dynamic data objects. It is the default implementation class used when creating dynamic data objects using the DataFactory.create() method, for example. DynamicDataObjectImpl provides efficient data storage using a dynamically allocated settings array.</P>

<P>StoreDataObjectImpl and DynamicStoreDataObjectImpl provide a delegating implementations for DataObjects that implement their own storage management using a store (see EMF's EStore interface) implementation class. StoreDataObjectImpl is used in conjuction with the &quot;-storePattern&quot; generator option (see section 4), while DynamicStoreDataObjectImpl, as its name implies, is used for dynamic store-based instances.</P>

<P><B>Type and Property implementation classes</B></P>

<P>The SDO implementation provides three implementations of the interface Type, one for each of the following three kinds of types: classes, simple data types, and enumerations.</P>

<UL>
	<LI>class ClassImpl extends EClassImpl implements Type</LI>
	<LI>class DataTypeImpl extends EDataTypeImpl implements Type</LI>
	<LI>class EnumImpl extends EEnumImpl implements Type</LI>
</UL>


<P>For example, class org.apache.tuscany.sdo.impl.ClassImpl extends form the corresponding Ecore class, EClassImpl, and mixes in the SDO interface commonj.sdo.Type. All the Type methods are implemented by calls to super.</P>

<P>With this approach, a data object's Type, returned from DataObjectImpl.getType(), and its EClass, returned by DataObjectImpl.eClass(), are the same underlying meta object. This allows the SDO implementation to leverage any appropriate base functionality without any performance overhead. The arrangement is shown in the following diagram:</P>

<P><SPAN class="image-wrap" style=""><IMG src="sdo-project-code-structure.data/meta.png" style="border: 0px solid black"></SPAN></P>

<P>The implementation of the SDO Property interface follows a similar pattern. Two implementation classes, subclasses of corresponding Ecore classes, mix in the Property interface:</P>

<UL>
	<LI>class AttributeImpl extends EAttributeImpl implements Property</LI>
	<LI>class ReferenceImpl extends EReferenceImpl implements Property</LI>
</UL>


<P>As with the Type implementation classes, these classes call methods on super to implement the mixed-in Property methods.</P>

<P>The following diagram illustrates the design:</P>

<P><SPAN class="image-wrap" style=""><IMG src="sdo-project-code-structure.data/meta2.png" style="border: 0px solid black"></SPAN></P>

<P>As shown, the getProperties() method in ClassImpl (i.e., of the SDO Type interface) returns a set of properties whose implementation classes also implement EAttribute or EReference, and since ClassImpl, extends EClassImpl (as shown in the previous diagram), these are in fact the same objects as those returned by the EClass.getEAllStructuralFeatures() method. The two metamodels are one and the same, making the implementation of many of the SDO APIs trivial calls to the base class.</P>

<P>ChangeSummary and DataGraph implementation classes</P>

<P>TBD.</P>


<P><B>Static Code Generator</B></P>

<P>The SDO static code generator is a command line tool for generating Java source code (static SDOs) for DataObjects defined in an XML Schema. It is implemented by the class org.apache.tuscany.sdo.generate.XSD2JavaGenerator in the sdo.tools project. The generator is used as follows:<BR>
<FONT color="gray"><BR>
Usage arguments:<BR>
<BR>
 [ -targetDirectory &lt;target-root-directory&gt; ]<BR>
 [ -javaPackage &lt;base-package-name&gt; ]<BR>
 [ -prefix &lt;prefix-string&gt; ]<BR>
 [ -sparsePattern | -storePattern ]<BR>
 [ -noInterfaces ] [ -noContainment ] [ -noNotification ] [ -arrayAccessors ] [ -noUnsettable ] [ -noEMF ]<BR>
 &lt;xsd-file&gt; | &lt;wsdl-file&gt;</FONT><BR>
For example:<BR>
<FONT color="gray"><BR>
java XSD2JavaGenerator somedir/somefile.xsd</FONT></P>

<P>Options:</P>

<P>-targetDirectory Generates the Java source code in the specified directory. By default, the code is generated in the same directory as the input xsd or wsdl file.</P>

<P>-javaPackage Overrides the Java package for the generated classes. If not specified, a default package or one specified with an sdoJava:package annotation on the &lt;schema&gt; element in the xsd file (see SDO specification for details) is used for the java package.</P>

<P>-prefix Specifies the prefix string to use for naming the generated factory. For example &quot;-prefix Foo&quot; will result in a factory interface with the name &quot;FooFactory&quot;.</P>

<P>-sparsePattern For SDO metamodels that have classes with many properties of which only a few are typically set at runtime, this option can be used to produce a space-optimized implementation (at the expense of speed).</P>

<P>-storePattern This option can be used to generate static classes that work with a Store-based DataObject implementation. It changes the generator pattern to generate accessors which delegate to the reflective methods (as opposed to the other way around) and changes the DataObject base class to org.apache.tuscany.sdo.impl.StoreDataObjectImpl. Note that this option generates classes that require a Store implementation to be provided before they can be run.</P>

<P>-noInterfaces By default, each DataObject generates both a Java interface and a corresponding implementation class. If an SDO metamodel does not use multiple inheritance (which is always the case for XML Schema derived models), then this option can be used to eliminate the interface and to generate only an implementation class.</P>

<P>-noNotification This option eliminates all change notification overhead in the generated classes. Changes to DataObjects generated using this option cannot be recorded, and consequently the classes cannot be used with an SDO ChangeSummary or DataGraph.</P>

<P>-noContainment Turns off container management for containment properties. DataObject.getContainer() will always return null for data objects generated with this option, even if a containment reference is set. Setting a containment reference will also not automatically remove the target object from its previous container, if it had one, so it will need to be explicitly removed by the client. Use of this option is only recommended for scenarios where this kind of container movement/management is not necessary.</P>

<P>-arrayAccessors <B>Note: this is prototype code and is not fully implemented.</B> Generates Java array getters/setters for multiplicity-many properties. With this option, the set of &quot;standard&quot; JavaBean array accessor methods (e.g., Foo[] getFoo(), Foo getFoo(int), int getFooLength(), setFoo(Foo[]), and void setFoo(int, Foo)) are generated. The normal List-returning accessor is renamed with the suffix &quot;List&quot; (e.g., List getFooList()). The array returned by the generated method is not a copy, but instead a pointer to the underlying storage array, so directly modifying it can have undesirable consequences and should be avoided.</P>

<P>-noUnsettable By default, some XML constructs result in SDO property implementations that maintain additional state information to record when the property has been set to the &quot;default value&quot;, as opposed to being truly unset (see DataObject.isSet() and DataObject.unset()). The SDO specification allows an implementation to choose to provide this behavior or not. With this option, all generated properties will not record their unset state. The generated isSet() methods simply returns whether the current value is equal to the property's &quot;default value&quot;.</P>

<P>-noEMF By default, the generated java implementation source files directly import the Eclipse EMF classes which they depend upon. This can lead to a discrepancy in EMF library level dependencies between the generated classes and the environment into which they are deployed. The -noEmf option provides an early level of function to avoid this situation. Classes generated using this option access EMF function indirectly via inherited behaviour, thereby allowing packaging of these generated classes into jar files which do not directly depend on EMF.</P>

<P>This early implementation of this option is limited in the subset of XML Schema it is known to handle, and is subject to change. The generator is known to be able to deal with Complex content (including content models which map to SDO Sequence), and Mixed content for example .</P>

<P>      &lt;xsd:complexType mixed=&quot;true&quot; name=&quot;Sequence&quot;&gt;<BR>
         &lt;xsd:sequence&gt;<BR>
            &lt;xsd:choice maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot;&gt;<BR>
               &lt;xsd:element name=&quot;a&quot; type=&quot;xsd:string&quot; /&gt;<BR>
               &lt;xsd:element name=&quot;b&quot; type=&quot;xsd:int&quot; /&gt;<BR>
            &lt;/xsd:choice&gt;<BR>
            &lt;xsd:element name=&quot;split&quot; type=&quot;xsd:string&quot; /&gt;<BR>
            &lt;xsd:choice maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot;&gt;<BR>
               &lt;xsd:element name=&quot;y&quot; type=&quot;xsd:string&quot; /&gt;<BR>
               &lt;xsd:element name=&quot;z&quot; type=&quot;xsd:int&quot; /&gt;<BR>
            &lt;/xsd:choice&gt;<BR>
        &lt;/xsd:sequence&gt;<BR>
     &lt;/xsd:complexType&gt;<BR>
Generator Patterns</P>

<P>The DataObject interface generation pattern is as described in the SDO specification (see Java Interface Specification section). The SDO specification does not define a factory pattern for efficient construction of static SDOs, which is however provided by the Tuscany implementation. The generated SDO Factory interface conforms to the following pattern:<BR>
<FONT color="gray">
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>public interface &lt;prefix&gt;Factory {
  &lt;Type1&gt; create&lt;Type1&gt;();
  &lt;Type2&gt; create&lt;Type2&gt;();
  ...
  &lt;prefix&gt;Factory INSTANCE = &lt;default_factory_impl&gt;;
}
</PRE>
</DIV></DIV></FONT></P>


<P>A generated factory corresponds to an SDO Type namespace uri (see commonj.sdo.Type.getURI) with one create() method for each SDO Type in the namespace. The &lt;prefix&gt; of the factory name is derived from the uri. An instance of the factory is available using the INSTANCE field in the interface.</P>

<P>Using the static factory, a DataObject might be created as follows:</P>

<P>Quote aQuote = StockFactory.INSTANCE.createQuote();<BR>
... // do something with aQuote<BR>
The generated implementation of each create() method simply constructs an instance of the corresponding type like this:</P>

<P><FONT color="gray">
<DIV class="preformatted panel" style="border-width: 1px;"><DIV class="preformattedContent panelContent">
<PRE>  public Quote createQuote() {
    QuoteImpl quote = new QuoteImpl();
    return quote;
  }
</PRE>
</DIV></DIV></FONT><BR>
In addition to these generated type-specific create&lt;Type&gt;() methods, the generated factory implementation class also includes a generated reflective create() method that, given an SDO Type, efficiently dispatches to the correct type-specific create() method. The reflective create() method is called by the implementation of the SDO commonj.sdo.helper.DataFactory interface.</P>


<P><B>Test/Example Programs</B></P>

<P>The SDO project does not include any proper sample programs at this time (any volunteers?) but it does include a number of JUnit test cases, some of which serve as good examples of how to use SDO APIs to perform various tasks.</P>

<P>The following tests are particularly good SDO examples included in the sdo.impl project:</P>

<P>SimpleDynamicTestCase This program uses the SDO XSDHelper.define() method to register a simple XML Schema based model (simple.xsd). It then instantiates a DataObject instance (type Quote), initializes several of its properties, and then serializes the instance to an XML stream.</P>

<P>MixedTypeTestCase This program shows how to uses the Sequence API to create an XML instance which mixes arbitrary text within the DataObject's XML structure. It uses the XML schema complexType (MixedQuote) in mixed.xsd to define the SDO model.</P>

<P>OpenTypeTestCase Uses an XML Schema complexType with a wildcard (xsd:any) to illustrate how to work with and manipulate an SDO open type. The type OpenQuote in open.xsd is used for this example.</P>

<P>SimpleCopyTestCase Uses the SDO CopyHelper to create shallow and deep copies of the simple Quote model from SimpleDynamicTest.</P>

<P>SimpleEqualityTestCase Uses the SDO EqualityHelper to perform deep and shallow equality checks.</P>

<P>ChangeSummaryTestCase Creates a data graph with an instance of type Quote (in simple.xsd) as the root object. It then turns on change logging and makes a number of changes to the graph. Finally, it turns off change logging and serializes the data graph.</P>

<P>XSDHelperTestCase This program shows how the XSDHelper.define() method can be called multiple times with the same schema. The second (and subsequent) call simply returns an empty list since no new types are defined.</P>

<P>The following is in the sdo.tools project:</P>

<P>SimpleStaticTestCase - This test performs the same function as SimpleDynamicTestCase, above, only using a generated version of the simple.xsd model. The generated model has been pre-generated (with default options) in the directory src/test, but it can be regenerated using the XSD2JavaGenerator, possibly with different generator options (e.g., -noInterfaces or -sparsePattern), if desired.</P>

<P>StaticSequenceNoEmfTest This test exercises the -noEMF generator option with a set of complex types, focussing on Sequenced behaviour in the generated classes. The generated model has been pre-generated (with options -noEMF -javaPackage com.example.noemf.sequences) in the directory src/test, but it can be regenerated using the XSD2JavaGenerator, possibly with different generator options (e.g., -noInterfaces or -sparsePattern), if desired.</P></TD></TR></TBODY></TABLE>
							</DIV>
						</DIV>
					</DIV>	
		            <!-- pageContent macro end -->
					
                </TD>
            </TR>
        </TABLE>

		<!-- footer macro -->
				<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
		</SCRIPT>
		<SCRIPT type="text/javascript">
		   _uacct = "UA-1174707-5";
		   urchinTracker();
		</SCRIPT>
		
				<A href="http://www.statcounter.com/" target="_blank"><IMG src="http://c26.statcounter.com/counter.php?sc_project=2619156&java=0&security=94bd7e7d&invisible=0" alt="website stats" border="0"></A>    

		<DIV class="footer">
			Copyright � 2003-2012, The Apache Software Foundation&nbsp;&nbsp;</BR>
                        Apache Tuscany and the Apache Tuscany project logo are trademarks of The Apache Software Foundation.
		</DIV>
		<!-- footer macro end -->

    </BODY>
</HTML>