325N/A/*
325N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage javax.xml.bind.annotation;
325N/A
325N/Aimport java.lang.annotation.Retention;
325N/Aimport java.lang.annotation.Target;
325N/A
325N/Aimport static java.lang.annotation.ElementType.*;
325N/Aimport static java.lang.annotation.RetentionPolicy.*;
325N/A
325N/A/**
325N/A * <p>
325N/A * Maps a JavaBean property to a XML attribute.
325N/A *
325N/A * <p> <b>Usage</b> </p>
325N/A * <p>
325N/A * The <tt>@XmlAttribute</tt> annotation can be used with the
325N/A * following program elements:
325N/A * <ul>
325N/A * <li> JavaBean property </li>
325N/A * <li> field </li>
325N/A * </ul>
325N/A *
325N/A * <p> A static final field is mapped to a XML fixed attribute.
325N/A *
325N/A * <p>See "Package Specification" in javax.xml.bind.package javadoc for
325N/A * additional common information.</p>
325N/A *
325N/A * The usage is subject to the following constraints:
325N/A * <ul>
325N/A * <li> If type of the field or the property is a collection
325N/A * type, then the collection item type must be mapped to schema
325N/A * simple type.
325N/A * <pre>
325N/A * // Examples
325N/A * &#64;XmlAttribute List&lt;Integer> items; //legal
325N/A * &#64;XmlAttribute List&lt;Bar> foo; // illegal if Bar does not map to a schema simple type
325N/A * </pre>
325N/A * </li>
325N/A * <li> If the type of the field or the property is a non
325N/A * collection type, then the type of the property or field
325N/A * must map to a simple schema type.
325N/A * <pre>
325N/A * // Examples
325N/A * &#64;XmlAttribute int foo; // legal
325N/A * &#64;XmlAttribute Foo foo; // illegal if Foo does not map to a schema simple type
325N/A * </pre>
325N/A * </li>
325N/A * <li> This annotation can be used with the following annotations:
325N/A * {@link XmlID},
325N/A * {@link XmlIDREF},
325N/A * {@link XmlList},
325N/A * {@link XmlSchemaType},
325N/A * {@link XmlValue},
325N/A * {@link XmlAttachmentRef},
325N/A * {@link XmlMimeType},
325N/A * {@link XmlInlineBinaryData},
325N/A * {@link javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter}.</li>
325N/A * </ul>
325N/A * </p>
325N/A *
325N/A * <p> <b>Example 1: </b>Map a JavaBean property to an XML attribute.</p>
325N/A * <pre>
325N/A * //Example: Code fragment
325N/A * public class USPrice {
325N/A * &#64;XmlAttribute
325N/A * public java.math.BigDecimal getPrice() {...} ;
325N/A * public void setPrice(java.math.BigDecimal ) {...};
325N/A * }
325N/A *
325N/A * &lt;!-- Example: XML Schema fragment -->
325N/A * &lt;xs:complexType name="USPrice">
325N/A * &lt;xs:sequence>
325N/A * &lt;/xs:sequence>
325N/A * &lt;xs:attribute name="price" type="xs:decimal"/>
325N/A * &lt;/xs:complexType>
325N/A * </pre>
325N/A *
325N/A * <p> <b>Example 2: </b>Map a JavaBean property to an XML attribute with anonymous type.</p>
325N/A * See Example 7 in @{@link XmlType}.
325N/A *
325N/A * <p> <b>Example 3: </b>Map a JavaBean collection property to an XML attribute.</p>
325N/A * <pre>
325N/A * // Example: Code fragment
325N/A * class Foo {
325N/A * ...
325N/A * &#64;XmlAttribute List&lt;Integer> items;
325N/A * }
325N/A *
325N/A * &lt;!-- Example: XML Schema fragment -->
325N/A * &lt;xs:complexType name="foo">
325N/A * ...
325N/A * &lt;xs:attribute name="items">
325N/A * &lt;xs:simpleType>
325N/A * &lt;xs:list itemType="xs:int"/>
325N/A * &lt;/xs:simpleType>
325N/A * &lt;/xs:complexType>
325N/A *
325N/A * </pre>
325N/A * @author Sekhar Vajjhala, Sun Microsystems, Inc.
325N/A * @see XmlType
325N/A * @since JAXB2.0
325N/A */
325N/A
325N/A@Retention(RUNTIME) @Target({FIELD, METHOD})
325N/Apublic @interface XmlAttribute {
325N/A /**
325N/A * Name of the XML Schema attribute. By default, the XML Schema
325N/A * attribute name is derived from the JavaBean property name.
325N/A *
325N/A */
325N/A String name() default "##default";
325N/A
325N/A /**
325N/A * Specifies if the XML Schema attribute is optional or
325N/A * required. If true, then the JavaBean property is mapped to a
325N/A * XML Schema attribute that is required. Otherwise it is mapped
325N/A * to a XML Schema attribute that is optional.
325N/A *
325N/A */
325N/A boolean required() default false;
325N/A
325N/A /**
325N/A * Specifies the XML target namespace of the XML Schema
325N/A * attribute.
325N/A *
325N/A */
325N/A String namespace() default "##default" ;
325N/A}