KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > JAXBIntrospector


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 package javax.xml.bind;
7 import javax.xml.namespace.QName JavaDoc;
8
9 /**
10  * Provide access to JAXB xml binding data for a JAXB object.
11  *
12  * <p>
13  * Intially, the intent of this class is to just conceptualize how
14  * a JAXB application developer can access xml binding information,
15  * independent if binding model is java to schema or schema to java.
16  * Since accessing the XML element name related to a JAXB element is
17  * a highly requested feature, demonstrate access to this
18  * binding information.
19  *
20  * The factory method to get a <code>JAXBIntrospector</code> instance is
21  * {@link JAXBContext#createJAXBIntrospector()}.
22  *
23  * @see JAXBContext#createJAXBIntrospector()
24  * @since JAXB2.0
25  */

26 public abstract class JAXBIntrospector {
27
28     /**
29      * <p>Return true iff <code>object</code> represents a JAXB element.</p>
30      * <p>Parameter <code>object</code> is a JAXB element for following cases:
31      * <ol>
32      * <li>It is an instance of <code>javax.xml.bind.JAXBElement</code>.</li>
33      * <li>The class of <code>object</code> is annotated with
34      * <code>&#64XmlRootElement</code>.
35      * </li>
36      * </ol>
37      *
38      * @see #getElementName(Object)
39      */

40     public abstract boolean isElement(Object JavaDoc object);
41
42     /**
43      * <p>Get xml element qname for <code>jaxbElement</code>.</p>
44      *
45      * @param jaxbElement is an object that {@link #isElement(Object)} returned true.
46      *
47      * @return xml element qname associated with jaxbElement;
48      * null if <code>jaxbElement</code> is not a JAXB Element.
49      */

50     public abstract QName JavaDoc getElementName(Object JavaDoc jaxbElement);
51
52     /**
53      * <p>Get the element value of a JAXB element.</p>
54      *
55      * <p>Convenience method to abstract whether working with either
56      * a javax.xml.bind.JAXBElement instance or an instance of
57      * <tt>&#64XmlRootElement</tt> annotated Java class.</p>
58      *
59      * @param jaxbElement object that #isElement(Object) returns true.
60      *
61      * @return The element value of the <code>jaxbElement</code>.
62      */

63     public static Object JavaDoc getValue(Object JavaDoc jaxbElement) {
64     if (jaxbElement instanceof JAXBElement) {
65         return ((JAXBElement)jaxbElement).getValue();
66     } else {
67         // assume that class of this instance is
68
// annotated with @XmlRootElement.
69
return jaxbElement;
70     }
71     }
72 }
73
Popular Tags