19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.bind.annotation; 27 28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 29 import java.lang.annotation.Retention; 30 import java.lang.annotation.Target; 31 32 import static java.lang.annotation.ElementType.*; 33 import static java.lang.annotation.ElementType.PARAMETER; 34 import static java.lang.annotation.RetentionPolicy.*; 35 36 /** 37 * Maps a JavaBean property to a XML element derived from property name. 38 * 39 * <p> <b>Usage</b> </p> 40 * <p> 41 * <tt>@XmlElement</tt> annotation can be used with the following program 42 * elements: 43 * <ul> 44 * <li> a JavaBean property </li> 45 * <li> non static, non transient field </li> 46 * <li> within {@link XmlElements} 47 * <p> 48 * 49 * </ul> 50 * 51 * The usage is subject to the following constraints: 52 * <ul> 53 * <li> This annotation can be used with following annotations: 54 * {@link XmlID}, 55 * {@link XmlIDREF}, 56 * {@link XmlList}, 57 * {@link XmlSchemaType}, 58 * {@link XmlValue}, 59 * {@link XmlAttachmentRef}, 60 * {@link XmlMimeType}, 61 * {@link XmlInlineBinaryData}, 62 * {@link XmlElementWrapper}, 63 * {@link XmlJavaTypeAdapter}</li> 64 * <li> if the type of JavaBean property is a collection type of 65 * array, an indexed property, or a parameterized list, and 66 * this annotation is used with {@link XmlElements} then, 67 * <tt>@XmlElement.type()</tt> must be DEFAULT.class since the 68 * collection item type is already known. </li> 69 * </ul> 70 * 71 * <p> 72 * A JavaBean property, when annotated with @XmlElement annotation 73 * is mapped to a local element in the XML Schema complex type to 74 * which the containing class is mapped. 75 * 76 * <p> 77 * <b>Example 1: </b> Map a public non static non final field to local 78 * element 79 * <pre> 80 * //Example: Code fragment 81 * public class USPrice { 82 * @XmlElement(name="itemprice") 83 * public java.math.BigDecimal price; 84 * } 85 * {@code 86 * 87 * <!-- Example: Local XML Schema element --> 88 * <xs:complexType name="USPrice"/> 89 * <xs:sequence> 90 * <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/> 91 * </sequence> 92 * </xs:complexType> 93 * }</pre> 94 * <p> 95 * 96 * <b> Example 2: </b> Map a field to a nillable element. 97 * <pre> 98 * 99 * //Example: Code fragment 100 * public class USPrice { 101 * @XmlElement(nillable=true) 102 * public java.math.BigDecimal price; 103 * } 104 * {@code 105 * 106 * <!-- Example: Local XML Schema element --> 107 * <xs:complexType name="USPrice"> 108 * <xs:sequence> 109 * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/> 110 * </sequence> 111 * </xs:complexType> 112 * }</pre> 113 * <p> 114 * <b> Example 3: </b> Map a field to a nillable, required element. 115 * <pre> 116 * 117 * //Example: Code fragment 118 * public class USPrice { 119 * @XmlElement(nillable=true, required=true) 120 * public java.math.BigDecimal price; 121 * } 122 * {@code 123 * 124 * <!-- Example: Local XML Schema element --> 125 * <xs:complexType name="USPrice"> 126 * <xs:sequence> 127 * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/> 128 * </sequence> 129 * </xs:complexType> 130 * }</pre> 131 * 132 * <p> <b>Example 4: </b>Map a JavaBean property to an XML element 133 * with anonymous type.</p> 134 * <p> 135 * See Example 6 in @{@link XmlType}. 136 * 137 * <p> 138 * @author Sekhar Vajjhala, Sun Microsystems, Inc. 139 * @since 1.6, JAXB 2.0 140 */ 141 142 @Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER}) 143 public @interface XmlElement { 144 /** 145 * Name of the XML Schema element. 146 * <p> If the value is "##default", then element name is derived from the 147 * JavaBean property name. 148 */ 149 String name() default "##default"; 150 151 /** 152 * Customize the element declaration to be nillable. 153 * <p>If nillable() is true, then the JavaBean property is 154 * mapped to a XML Schema nillable element declaration. 155 */ 156 boolean nillable() default false; 157 | 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.xml.bind.annotation; 27 28 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 29 import java.lang.annotation.Retention; 30 import java.lang.annotation.Target; 31 32 import static java.lang.annotation.ElementType.*; 33 import static java.lang.annotation.ElementType.PARAMETER; 34 import static java.lang.annotation.RetentionPolicy.*; 35 36 /** 37 * Maps a JavaBean property to a XML element derived from property name. 38 * 39 * <p> <b>Usage</b> 40 * <p> 41 * <tt>@XmlElement</tt> annotation can be used with the following program 42 * elements: 43 * <ul> 44 * <li> a JavaBean property </li> 45 * <li> non static, non transient field </li> 46 * <li> within {@link XmlElements} 47 * </ul> 48 * 49 * The usage is subject to the following constraints: 50 * <ul> 51 * <li> This annotation can be used with following annotations: 52 * {@link XmlID}, 53 * {@link XmlIDREF}, 54 * {@link XmlList}, 55 * {@link XmlSchemaType}, 56 * {@link XmlValue}, 57 * {@link XmlAttachmentRef}, 58 * {@link XmlMimeType}, 59 * {@link XmlInlineBinaryData}, 60 * {@link XmlElementWrapper}, 61 * {@link XmlJavaTypeAdapter}</li> 62 * <li> if the type of JavaBean property is a collection type of 63 * array, an indexed property, or a parameterized list, and 64 * this annotation is used with {@link XmlElements} then, 65 * <tt>@XmlElement.type()</tt> must be DEFAULT.class since the 66 * collection item type is already known. </li> 67 * </ul> 68 * 69 * <p> 70 * A JavaBean property, when annotated with @XmlElement annotation 71 * is mapped to a local element in the XML Schema complex type to 72 * which the containing class is mapped. 73 * 74 * <p> 75 * <b>Example 1: </b> Map a public non static non final field to local 76 * element 77 * <pre> 78 * //Example: Code fragment 79 * public class USPrice { 80 * {@literal @}XmlElement(name="itemprice") 81 * public java.math.BigDecimal price; 82 * } 83 * {@code 84 * 85 * <!-- Example: Local XML Schema element --> 86 * <xs:complexType name="USPrice"/> 87 * <xs:sequence> 88 * <xs:element name="itemprice" type="xs:decimal" minOccurs="0"/> 89 * </sequence> 90 * </xs:complexType> 91 * }</pre> 92 * <p> 93 * 94 * <b> Example 2: </b> Map a field to a nillable element. 95 * <pre> 96 * //Example: Code fragment 97 * public class USPrice { 98 * {@literal @}XmlElement(nillable=true) 99 * public java.math.BigDecimal price; 100 * } 101 * {@code 102 * 103 * <!-- Example: Local XML Schema element --> 104 * <xs:complexType name="USPrice"> 105 * <xs:sequence> 106 * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="0"/> 107 * </sequence> 108 * </xs:complexType> 109 * }</pre> 110 * <p> 111 * <b> Example 3: </b> Map a field to a nillable, required element. 112 * <pre> 113 * //Example: Code fragment 114 * public class USPrice { 115 * {@literal @}XmlElement(nillable=true, required=true) 116 * public java.math.BigDecimal price; 117 * } 118 * {@code 119 * 120 * <!-- Example: Local XML Schema element --> 121 * <xs:complexType name="USPrice"> 122 * <xs:sequence> 123 * <xs:element name="price" type="xs:decimal" nillable="true" minOccurs="1"/> 124 * </sequence> 125 * </xs:complexType> 126 * }</pre> 127 * 128 * <p> <b>Example 4: </b>Map a JavaBean property to an XML element 129 * with anonymous type.</p> 130 * <p> 131 * See Example 6 in @{@link XmlType}. 132 * 133 * @author Sekhar Vajjhala, Sun Microsystems, Inc. 134 * @since 1.6, JAXB 2.0 135 */ 136 137 @Retention(RUNTIME) @Target({FIELD, METHOD, PARAMETER}) 138 public @interface XmlElement { 139 /** 140 * Name of the XML Schema element. 141 * <p> If the value is "##default", then element name is derived from the 142 * JavaBean property name. 143 */ 144 String name() default "##default"; 145 146 /** 147 * Customize the element declaration to be nillable. 148 * <p>If nillable() is true, then the JavaBean property is 149 * mapped to a XML Schema nillable element declaration. 150 */ 151 boolean nillable() default false; 152 |