JAXBElement (Java EE 5)

Java EE API


javax.xml.bind Class JAXBElement<T>

java.lang.Object
  extended by javax.xml.bind.JAXBElement<T>
All Implemented Interfaces:
Serializable

public class JAXBElement<T>
extends Object
implements Serializable

Implements: java.io.Serializable

Xml 元素的 JAXB 表示形式。

此类表示关于 Xml 元素的信息,这些信息包括模式中的元素声明,以及具有以下属性的 xml 文档中的元素实例值,如下所示:

  • 元素的 xml 标记 name
  • value 表示元素实例的属性和内容模式
  • 元素声明的 declaredTypexs:element @type 属性)
  • 元素声明的 scope
  • boolean 值形式的 nil 属性。(元素实例的 xsi:nil 属性)

declaredTypescope 属性是 xml 类型定义的 JAXB 类绑定。

Scope 可以是 GlobalScope,也可以是表示包含模式元素声明的复杂类型定义的 Java 类。

这里有一个属性约束,即如果 valuenull,则 nil 一定为 true。反之则不然,以支持表示包含属性的 nil 元素。如果 nil 为 true,则 value 可能为非 null,这样它可以保存与 nil 元素关联的属性值。

英文文档:

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

Since:
JAXB 2.0
Author:
Kohsuke Kawaguchi, Joe Fialli
See Also:
Serialized Form

Nested Class Summary
static class
 
Field Summary
protected  Class<T>
protected  QName
protected  boolean
protected  Class
protected  T
 
Constructor Summary
 
Method Summary
 Class<T>
 QName
 Class
 T
 boolean
 boolean
 boolean
 void
 void
 
Methods inherited from class java.lang.Object
 

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


英文文档:

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 name
declaredType - Java binding of xml element declaration's type
scope - Java binding of scope of xml element declaration. Passing null is the same as passing GlobalScope.class
value - Java instance representing xml element's value.
See Also:
getScope(), isTypeSubstituted()


英文文档:

JAXBElement

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

Method Detail

public Class<T> getDeclaredType()
返回 xml 元素声明的类型属性的 Java 绑定。
英文文档:

getDeclaredType

public Class<T> getDeclaredType()
Returns the Java binding of the xml element declaration's type attribute.


public javax.xml.namespace.QName getName()
返回 xml 元素标记名称。
英文文档:

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 by true. Details of constraint are described at isNil().

See Also:
isTypeSubstituted()

public Object getValue()

返回此元素的内容模式和属性值。

关于此值为 null 时的属性约束的描述,请参见 #isNil()

英文文档:

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 is null


public Class<T> getScope()
返回 xml 元素声明的作用域。
return 如果此元素位于全局作用域中,则返回 GlobalScope.class
See also isGlobalScope()
英文文档:

getScope

public Class getScope()
Returns scope of xml element declaration.

Returns:
GlobalScope.class if this element is of global scope.
See Also:
isGlobalScope()

public boolean isNil()

如果此元素实例内容模式为 nil,则返回 true

#getValue() 为 null 时,此属性总是返回 true。注意,反之则不然,当此属性为 true 时,#getValue() 可以包含非 null 属性值。对于 nil xml 元素,包含属性是有效的。

英文文档:

isNil

public boolean isNil()

Returns true iff this element instance content model is nil.

This property always returns true when getValue() is null. Note that the converse is not true, when this property is true, getValue() can contain a non-null value for attribute(s). It is valid for a nil xml element to have attribute(s).


public void setNil(boolean value)

设置此属性是否包含 nil 内容。

See also isNil()
英文文档:

setNil

public void setNil(boolean value)

Set whether this element has nil content.

See Also:
isNil()

public boolean isGlobalScope()
如果此 xml 元素声明是全局性的,则返回 true。
英文文档:

isGlobalScope

public boolean isGlobalScope()
Returns true iff this xml element declaration is global.


public boolean isTypeSubstituted()
如果此 xml 元素实例的值的类型与 xml 元素声明的声明类型不同,则返回 true。
英文文档:

isTypeSubstituted

public boolean isTypeSubstituted()
Returns true iff this xml element instance's value has a different type than xml element declaration's declared type.



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!