Source Code Cross Referenced for XmlType.java in  » 6.0-JDK-Modules » jaxb-api » javax » xml » bind » annotation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb api » javax.xml.bind.annotation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003:         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
004:         */
005:
006:        package javax.xml.bind.annotation;
007:
008:        import static java.lang.annotation.ElementType.TYPE;
009:        import java.lang.annotation.Retention;
010:        import static java.lang.annotation.RetentionPolicy.RUNTIME;
011:        import java.lang.annotation.Target;
012:
013:        /**
014:         * <p>
015:         * Maps a class or an enum type to a XML Schema type.
016:         *
017:         * <p><b>Usage</b></p>
018:         * <p> The <tt>@XmlType</tt> annnotation can be used with the following program
019:         * elements:
020:         * <ul>
021:         *   <li> a top level class </li>
022:         *   <li> an enum type </li>
023:         * </ul>
024:         *
025:         * <p>See "Package Specification" in javax.xml.bind.package javadoc for
026:         * additional common information.</p>
027:         *
028:         * <h3> Mapping a Class </h3> 
029:         * <p>
030:         * A class maps to a XML Schema type. A class is a data container for
031:         * values represented by properties and fields. A schema type is a
032:         * data container for values represented by schema components within a
033:         * schema type's content model (e.g. model groups, attributes etc).
034:         * <p> To be mapped, a class must either have a public no-arg
035:         * constructor or a static no-arg factory method. The static factory
036:         * method can be specified in <tt>factoryMethod()</tt> and
037:         * <tt>factoryClass()</tt> annotation elements. The static factory
038:         * method or the no-arg constructor is used during unmarshalling to
039:         * create an instance of this class. If both are present, the static
040:         * factory method overrides the no-arg constructor.
041:         * <p>
042:         * A class maps to either a XML Schema complex type or a XML Schema simple
043:         * type. The XML Schema type is derived based on the 
044:         * mapping of JavaBean properties and fields contained within the
045:         * class. The schema type to which the class is mapped can either be
046:         * named or anonymous. A class can be mapped to an anonymous schema
047:         * type by annotating the class with <tt>&#64XmlType(name="")</tt>. 
048:         * <p>
049:         * Either a global element, local element or a local attribute can be
050:         * associated with an anonymous type as follows:
051:         * <ul>
052:         *   <li><b>global element: </b> A global element of an anonymous
053:         *      type can be derived by annotating the class with @{@link
054:         *      XmlRootElement}. See Example 3 below. </li> 
055:         *
056:         *   <li><b>local element: </b> A JavaBean property that references
057:         *      a class annotated with @XmlType(name="") and is mapped to the
058:         *      element associated with the anonymous type. See Example 4
059:         *      below.</li> 
060:         *
061:         *   <li><b>attribute: </b> A JavaBean property that references
062:         *      a class annotated with @XmlType(name="") and is mapped to the
063:         *      attribute associated with the anonymous type. See Example 5 below. </li>
064:         * </ul>
065:         * <b> Mapping to XML Schema Complex Type </b>
066:         * <ul>
067:         *   <li>If class is annotated with <tt>@XmlType(name="") </tt>, it
068:         *   is mapped to an anonymous type otherwise, the class name maps
069:         *   to a complex type name. The <tt>XmlName()</tt> annotation element
070:         *   can be used to customize the name.</li>  
071:         *
072:         *   <li> Properties and fields that are mapped to elements are mapped to a
073:         *   content model within a complex type. The annotation element
074:         *   <tt>propOrder()</tt> can be used to customize the content model to be
075:         *   <tt>xs:all</tt> or <tt>xs:sequence</tt>.  It is used for specifying
076:         *   the order of XML elements in <tt>xs:sequence</tt>. </li> 
077:         *
078:         *   <li> Properties and fields can be mapped to attributes within the
079:         *        complex type.  </li>
080:         *
081:         *   <li> The targetnamespace of the XML Schema type can be customized
082:         *        using the annotation element <tt>namespace()</tt>. </li>
083:         * </ul>
084:         *
085:         * <p>
086:         * <b> Mapping class to XML Schema simple type </b>
087:         * <p>
088:         * A class can be mapped to a XML Schema simple type using the
089:         * <tt>@XmlValue</tt> annotation. For additional details and examples,
090:         * see @{@link XmlValue} annotation type.
091:         * <p>
092:         * The following table shows the mapping of the class to a XML Schema
093:         * complex type or simple type. The notational symbols used in the table are:
094:         * <ul>
095:         *   <li> ->    : represents a mapping </li>
096:         *   <li> [x]+  : one or more occurances of x </li>
097:         *   <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with
098:         *         <tt>@XmlValue</tt></li>
099:         *   <li> X     : don't care
100:         * </ul>
101:         * <blockquote>
102:         *   <table border="1" cellpadding="4" cellspacing="3">
103:         *     <tbody>
104:         *       <tr>
105:         *         <td><b>Target</td>
106:         *         <td><b>propOrder</b></td>
107:         *         <td><b>ClassBody</b></td>
108:         *         <td><b>ComplexType</b></td>
109:         *         <td><b>SimpleType</b></td>
110:         *       </tr>
111:         * 
112:         *       <tr valign="top">
113:         *         <td>Class</td>
114:         *         <td>{}</td>
115:         *         <td>[property]+ -> elements</td>
116:         *         <td>complexcontent<br>xs:all</td>
117:         *         <td> </td>
118:         *       </tr>
119:         * 
120:         *       <tr valign="top">
121:         *         <td>Class</td>
122:         *         <td>non empty</td>
123:         *         <td>[property]+ -> elements</td>
124:         *         <td>complexcontent<br>xs:sequence</td>
125:         *         <td> </td>
126:         *       </tr>
127:         * 
128:         *       <tr valign="top">
129:         *         <td>Class</td>
130:         *         <td>X</td>
131:         *         <td>no property -> element</td>
132:         *         <td>complexcontent<br>empty sequence</td>
133:         *         <td> </td>
134:         *       </tr>
135:         * 
136:         *       <tr valign="top">
137:         *         <td>Class</td>
138:         *         <td>X</td>
139:         *         <td>1 [ <tt>@XmlValue</tt> property] && <br> [property]+
140:         *             ->attributes</td> 
141:         *         <td>simplecontent</td>
142:         *         <td> </td>
143:         *       </tr>
144:         * 
145:         *       <tr valign="top">
146:         *         <td>Class</td>
147:         *         <td>X</td>
148:         *         <td>1 [ <tt>@XmlValue</tt> property ]&& <br> no properties
149:         *         -> attribute</td> 
150:         *         <td> </td>
151:         *         <td>simpletype</td>
152:         *         <td> </td>
153:         *       </tr>
154:         *     </tbody>
155:         *   </table>
156:         * </blockquote>
157:         * 
158:         * <h3> Mapping an enum type </h3>
159:         * 
160:         * An enum type maps to a XML schema simple type with enumeration
161:         * facets. The following annotation elements are ignored since they
162:         * are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> , 
163:         * <tt>factoryClass()</tt> .
164:         *
165:         *  <h3> Usage with other annotations </h3>
166:         * <p> This annotation can be used with the following annotations: 
167:         * {@link XmlRootElement}, {@link XmlAccessorOrder}, {@link XmlAccessorType},
168:         * {@link XmlEnum}. However, {@link
169:         * XmlAccessorOrder} and {@link XmlAccessorType} are ignored when this
170:         * annotation is used on an enum type.
171:         * 
172:         * <p> <b> Example 1: </b> Map a class to a complex type with
173:         *   xs:sequence with a customized ordering of JavaBean properties. 
174:         * </p>
175:         *
176:         * <pre>
177:         *   &#64;XmlType(propOrder={"street", "city" , "state", "zip", "name" })
178:         *   public class USAddress {
179:         *     String getName() {..};
180:         *     void setName(String) {..};
181:         * 
182:         *     String getStreet() {..};
183:         *     void setStreet(String) {..};
184:         *
185:         *     String getCity() {..}; 
186:         *     void setCity(String) {..};
187:         * 
188:         *     String getState() {..};
189:         *     void setState(String) {..};
190:         *
191:         *     java.math.BigDecimal getZip() {..};
192:         *     void setZip(java.math.BigDecimal) {..};
193:         *   }
194:         *
195:         *   &lt;!-- XML Schema mapping for USAddress -->
196:         *   &lt;xs:complexType name="USAddress">
197:         *     &lt;xs:sequence>
198:         *       &lt;xs:element name="street" type="xs:string"/>
199:         *       &lt;xs:element name="city" type="xs:string"/>
200:         *       &lt;xs:element name="state" type="xs:string"/>
201:         *       &lt;xs:element name="zip" type="xs:decimal"/>
202:         *       &lt;xs:element name="name" type="xs:string"/>
203:         *     &lt;/xs:all>
204:         *   &lt;/xs:complexType> 
205:         * </pre>
206:         * <p> <b> Example 2: </b> Map a class to a complex type with
207:         *     xs:all </p>
208:         * <pre>
209:         * &#64;XmlType(propOrder={})
210:         * public class USAddress { ...}
211:         * 
212:         * &lt;!-- XML Schema mapping for USAddress -->
213:         * &lt;xs:complexType name="USAddress">
214:         *   &lt;xs:all>
215:         *     &lt;xs:element name="name" type="xs:string"/>
216:         *     &lt;xs:element name="street" type="xs:string"/>
217:         *     &lt;xs:element name="city" type="xs:string"/>
218:         *     &lt;xs:element name="state" type="xs:string"/>
219:         *     &lt;xs:element name="zip" type="xs:decimal"/>
220:         *   &lt;/xs:sequence>
221:         * &lt;/xs:complexType>
222:         *</pre>
223:         * <p> <b> Example 3: </b> Map a class to a global element with an
224:         * anonymous type. 
225:         * </p>
226:         * <pre>
227:         *   &#64;XmlRootElement
228:         *   &#64;XmlType(name="")
229:         *   public class USAddress { ...}
230:         *
231:         *   &lt;!-- XML Schema mapping for USAddress -->
232:         *   &lt;xs:element name="USAddress">
233:         *     &lt;xs:complexType>
234:         *       &lt;xs:sequence>
235:         *         &lt;xs:element name="name" type="xs:string"/>
236:         *         &lt;xs:element name="street" type="xs:string"/>
237:         *         &lt;xs:element name="city" type="xs:string"/>
238:         *         &lt;xs:element name="state" type="xs:string"/>
239:         *         &lt;xs:element name="zip" type="xs:decimal"/>
240:         *       &lt;/xs:sequence>
241:         *     &lt;/xs:complexType>
242:         *   &lt;/xs:element>
243:         * </pre>
244:         *
245:         * <p> <b> Example 4: </b> Map a property to a local element with
246:         * anonmyous type. 
247:         * <pre>
248:         *   //Example: Code fragment
249:         *   public class Invoice {
250:         *       USAddress addr;
251:         *           ...
252:         *       }
253:         *
254:         *   &#64;XmlType(name="")
255:         *   public class USAddress { ... }
256:         *   } 
257:         *
258:         *   &lt;!-- XML Schema mapping for USAddress -->
259:         *   &lt;xs:complexType name="Invoice">
260:         *     &lt;xs:sequence>
261:         *       &lt;xs:element name="addr">
262:         *         &lt;xs:complexType>
263:         *           &lt;xs:element name="name", type="xs:string"/>
264:         *           &lt;xs:element name="city", type="xs:string"/>
265:         *           &lt;xs:element name="city" type="xs:string"/>
266:         *           &lt;xs:element name="state" type="xs:string"/>
267:         *           &lt;xs:element name="zip" type="xs:decimal"/>
268:         *         &lt;/xs:complexType>
269:         *       ...
270:         *     &lt;/xs:sequence>
271:         *   &lt;/xs:complexType> 
272:         * </pre>
273:         *
274:         * <p> <b> Example 5: </b> Map a property to an attribute with
275:         * anonymous type.
276:         * 
277:         * <pre>
278:         *
279:         *     //Example: Code fragment
280:         *     public class Item {
281:         *         public String name;
282:         *         &#64;XmlAttribute 
283:         *         public USPrice price;
284:         *     }
285:         *    
286:         *     // map class to anonymous simple type. 
287:         *     &#64;XmlType(name="")
288:         *     public class USPrice { 
289:         *         &#64;XmlValue
290:         *         public java.math.BigDecimal price;
291:         *     }
292:         *
293:         *     &lt;!-- Example: XML Schema fragment -->
294:         *     &lt;xs:complexType name="Item">
295:         *       &lt;xs:sequence>
296:         *         &lt;xs:element name="name" type="xs:string"/>
297:         *         &lt;xs:attribute name="price">
298:         *           &lt;xs:simpleType>
299:         *             &lt;xs:restriction base="xs:decimal"/>
300:         *           &lt;/xs:simpleType>
301:         *         &lt;/xs:attribute>
302:         *       &lt;/xs:sequence>
303:         *     &lt;/xs:complexType>
304:         * </pre>
305:         *
306:         *  <p> <b> Example 6: </b> Define a factoryClass and factoryMethod
307:         *
308:         * <pre> 
309:         *      &#64;XmlType(name="USAddressType", factoryClass=USAddressFactory.class,
310:         *      factoryMethod="getUSAddress")
311:         *      public class USAddress {
312:         *
313:         *          private String city;
314:         *          private String name;
315:         *          private String state;
316:         *          private String street;
317:         *          private int    zip;
318:         *
319:         *      public USAddress(String name, String street, String city, 
320:         *          String state, int zip) {
321:         *          this.name = name;
322:         *          this.street = street;
323:         *          this.city = city;
324:         *          this.state = state;
325:         *          this.zip = zip;
326:         *      }
327:         *  }
328:         *
329:         *  public class USAddressFactory {
330:         *      public static USAddress getUSAddress(){
331:         *       return new USAddress("Mark Baker", "23 Elm St", 
332:         *          "Dayton", "OH", 90952);
333:         *  }
334:         *
335:         * </pre>
336:         *
337:         *  <p> <b> Example 7: </b> Define factoryMethod and use the default factoryClass
338:         * 
339:         * <pre>
340:         *      &#64;XmlType(name="USAddressType", factoryMethod="getNewInstance")
341:         *      public class USAddress {
342:         *
343:         *          private String city;
344:         *          private String name;
345:         *          private String state;
346:         *          private String street;
347:         *          private int    zip;
348:         *
349:         *          private USAddress() {}
350:         *
351:         *          public static USAddress getNewInstance(){
352:         *              return new USAddress();
353:         *          }
354:         *      }
355:         * </pre>
356:         *
357:         * @author Sekhar Vajjhala, Sun Microsystems, Inc.
358:         * @see XmlElement
359:         * @see XmlAttribute
360:         * @see XmlValue
361:         * @see XmlSchema
362:         * @since JAXB2.0
363:         * @version $Revision: 1.20 $
364:         */
365:
366:        @Retention(RUNTIME)
367:        @Target({TYPE})
368:        public @interface XmlType {
369:            /**
370:             * Name of the XML Schema type which the class is mapped.
371:             */
372:            String name() default "##default";
373:
374:            /**
375:             * Specifies the order for XML Schema elements when class is
376:             * mapped to a XML Schema complex type.
377:             * 
378:             * <p> Refer to the table for how the propOrder affects the
379:             * mapping of class </p>
380:             * 
381:             * <p> The propOrder is a list of names of JavaBean properties in
382:             *     the class. Each name in the list is the name of a Java
383:             *     identifier of the JavaBean property. The order in which
384:             *     JavaBean properties are listed is the order of XML Schema
385:             *     elements to which the JavaBean properties are mapped. </p>
386:             * <p> All of the JavaBean properties being mapped to XML Schema elements
387:             *     must be listed. 
388:             * <p> A JavaBean property or field listed in propOrder must not
389:             *     be transient or annotated with <tt>@XmlTransient</tt>.
390:             * <p> The default ordering of JavaBean properties is determined
391:             *     by @{@link XmlAccessorOrder}. 
392:             */
393:            String[] propOrder() default { "" };
394:
395:            /**
396:             * Name of the target namespace of the XML Schema type. By
397:             * default, this is the target namespace to which the package
398:             * containing the class is mapped.
399:             */
400:            String namespace() default "##default";
401:
402:            /**
403:             * Class containing a no-arg factory method for creating an
404:             * instance of this class. The default is this class.
405:             * 
406:             * <p>If <tt>factoryClass</tt> is DEFAULT.class and 
407:             * <tt>factoryMethod</tt> is "", then there is no static factory
408:             * method.
409:             * 
410:             * <p>If <tt>factoryClass</tt> is DEFAULT.class and
411:             * <tt>factoryMethod</tt> is not "", then 
412:             * <tt>factoryMethod</tt> is the name of a static factory method
413:             * in this class. 
414:             *
415:             * <p>If <tt>factoryClass</tt> is not DEFAULT.class, then 
416:             * <tt>factoryMethod</tt> must not be "" and must be the name of
417:             * a static factory method specified in <tt>factoryClass</tt>.
418:             */
419:            Class factoryClass() default DEFAULT.class;
420:
421:            /**
422:             * Used in {@link XmlType#factoryClass()} to
423:             * signal that either factory mehod is not used or
424:             * that it's in the class with this {@link XmlType} itself. 
425:             */
426:            static final class DEFAULT {
427:            }
428:
429:            /**
430:             * Name of a no-arg factory method in the class specified in
431:             * <tt>factoryClass</tt> factoryClass(). 
432:             * 
433:             */
434:            String factoryMethod() default "";
435:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.