| java.lang.Object | |
| ↳ | com.google.gdata.model.Element |
Known Direct Subclasses
|
Known Indirect Subclasses
|
Data element in an instance document. Contains attributes, child elements, and a text node.
The various setter methods provided by this class return this
so setter invocations can be chained, as in the following example:
Element who = new Element(KEY)
.setAttributeValue(ATTR_KEY, "value")
.addElement(
new Element(EXT_KEY_NOEXT)
.setTextValue("yolk"));
Subclasses are expected to follow the same model for any setter methods they provide.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| LOGGER | |||||||||||
| key | The element key associated with this element. | ||||||||||
| state | The state of this element, contains all actual data. | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Construct element and associate with a key.
| |||||||||||
Construct a generic undeclared element with the specified qualified name.
| |||||||||||
Copy constructor that initializes a new Element instance to be a wrapper
around another element instance.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Add a child element with the given ID.
| |||||||||||
Add a child element with the given key.
| |||||||||||
Add a child element, using the key of the child element as the key into
this element's children.
| |||||||||||
Clears internal state of all attributes, child elements, and text content.
| |||||||||||
Helper method that constructs a new
Element instance of the type
defined by the type parameter E. | |||||||||||
Helper method that constructs a new
Element instance of the type
defined by the type parameter E. | |||||||||||
Returns the number of attributes present on this element.
| |||||||||||
Returns an iterator over the attributes of this element with a well-defined
iteration order based on the metadata.
| |||||||||||
Returns an iterator over all attributes on this element.
| |||||||||||
Get the value of an attribute by id.
| |||||||||||
Returns the attribute value cast to the appropriate type, based on the
given key.
| |||||||||||
Returns the default
ElementKey for an Element type. | |||||||||||
Get child element matching the specified key.
| |||||||||||
Get a child element matching the specified qualified name.
| |||||||||||
Returns the number of child elements present on this element.
| |||||||||||
Get the id of this element.
| |||||||||||
Returns an iterator over all child elements of this element.
| |||||||||||
Returns an iterator over all child elements with a well-defined iteration
order based on this metadata.
| |||||||||||
Returns the key to this element.
| |||||||||||
Get child elements matching the specified key.
| |||||||||||
Get child elements matching the specified id.
| |||||||||||
Convenience method to return child element's text node cast to
the specified type.
| |||||||||||
Convenience method to return child element's text node as an object.
| |||||||||||
Returns an immutable list of elements matching the given id.
| |||||||||||
Get child elements matching the specified key.
| |||||||||||
Returns the element value adapted to the key's datatype.
| |||||||||||
Returns the untyped element value or null if it has no value.
| |||||||||||
Returns true if the element has an attribute with the given key.
| |||||||||||
Returns true if the element has an attribute with the given id.
| |||||||||||
Returns true if the element has child element(s) with the given id.
| |||||||||||
Returns true if the element has child element(s) with the given key.
| |||||||||||
Returns true if this element has been locked using
lock(). | |||||||||||
Locks this element.
| |||||||||||
This method is deprecated.
use removeAttributeValue instead.
| |||||||||||
This method is deprecated.
use removeAttributeValue instead.
| |||||||||||
Remove attribute (if present).
| |||||||||||
Remove attribute (if present).
| |||||||||||
Remove a single child element from this element.
| |||||||||||
Remove child element(s) of a given name.
| |||||||||||
Remove child element(s) of a given name.
| |||||||||||
Remove a single child element from this element.
| |||||||||||
Replace one element with another.
| |||||||||||
Resolve this element's state against the metadata.
| |||||||||||
Resolve the state of all elements in the tree, rooted at this
element, against the metadata.
| |||||||||||
Add attribute by value.
| |||||||||||
Add attribute by id and value.
| |||||||||||
Sets a child element to the given value.
| |||||||||||
Sets the value of the child element(s) with the given id.
| |||||||||||
Sets the value of the child element(s) with the
key. | |||||||||||
Sets the value of the element and returns the element to allow chaining.
| |||||||||||
Visits the element using the specified
ElementVisitor and metadata. | |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adapts an element based on a key.
| |||||||||||
Adapts an element based on a different key.
| |||||||||||
Helper method to check for equality between two object, including null
checks.
| |||||||||||
Narrow down element's type to the most specific one possible.
| |||||||||||
Validate the element using the given metadata, and placing any errors into
the validation context.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
The state of this element, contains all actual data. This allows shallow copies to be very efficient.
Construct element and associate with a key.
| elementKey | The key to this element, contains the ID and datatype. |
|---|
Construct a generic undeclared element with the specified qualified name.
| qName | Qualified name |
|---|
Copy constructor that initializes a new Element instance to be a wrapper around another element instance. The element will use the given element as its source for any content.
| elementKey | The element key to associate with the copy. |
|---|---|
| source | The element to copy data from. |
Add a child element with the given ID. This will add the given element to
the end of the collection of elements with the same ID. If you want to
replace any existing elements use setElement(QName, Element)
instead.
| id | The qualified name to use for the child |
|---|---|
| element | Child element |
| NullPointerException | if element is null. |
|---|
Add a child element with the given key. This will add the given element to
the end of the collection of elements with the same ID. If you want to
replace any existing elements use setElement(ElementKey, Element)
instead.
| key | The key of the child. |
|---|---|
| element | Child element |
Add a child element, using the key of the child element as the key into this element's children.
| element | Child element |
|---|
| NullPointerException | if element is null. |
|---|
Clears internal state of all attributes, child elements, and text content.
Helper method that constructs a new Element instance of the type
defined by the type parameter E.
| key | The element key to create the element for. |
|---|---|
| source | The source element to use, or null if a fresh instance should be created. |
| ContentCreationException | if content cannot be created |
|---|
Helper method that constructs a new Element instance of the type
defined by the type parameter E.
| key | The element key to create the element from |
|---|
| ContentCreationException | if content cannot be created |
|---|
| obj |
|---|
Returns the number of attributes present on this element.
Returns an iterator over the attributes of this element with a well-defined iteration order based on the metadata. All declared attributes are returned first, in the order of declaration, followed by undeclared attributes in the order in which they were added to this element. If the metadata declares virtual attributes, those attributes will be included in the iterator, likewise any attributes which are hidden will be excluded.
| metadata | The element metadata to use for iteration |
|---|
Returns an iterator over all attributes on this element.
Returns the attribute value cast to the appropriate type, based on the given key.
| key | The attribute key to use to cast the attribute value |
|---|
| IllegalArgumentException | if the value cannot be converted to the key type |
|---|
Returns the default ElementKey for an Element type.
| type | Element type |
|---|
Get child element matching the specified key. Will try to adapt the element to the given key if it is not already an instance of the requested class. This will fail with an exception if the adaptation was not valid.
| childKey | The metadata key for the child element to retrieve |
|---|
null if none was found| IllegalArgumentException | if the key referenced a repeating element |
|---|
Get a child element matching the specified qualified name.
| id | The qualified name of the child to retrieve |
|---|
null if none was found| IllegalArgumentException | if the id referenced a repeating element |
|---|
Returns the number of child elements present on this element.
Returns an iterator over all child elements of this element.
Returns an iterator over all child elements with a well-defined iteration order based on this metadata. All declared elements are returned first, in the order of declaration, followed by undeclared elements in the order in which they were added to this element. If the metadata declares virtual elements, those elements will be included in the iterator, likewise any elements which are hidden will be excluded.
| metadata | The metadata to use for iteration |
|---|
Get child elements matching the specified key. This set cannot be
used to add new child elements, instead the addElement(Element)
method should be used. If the elements at the given key are not of the
correct type an IllegalArgumentException will be thrown.
| key | The child key to lookup child elements based on. |
|---|
Get child elements matching the specified id. This set cannot be used
to add new child elements, instead the addElement(Element) method
should be used.
| id |
|---|
Convenience method to return child element's text node cast to
the specified type. Returns null if child element does
not exist or has no text node.
| key | Identifying the child element. |
|---|
V,
or null if child element does not exist or has no
text node
Convenience method to return child element's text node as an object.
Returns null if child doesn't exist or child does not have a text
node.
| id |
|---|
Returns an immutable list of elements matching the given id.
| id |
|---|
Get child elements matching the specified key. This list cannot be
used to add new child elements, instead the addElement(Element)
method should be used. If the elements at the given key are not of the
correct type an IllegalArgumentException will be thrown.
| key | Child key to lookup child elements based on. |
|---|
Returns the element value adapted to the key's datatype.
| key | The element key used to convert the value. |
|---|
Returns the untyped element value or null if it has no value.
Returns true if the element has an attribute with the given key.
| childKey |
|---|
Returns true if the element has an attribute with the given id.
| id |
|---|
Returns true if the element has child element(s) with the given id.
| id |
|---|
Returns true if the element has child element(s) with the given key.
| childKey |
|---|
Returns true if this element has been locked using lock(). Once an
element has been locked it cannot be unlocked.
Locks this element. A locked element cannot have any changes made to its content or its attributes or child elements. This will also lock all attributes and child elements as well. Once this method has been called, this element can be safely published to other threads.
This method is deprecated.
use removeAttributeValue instead.
| key |
|---|
This method is deprecated.
use removeAttributeValue instead.
| id |
|---|
Remove attribute (if present).
| key | The key of the attribute. |
|---|
Remove attribute (if present).
| id | The qualified name of the attribute. |
|---|
Remove a single child element from this element. This method returns true if the element was found and removed, or false if it was not. It uses identity and not equality to find a match.
| element | The child element to remove. |
|---|
Remove child element(s) of a given name. All elements with the given id will be removed.
| id | The id of the child element(s) to remove. |
|---|
Remove child element(s) of a given name. All elements with the same ID as the given key will be removed.
| childKey | Key of the element(s) to remove. |
|---|
Remove a single child element from this element. This method returns true if the element was found and removed, or false if it was not. It uses identity and not equality to find a match.
| childKey | The key for the child element to remove. |
|---|---|
| element | The child element to remove. |
Replace one element with another. If the element to add has the same id as the one that is being replaced, it will be switch in place, maintaining order in repeating or undeclared elements.
| toRemove | Element to remove. |
|---|---|
| toAdd | Element to add. |
Resolve this element's state against the metadata. Accumulates errors in caller's validation context.
| metadata | |
|---|---|
| vc | Validation context |
Resolve the state of all elements in the tree, rooted at this element, against the metadata. Throws an exception if the tree cannot be resolved.
| metadata | The metadata to resolve against. |
|---|
| ContentValidationException | if tree cannot be resolved |
|---|
Add attribute by value. If the value is null the value will be
removed.
| key | Attribute key that is being added |
|---|---|
| attrValue | Attribute value or null to remove
|
Add attribute by id and value. If the value is null this is
equivalent to removing the attribute with the given id.
| id | |
|---|---|
| attrValue |
Sets a child element to the given value. Uses the element key of the
element as the key. This is equivalent to calling
setElement(element.getElementKey(), element);.
| element |
|---|
| NullPointerException | if element is null. |
|---|
Sets the value of the child element(s) with the given id. The given element
will replace all existing elements at the given id. If the given element
is null, this is equivalent to removeElement(QName).
| id | |
|---|---|
| element |
Sets the value of the child element(s) with the key. The
element will replace all existing elements with the same key. If
element is null, this is equivalent to removeElement(ElementKey).
| key | The key for the child element |
|---|---|
| element | Child element |
Sets the value of the element and returns the element to allow chaining.
| newValue | Element's value |
|---|
| IllegalStateException | if the element is immutable |
|---|---|
| IllegalArgumentException | if the object is of an invalid type or if this element does not allow a value |
Visits the element using the specified ElementVisitor and metadata.
A null metadata indicates that the element is undeclared, and
child elements will be visited in the order they were added to the element.
| ev | The element visitor instance to use. |
|---|---|
| meta | The metadata for the element, or null for undeclared
metadata. |
| ElementVisitor.StoppedException | if traversal must be stopped |
|---|
Adapts an element based on a key. This will find an adaptation in the metadata and adapt to that metadata type (and element type). If no adaptation is found this will return the source element.
| source | The element we are narrowing from. |
|---|---|
| sourceMeta | The source metadata to adapt from. |
| kind | The kind name to lookup the adaptation for. |
Adapts an element based on a different key. If the key represents
a more narrow type than source, an instance of the more narrow
type will be returned, containing the same information as the source. If
the source is null, a null instance of T will be returned.
| key | The element key to adapt to. |
|---|---|
| source | The element we are adapting from. |
| ContentCreationException | if the metadata cannot be used to adapt. |
|---|---|
| NullPointerException | if meta is null. |
Helper method to check for equality between two object, including null checks.
| o1 | Object 1 or null |
|---|---|
| o2 | Object 2 or null |
Narrow down element's type to the most specific one possible.
Any validation errors discovered during narrowing are accumulated in the validation context.
Default action is to not do anything with current element. Subclasses may override this function to narrow the type in some custom fashion.
| metadata | The element metadata to narrow to. |
|---|---|
| vc | Validation context |
| o | Given object |
|---|
Validate the element using the given metadata, and placing any errors into the validation context. The default behavior is to use the metadata validation, subclasses may override this to add their own validation. If the metadata is null (undeclared), no validation will be performed.
| metadata | |
|---|---|
| vc |