1 /*
2  * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
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.adapters;
27 
28 import javax.xml.bind.annotation.XmlAnyElement;
29 import javax.xml.bind.annotation.XmlElementRefs;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlSchemaType;
32 import javax.xml.bind.annotation.XmlElementRef;
33 import javax.xml.bind.annotation.XmlAttribute;
34 import javax.xml.bind.annotation.XmlSchema;
35 import javax.xml.bind.annotation.XmlAccessorType;
36 import javax.xml.bind.annotation.XmlSchemaTypes;
37 import java.lang.annotation.Target;
38 import java.lang.annotation.Retention;
39 
40 import static java.lang.annotation.RetentionPolicy.RUNTIME;
41 import static java.lang.annotation.ElementType.FIELD;
42 import static java.lang.annotation.ElementType.METHOD;
43 import static java.lang.annotation.ElementType.TYPE;
44 import static java.lang.annotation.ElementType.PARAMETER;
45 import static java.lang.annotation.ElementType.PACKAGE;
46 
47 
48 /**
49  * Use an adapter that implements {@link XmlAdapter} for custom marshaling.
50  *
51  * <p> <b> Usage: </b> </p>
52  *
53  * <p> The <tt>@XmlJavaTypeAdapter</tt> annotation can be used with the
54  * following program elements:
55  * <ul>
56  *   <li> a JavaBean property </li>
57  *   <li> field </li>
58  *   <li> parameter </li>
59  *   <li> package </li>
60  *   <li> from within {@link XmlJavaTypeAdapters} </li>
61  * </ul>
62  *
63  * <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined on a
64  * class, it applies to all references to the class.
65  * <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined at the
66  * package level it applies to all references from within the package
67  * to <tt>@XmlJavaTypeAdapter.type()</tt>.
68  * <p> When <tt>@XmlJavaTypeAdapter</tt> annotation is defined on the
69  * field, property or parameter, then the annotation applies to the
70  * field, property or the parameter only.
71  * <p> A <tt>@XmlJavaTypeAdapter</tt> annotation on a field, property
72  * or parameter overrides the <tt>@XmlJavaTypeAdapter</tt> annotation
73  * associated with the class being referenced by the field, property
74  * or parameter.
75  * <p> A <tt>@XmlJavaTypeAdapter</tt> annotation on a class overrides
76  * the <tt>@XmlJavaTypeAdapter</tt> annotation specified at the
77  * package level for that class.
78  *
79  * <p>This annotation can be used with the following other annotations:
80  * {@link XmlElement}, {@link XmlAttribute}, {@link XmlElementRef},
81  * {@link XmlElementRefs}, {@link XmlAnyElement}. This can also be
82  * used at the package level with the following annotations:
83  * {@link XmlAccessorType}, {@link XmlSchema}, {@link XmlSchemaType},
84  * {@link XmlSchemaTypes}.
85  *
86  * <p><b> Example: </b> See example in {@link XmlAdapter}
87  *
88  * @author <ul><li>Sekhar Vajjhala, Sun Microsystems Inc.</li> <li> Kohsuke Kawaguchi, Sun Microsystems Inc.</li></ul>
89  * @since JAXB2.0
90  * @see XmlAdapter
91  */
92 
93 @Retention(RUNTIME) @Target({PACKAGE,FIELD,METHOD,TYPE,PARAMETER})
94 public @interface XmlJavaTypeAdapter {
95     /**
96      * Points to the class that converts a value type to a bound type or vice versa.
97      * See {@link XmlAdapter} for more details.
98      */
value()99     Class<? extends XmlAdapter> value();
100 
101     /**
102      * If this annotation is used at the package level, then value of
103      * the type() must be specified.
104      */
105 
type()106     Class type() default DEFAULT.class;
107 
108     /**
109      * Used in {@link XmlJavaTypeAdapter#type()} to
110      * signal that the type be inferred from the signature
111      * of the field, property, parameter or the class.
112      */
113 
114     static final class DEFAULT {}
115 
116 }
117