FileDocCategorySizeDatePackage
JAXBElement.javaAPI DocJava SE 6 API6381Tue Jun 10 00:27:04 BST 2008javax.xml.bind

JAXBElement

public class JAXBElement extends Object implements 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

  • element's xml tag name
  • value represents the element instance's atttribute(s) and content model
  • element declaration's declaredType (xs:element @type attribute)
  • scope of element declaration
  • boolean nil property. (element instance's xsi:nil attribute)

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

Fields Summary
protected final QName
name
xml element tag name
protected final Class
declaredType
Java datatype binding for xml element declaration's type.
protected final Class
scope
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.
protected T
value
xml element value. Represents content model and attributes of an xml element instance.
protected boolean
nil
true iff the xml element instance has xsi:nil="true".
private static final long
serialVersionUID
Constructors Summary
public JAXBElement(QName name, Class declaredType, Class scope, T value)

Construct 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()


                
         

                                                                                        
       
		         
		        
		         
        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);
    
public JAXBElement(QName name, Class declaredType, T value)
Construct an xml element instance. This is just a convenience method for new JAXBElement(name,declaredType,GlobalScope.class,value)

        this(name,declaredType,GlobalScope.class,value);
    
Methods Summary
public java.lang.ClassgetDeclaredType()
Returns the Java binding of the xml element declaration's type attribute.

        return declaredType;
    
public javax.xml.namespace.QNamegetName()
Returns the xml element tag name.

        return name;
    
public java.lang.ClassgetScope()
Returns scope of xml element declaration.

see
#isGlobalScope()
return
GlobalScope.class if this element is of global scope.

        return scope;
    
public TgetValue()

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

        return value;
    
public booleanisGlobalScope()
Returns true iff this xml element declaration is global.

        return this.scope == GlobalScope.class;
    
public booleanisNil()

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).

        return (value == null) || nil;
    
public booleanisTypeSubstituted()
Returns true iff this xml element instance's value has a different type than xml element declaration's declared type.

        if(value==null)     return false;
        return value.getClass() != declaredType;
    
public voidsetNil(boolean value)

Set whether this element has nil content.

see
#isNil()

        this.nil = value;
    
public voidsetValue(T t)

Set 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()

        this.value = t;