xmltype.html

来自「j2ee帮助文档软件设计/软件工程 文件格式」· HTML 代码 · 共 693 行 · 第 1/2 页

HTML
693
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_14) on Mon Jan 28 05:46:59 PST 2008 --><TITLE>XmlType (Java EE 5)</TITLE><META NAME="keywords" CONTENT="javax.xml.bind.annotation.XmlType class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){    parent.document.title="XmlType (Java EE 5)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../../../javax/xml/bind/annotation/XmlTransient.html" title="annotation in javax.xml.bind.annotation"><B>PREV CLASS</B></A>&nbsp;&nbsp;<A HREF="../../../../javax/xml/bind/annotation/XmlType.DEFAULT.html" title="class in javax.xml.bind.annotation"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../../../index.html?javax/xml/bind/annotation/XmlType.html" target="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="XmlType.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;&nbsp;<SCRIPT type="text/javascript">  <!--  if(window==top) {    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');  }  //--></SCRIPT><NOSCRIPT>  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY:&nbsp;REQUIRED&nbsp;|&nbsp;<A HREF="#annotation_type_optional_element_summary">OPTIONAL</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL:&nbsp;<A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">javax.xml.bind.annotation</FONT><BR>Annotation Type XmlType</H2><HR><DL><DT><PRE><FONT SIZE="-1"><A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/Retention.html" title="class or interface in java.lang.annotation">@Retention</A>(<A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/Retention.html#value()" title="class or interface in java.lang.annotation">value</A>=<A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/RetentionPolicy.html#RUNTIME" title="class or interface in java.lang.annotation">RUNTIME</A>)<A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/Target.html" title="class or interface in java.lang.annotation">@Target</A>(<A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/Target.html#value()" title="class or interface in java.lang.annotation">value</A>=<A HREF="http://java.sun.com/j2se/1.5/docs/api/java/lang/annotation/ElementType.html#TYPE" title="class or interface in java.lang.annotation">TYPE</A>)</FONT>public @interface <B>XmlType</B></DL></PRE><P><p> Maps a class or an enum type to a XML Schema type. <p><b>Usage</b></p> <p> The <tt>@XmlType</tt> annnotation can be used with the following program elements: <ul>   <li> a top level class </li>   <li> an enum type </li> </ul> <p>See "Package Specification" in javax.xml.bind.package javadoc for additional common information.</p> <h3> Mapping a Class </h3>  <p> A class maps to a XML Schema type. A class is a data container for values represented by properties and fields. A schema type is a data container for values represented by schema components within a schema type's content model (e.g. model groups, attributes etc). <p> To be mapped, a class must either have a public no-arg constructor or a static no-arg factory method. The static factory method can be specified in <tt>factoryMethod()</tt> and <tt>factoryClass()</tt> annotation elements. The static factory method or the no-arg constructor is used during unmarshalling to create an instance of this class. If both are present, the static factory method overrides the no-arg constructor. <p> A class maps to either a XML Schema complex type or a XML Schema simple type. The XML Schema type is derived based on the  mapping of JavaBean properties and fields contained within the class. The schema type to which the class is mapped can either be named or anonymous. A class can be mapped to an anonymous schema type by annotating the class with <tt>&#64XmlType(name="")</tt>.  <p> Either a global element, local element or a local attribute can be associated with an anonymous type as follows: <ul>   <li><b>global element: </b> A global element of an anonymous      type can be derived by annotating the class with @<A HREF="../../../../javax/xml/bind/annotation/XmlRootElement.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlRootElement</CODE></A>. See Example 3 below. </li>    <li><b>local element: </b> A JavaBean property that references      a class annotated with @XmlType(name="") and is mapped to the      element associated with the anonymous type. See Example 4      below.</li>    <li><b>attribute: </b> A JavaBean property that references      a class annotated with @XmlType(name="") and is mapped to the      attribute associated with the anonymous type. See Example 5 below. </li> </ul> <b> Mapping to XML Schema Complex Type </b> <ul>   <li>If class is annotated with <tt>@XmlType(name="") </tt>, it   is mapped to an anonymous type otherwise, the class name maps   to a complex type name. The <tt>XmlName()</tt> annotation element   can be used to customize the name.</li>     <li> Properties and fields that are mapped to elements are mapped to a   content model within a complex type. The annotation element   <tt>propOrder()</tt> can be used to customize the content model to be   <tt>xs:all</tt> or <tt>xs:sequence</tt>.  It is used for specifying   the order of XML elements in <tt>xs:sequence</tt>. </li>    <li> Properties and fields can be mapped to attributes within the        complex type.  </li>   <li> The targetnamespace of the XML Schema type can be customized        using the annotation element <tt>namespace()</tt>. </li> </ul> <p> <b> Mapping class to XML Schema simple type </b> <p> A class can be mapped to a XML Schema simple type using the <tt>@XmlValue</tt> annotation. For additional details and examples, see @<A HREF="../../../../javax/xml/bind/annotation/XmlValue.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlValue</CODE></A> annotation type. <p> The following table shows the mapping of the class to a XML Schema complex type or simple type. The notational symbols used in the table are: <ul>   <li> ->    : represents a mapping </li>   <li> [x]+  : one or more occurances of x </li>   <li> [ <tt>@XmlValue</tt> property ]: JavaBean property annotated with         <tt>@XmlValue</tt></li>   <li> X     : don't care </ul> <blockquote>   <table border="1" cellpadding="4" cellspacing="3">     <tbody>       <tr>         <td><b>Target</td>         <td><b>propOrder</b></td>         <td><b>ClassBody</b></td>         <td><b>ComplexType</b></td>         <td><b>SimpleType</b></td>       </tr>        <tr valign="top">         <td>Class</td>         <td>{}</td>         <td>[property]+ -> elements</td>         <td>complexcontent<br>xs:all</td>         <td> </td>       </tr>        <tr valign="top">         <td>Class</td>         <td>non empty</td>         <td>[property]+ -> elements</td>         <td>complexcontent<br>xs:sequence</td>         <td> </td>       </tr>        <tr valign="top">         <td>Class</td>         <td>X</td>         <td>no property -> element</td>         <td>complexcontent<br>empty sequence</td>         <td> </td>       </tr>        <tr valign="top">         <td>Class</td>         <td>X</td>         <td>1 [ <tt>@XmlValue</tt> property] && <br> [property]+             ->attributes</td>          <td>simplecontent</td>         <td> </td>       </tr>        <tr valign="top">         <td>Class</td>         <td>X</td>         <td>1 [ <tt>@XmlValue</tt> property ]&& <br> no properties         -> attribute</td>          <td> </td>         <td>simpletype</td>         <td> </td>       </tr>     </tbody>   </table> </blockquote>  <h3> Mapping an enum type </h3>  An enum type maps to a XML schema simple type with enumeration facets. The following annotation elements are ignored since they are not meaningful: <tt>propOrder()</tt> , <tt>factoryMethod()</tt> ,  <tt>factoryClass()</tt> .  <h3> Usage with other annotations </h3> <p> This annotation can be used with the following annotations:  <A HREF="../../../../javax/xml/bind/annotation/XmlRootElement.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlRootElement</CODE></A>, <A HREF="../../../../javax/xml/bind/annotation/XmlAccessorOrder.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlAccessorOrder</CODE></A>, <A HREF="../../../../javax/xml/bind/annotation/XmlAccessorType.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlAccessorType</CODE></A>, <A HREF="../../../../javax/xml/bind/annotation/XmlEnum.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlEnum</CODE></A>. However, <A HREF="../../../../javax/xml/bind/annotation/XmlAccessorOrder.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlAccessorOrder</CODE></A> and <A HREF="../../../../javax/xml/bind/annotation/XmlAccessorType.html" title="annotation in javax.xml.bind.annotation"><CODE>XmlAccessorType</CODE></A> are ignored when this annotation is used on an enum type.  <p> <b> Example 1: </b> Map a class to a complex type with   xs:sequence with a customized ordering of JavaBean properties.  </p> <pre>   &#64;XmlType(propOrder={"street", "city" , "state", "zip", "name" })   public class USAddress {     String getName() {..};     void setName(String) {..};      String getStreet() {..};     void setStreet(String) {..};     String getCity() {..};      void setCity(String) {..};      String getState() {..};     void setState(String) {..};     java.math.BigDecimal getZip() {..};     void setZip(java.math.BigDecimal) {..};   }   &lt;!-- XML Schema mapping for USAddress -->   &lt;xs:complexType name="USAddress">     &lt;xs:sequence>       &lt;xs:element name="street" type="xs:string"/>       &lt;xs:element name="city" type="xs:string"/>       &lt;xs:element name="state" type="xs:string"/>       &lt;xs:element name="zip" type="xs:decimal"/>       &lt;xs:element name="name" type="xs:string"/>     &lt;/xs:all>   &lt;/xs:complexType>  </pre> <p> <b> Example 2: </b> Map a class to a complex type with     xs:all </p> <pre> &#64;XmlType(propOrder={}) public class USAddress { ...}  &lt;!-- XML Schema mapping for USAddress --> &lt;xs:complexType name="USAddress">   &lt;xs:all>     &lt;xs:element name="name" type="xs:string"/>     &lt;xs:element name="street" type="xs:string"/>     &lt;xs:element name="city" type="xs:string"/>     &lt;xs:element name="state" type="xs:string"/>     &lt;xs:element name="zip" type="xs:decimal"/>   &lt;/xs:sequence> &lt;/xs:complexType></pre> <p> <b> Example 3: </b> Map a class to a global element with an anonymous type.  </p> <pre>   &#64;XmlRootElement   &#64;XmlType(name="")   public class USAddress { ...}   &lt;!-- XML Schema mapping for USAddress -->   &lt;xs:element name="USAddress">     &lt;xs:complexType>       &lt;xs:sequence>         &lt;xs:element name="name" type="xs:string"/>         &lt;xs:element name="street" type="xs:string"/>         &lt;xs:element name="city" type="xs:string"/>         &lt;xs:element name="state" type="xs:string"/>         &lt;xs:element name="zip" type="xs:decimal"/>       &lt;/xs:sequence>     &lt;/xs:complexType>   &lt;/xs:element> </pre> <p> <b> Example 4: </b> Map a property to a local element with anonmyous type.  <pre>   //Example: Code fragment   public class Invoice {       USAddress addr;           ...       }   &#64;XmlType(name="")   public class USAddress { ... }   }    &lt;!-- XML Schema mapping for USAddress -->   &lt;xs:complexType name="Invoice">     &lt;xs:sequence>       &lt;xs:element name="addr">         &lt;xs:complexType>           &lt;xs:element name="name", type="xs:string"/>           &lt;xs:element name="city", type="xs:string"/>           &lt;xs:element name="city" type="xs:string"/>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?