Class JAXBElement<T>
- java.lang.Object
-
- jakarta.xml.bind.JAXBElement<T>
-
- All Implemented Interfaces:
Serializable
public class JAXBElement<T> extends Object implements Serializable
Jakarta XML Binding 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 valuerepresents the element instance's attribute(s) and content model- element declaration's
declaredType(xs:element @typeattribute) scopeof element declaration- boolean
nilproperty. (element instance'sxsi:nilattribute)
The
declaredTypeandscopeproperty are the Jakarta XML Binding class binding for the xml type definition.Scopeis eitherJAXBElement.GlobalScopeor the Java class representing the complex type definition containing the schema element declaration.There is a property constraint that if
valueisnull, thennilmust betrue. The converse is not true to enable representing a nil element with attribute(s). Ifnilis true, it is possible thatvalueis non-null so it can hold the value of the attributes associated with a nil element.- Since:
- 1.6, JAXB 2.0
- Author:
- Kohsuke Kawaguchi, Joe Fialli
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJAXBElement.GlobalScopeDesignates global scope for an xml element.
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>declaredTypeJava datatype binding for xml element declaration's type.protected QNamenamexml element tag nameprotected booleanniltrue iff the xml element instance has xsi:nil="true".protected Class<?>scopeScope of xml element declaration representing this xml element instance.protected Tvaluexml element value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class<T>getDeclaredType()Returns the Java binding of the xml element declaration's type attribute.QNamegetName()Returns the xml element tag name.Class<?>getScope()Returns scope of xml element declaration.TgetValue()Return the content model and attribute values for this element.booleanisGlobalScope()Returns true iff this xml element declaration is global.booleanisNil()Returnstrueiff this element instance content model is nil.booleanisTypeSubstituted()Returns true iff this xml element instance's value has a different type than xml element declaration's declared type.voidsetNil(boolean value)Set whether this element has nil content.voidsetValue(T t)Set the content model and attributes of this xml element.
-
-
-
Field Detail
-
name
protected final QName name
xml element tag name
-
declaredType
protected final Class<T> declaredType
Java datatype binding for xml element declaration's type.
-
scope
protected final Class<?> scope
Scope of xml element declaration representing this xml element instance. Can be one of the following values: -JAXBElement.GlobalScopefor global xml element declaration. - local element declaration has a scope set to the Java class representation of complex type defintion containing xml element declaration.
-
value
protected T value
xml element value. Represents content model and attributes of an xml element instance.
-
nil
protected boolean nil
true iff the xml element instance has xsi:nil="true".
-
-
Constructor Detail
-
JAXBElement
public JAXBElement(QName name, Class<T> declaredType, Class<?> scope, T value)
Construct an xml element instance.
- Parameters:
name- Java binding of xml element tag namedeclaredType- Java binding of xml element declaration's typescope- Java binding of scope of xml element declaration. Passing null is the same as passingGlobalScope.classvalue- Java instance representing xml element's value.- See Also:
getScope(),isTypeSubstituted()
-
-
Method Detail
-
getDeclaredType
public Class<T> getDeclaredType()
Returns the Java binding of the xml element declaration's type attribute.
-
getName
public QName getName()
Returns the xml element tag name.
-
setValue
public void setValue(T t)
Set the content model and attributes of this xml element.
When this property is set to
null,isNil()must bytrue. Details of constraint are described atisNil().- See Also:
isTypeSubstituted()
-
getValue
public T getValue()
Return the content model and attribute values for this element.
See
isNil()for a description of a property constraint when this value isnull
-
getScope
public Class<?> getScope()
Returns scope of xml element declaration.- Returns:
GlobalScope.classif this element is of global scope.- See Also:
isGlobalScope()
-
isNil
public boolean isNil()
Returns
trueiff this element instance content model is nil.This property always returns
truewhengetValue()is null. Note that the converse is not true, when this property istrue,getValue()can contain a non-null value for attribute(s). It is valid for a nil xml element to have attribute(s).
-
setNil
public void setNil(boolean value)
Set whether this element has nil content.
- See Also:
isNil()
-
isGlobalScope
public boolean isGlobalScope()
Returns true iff this xml element declaration is global.
-
isTypeSubstituted
public boolean isTypeSubstituted()
Returns true iff this xml element instance's value has a different type than xml element declaration's declared type.
-
-