/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package javax.xml.bind;
import javax.xml.namespace.QName;
import java.io.Serializable;
/**
* <p>JAXB representation of an Xml Element.</p>
*
* <p>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
* <ul>
* <li>element's xml tag <b><tt>name</tt></b></li>
* <li><b><tt>value</tt></b> represents the element instance's atttribute(s) and content model</li>
* <li>element declaration's <b><tt>declaredType</tt></b> (<tt>xs:element @type</tt> attribute)</li>
* <li><b><tt>scope</tt></b> of element declaration</li>
* <li>boolean <b><tt>nil</tt></b> property. (element instance's <tt><b>xsi:nil</b></tt> attribute)</li>
* </ul>
*
* <p>The <tt>declaredType</tt> and <tt>scope</tt> property are the
* JAXB class binding for the xml type definition.
* </p>
*
* <p><b><tt>Scope</tt></b> is either {@link GlobalScope} or the Java class representing the
* complex type definition containing the schema element declaration.
* </p>
*
* <p>There is a property constraint that if <b><tt>value</tt></b> is <tt>null</tt>,
* then <tt>nil</tt> must be <tt>true</tt>. The converse is not true to enable
* representing a nil element with attribute(s). If <tt>nil</tt> is true, it is possible
* that <tt>value</tt> is non-null so it can hold the value of the attributes
* associated with a nil element.
* </p>
*
* @author Kohsuke Kawaguchi, Joe Fialli
* @since JAXB 2.0
*/
public class JAXBElement<T> implements Serializable {
/** xml element tag name */
final protected QName name;
/** Java datatype binding for xml element declaration's type. */
final protected Class<T> declaredType;
/** Scope of xml element declaration representing this xml element instance.
* Can be one of the following values:
* - {@link GlobalScope} for global xml element declaration.
* - local element declaration has a scope set to the Java class
* representation of complex type defintion containing
* xml element declaration.
*/
final protected Class scope;
/** xml element value.
Represents content model and attributes of an xml element instance. */
protected T value;
/** true iff the xml element instance has xsi:nil="true". */
protected boolean nil = false;
/**
* Designates global scope for an xml element.
*/
public static final class GlobalScope {}
/**
* <p>Construct an xml element instance.</p>
*
* @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 <tt>GlobalScope.class</tt>
* @param value
* Java instance representing xml element's value.
* @see #getScope()
* @see #isTypeSubstituted()
*/
public JAXBElement(QName name,
Class<T> declaredType,
Class scope,
T value) {
if(declaredType==null || name==null)
throw new IllegalArgumentException();
this.declaredType = declaredType;
if(scope==null) scope = GlobalScope.class;
this.scope = scope;
this.name = name;
setValue(value);
}
/**
* Construct an xml element instance.
=1= |