325N/A/*
325N/A * Copyright (c) 2004, 2010, 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;
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/A/**
325N/A * Provide access to JAXB xml binding data for a JAXB object.
325N/A *
325N/A * <p>
325N/A * Intially, the intent of this class is to just conceptualize how
325N/A * a JAXB application developer can access xml binding information,
325N/A * independent if binding model is java to schema or schema to java.
325N/A * Since accessing the XML element name related to a JAXB element is
325N/A * a highly requested feature, demonstrate access to this
325N/A * binding information.
325N/A *
325N/A * The factory method to get a <code>JAXBIntrospector</code> instance is
325N/A * {@link JAXBContext#createJAXBIntrospector()}.
325N/A *
325N/A * @see JAXBContext#createJAXBIntrospector()
325N/A * @since JAXB2.0
325N/A */
325N/Apublic abstract class JAXBIntrospector {
325N/A
325N/A /**
325N/A * <p>Return true iff <code>object</code> represents a JAXB element.</p>
325N/A * <p>Parameter <code>object</code> is a JAXB element for following cases:
325N/A * <ol>
325N/A * <li>It is an instance of <code>javax.xml.bind.JAXBElement</code>.</li>
325N/A * <li>The class of <code>object</code> is annotated with
325N/A * <code>&#64XmlRootElement</code>.
325N/A * </li>
325N/A * </ol>
325N/A *
325N/A * @see #getElementName(Object)
325N/A */
325N/A public abstract boolean isElement(Object object);
325N/A
325N/A /**
325N/A * <p>Get xml element qname for <code>jaxbElement</code>.</p>
325N/A *
325N/A * @param jaxbElement is an object that {@link #isElement(Object)} returned true.
325N/A *
325N/A * @return xml element qname associated with jaxbElement;
325N/A * null if <code>jaxbElement</code> is not a JAXB Element.
325N/A */
325N/A public abstract QName getElementName(Object jaxbElement);
325N/A
325N/A /**
325N/A * <p>Get the element value of a JAXB element.</p>
325N/A *
325N/A * <p>Convenience method to abstract whether working with either
325N/A * a javax.xml.bind.JAXBElement instance or an instance of
325N/A * <tt>&#64XmlRootElement</tt> annotated Java class.</p>
325N/A *
325N/A * @param jaxbElement object that #isElement(Object) returns true.
325N/A *
325N/A * @return The element value of the <code>jaxbElement</code>.
325N/A */
325N/A public static Object getValue(Object jaxbElement) {
325N/A if (jaxbElement instanceof JAXBElement) {
325N/A return ((JAXBElement)jaxbElement).getValue();
325N/A } else {
325N/A // assume that class of this instance is
325N/A // annotated with @XmlRootElement.
325N/A return jaxbElement;
325N/A }
325N/A }
325N/A}