src/share/jaxws_classes/javax/xml/bind/JAXBIntrospector.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/bind/JAXBIntrospector.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,92 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.bind;
    1.30 +import  javax.xml.namespace.QName;
    1.31 +
    1.32 +/**
    1.33 + * Provide access to JAXB xml binding data for a JAXB object.
    1.34 + *
    1.35 + * <p>
    1.36 + * Intially, the intent of this class is to just conceptualize how
    1.37 + * a JAXB application developer can access xml binding information,
    1.38 + * independent if binding model is java to schema or schema to java.
    1.39 + * Since accessing the XML element name related to a JAXB element is
    1.40 + * a highly requested feature, demonstrate access to this
    1.41 + * binding information.
    1.42 + *
    1.43 + * The factory method to get a <code>JAXBIntrospector</code> instance is
    1.44 + * {@link JAXBContext#createJAXBIntrospector()}.
    1.45 + *
    1.46 + * @see JAXBContext#createJAXBIntrospector()
    1.47 + * @since JAXB2.0
    1.48 + */
    1.49 +public abstract class JAXBIntrospector {
    1.50 +
    1.51 +    /**
    1.52 +     * <p>Return true iff <code>object</code> represents a JAXB element.</p>
    1.53 +     * <p>Parameter <code>object</code> is a JAXB element for following cases:
    1.54 +     * <ol>
    1.55 +     *   <li>It is an instance of <code>javax.xml.bind.JAXBElement</code>.</li>
    1.56 +     *   <li>The class of <code>object</code> is annotated with
    1.57 +     *       <code>&#64XmlRootElement</code>.
    1.58 +     *   </li>
    1.59 +     * </ol>
    1.60 +     *
    1.61 +     * @see #getElementName(Object)
    1.62 +     */
    1.63 +    public abstract boolean isElement(Object object);
    1.64 +
    1.65 +    /**
    1.66 +     * <p>Get xml element qname for <code>jaxbElement</code>.</p>
    1.67 +     *
    1.68 +     * @param jaxbElement is an object that {@link #isElement(Object)} returned true.
    1.69 +     *
    1.70 +     * @return xml element qname associated with jaxbElement;
    1.71 +     *         null if <code>jaxbElement</code> is not a JAXB Element.
    1.72 +     */
    1.73 +    public abstract QName getElementName(Object jaxbElement);
    1.74 +
    1.75 +    /**
    1.76 +     * <p>Get the element value of a JAXB element.</p>
    1.77 +     *
    1.78 +     * <p>Convenience method to abstract whether working with either
    1.79 +     *    a javax.xml.bind.JAXBElement instance or an instance of
    1.80 +     *    <tt>&#64XmlRootElement</tt> annotated Java class.</p>
    1.81 +     *
    1.82 +     * @param jaxbElement  object that #isElement(Object) returns true.
    1.83 +     *
    1.84 +     * @return The element value of the <code>jaxbElement</code>.
    1.85 +     */
    1.86 +    public static Object getValue(Object jaxbElement) {
    1.87 +        if (jaxbElement instanceof JAXBElement) {
    1.88 +            return ((JAXBElement)jaxbElement).getValue();
    1.89 +        } else {
    1.90 +            // assume that class of this instance is
    1.91 +            // annotated with @XmlRootElement.
    1.92 +            return jaxbElement;
    1.93 +        }
    1.94 +    }
    1.95 +}

mercurial