/* * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javax.xml.bind; import javax.xml.namespace.QName; import java.io.Serializable; /** *
JAXB representation of an Xml Element.
* *This class represents information about an Xml Element from both the element * declaration within a schema and the element instance value within an xml document * with the following properties *
The declaredType and scope property are the * JAXB class binding for the xml type definition. *
* *Scope is either {@link GlobalScope} or the Java class representing the * complex type definition containing the schema element declaration. *
* *There is a property constraint that if value is null, * then nil must be true. The converse is not true to enable * representing a nil element with attribute(s). If nil is true, it is possible * that value is non-null so it can hold the value of the attributes * associated with a nil element. *
* * @author Kohsuke Kawaguchi, Joe Fialli * @since JAXB 2.0 */ public class JAXBElementConstruct an xml element instance.
* * @param name Java binding of xml element tag name * @param declaredType Java binding of xml element declaration's type * @param scope * Java binding of scope of xml element declaration. * Passing null is the same as passing GlobalScope.class * @param value * Java instance representing xml element's value. * @see #getScope() * @see #isTypeSubstituted() */ public JAXBElement(QName name, ClassSet the content model and attributes of this xml element.
* *When this property is set to null, isNil() must by true. * Details of constraint are described at {@link #isNil()}.
* * @see #isTypeSubstituted() */ public void setValue(T t) { this.value = t; } /** *Return the content model and attribute values for this element.
* *See {@link #isNil()} for a description of a property constraint when * this value is null
*/ public T getValue() { return value; } /** * Returns scope of xml element declaration. * * @see #isGlobalScope() * @return GlobalScope.class if this element is of global scope. */ public Class getScope() { return scope; } /** *Returns true iff this element instance content model * is nil.
* *This property always returns true when {@link #getValue()} is null. * Note that the converse is not true, when this property is true, * {@link #getValue()} can contain a non-null value for attribute(s). It is * valid for a nil xml element to have attribute(s).
*/ public boolean isNil() { return (value == null) || nil; } /** *Set whether this element has nil content.
* * @see #isNil() */ public void setNil(boolean value) { this.nil = value; } /* Convenience methods * (Not necessary but they do unambiguously conceptualize * the rationale behind this class' fields.) */ /** * Returns true iff this xml element declaration is global. */ public boolean isGlobalScope() { return this.scope == GlobalScope.class; } /** * Returns true iff this xml element instance's value has a different * type than xml element declaration's declared type. */ public boolean isTypeSubstituted() { if(value==null) return false; return value.getClass() != declaredType; } private static final long serialVersionUID = 1L; }