JDOM
2.0.5

org.jdom2
Class Content

java.lang.Object
  extended by org.jdom2.Content
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, NamespaceAware
Direct Known Subclasses:
Comment, DocType, Element, EntityRef, ProcessingInstruction, Text

public abstract class Content
extends java.lang.Object
implements java.io.Serializable, NamespaceAware

Superclass for JDOM objects which can be legal child content of Parent nodes.

Author:
Bradley S. Huffman, Jason Hunter, Rolf Lear
See Also:
Comment, DocType, Element, EntityRef, Parent, ProcessingInstruction, Text, Serialized Form

Nested Class Summary
static class Content.CType
          An enumeration useful for identifying content types without having to do instanceof type conditionals.
 
Field Summary
protected  Content.CType ctype
          The content type enumerate value for this Content
protected  Parent parent
          The parent Parent of this Content.
 
Constructor Summary
protected Content(Content.CType type)
          Create a new Content instance of a particular type.
 
Method Summary
 Content clone()
          Return a deep clone of this instance.
 Content detach()
          Detaches this child from its parent or does nothing if the child has no parent.
 boolean equals(java.lang.Object ob)
          This tests for equality of this Content object to the supplied object.
 Content.CType getCType()
          All content has an enumerated type expressing the type of content.
 Document getDocument()
          Return this child's owning document or null if the branch containing this child is currently not attached to a document.
 java.util.List<Namespace> getNamespacesInherited()
          Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.
 java.util.List<Namespace> getNamespacesInScope()
          Obtain a list of all namespaces that are in scope for the current content.
 java.util.List<Namespace> getNamespacesIntroduced()
          Obtain a list of all namespaces that are introduced to the XML tree by this node.
 Parent getParent()
          Return this child's parent, or null if this child is currently not attached.
 Element getParentElement()
          A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element.
abstract  java.lang.String getValue()
          Returns the XPath 1.0 string value of this child.
 int hashCode()
          This returns the hash code for this Content item.
protected  Content setParent(Parent parent)
          Sets the parent of this Content.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected transient Parent parent
The parent Parent of this Content. Note that the field is not serialized, thus deserialized Content instances are 'detached'


ctype

protected final Content.CType ctype
The content type enumerate value for this Content

Constructor Detail

Content

protected Content(Content.CType type)
Create a new Content instance of a particular type.

Parameters:
type - The Content.CType of this Content
Method Detail

getCType

public final Content.CType getCType()
All content has an enumerated type expressing the type of content. This makes it possible to use switch-type statements on the content.

Returns:
A CType enumerated value representing this content.

detach

public Content detach()
Detaches this child from its parent or does nothing if the child has no parent.

This method can be overridden by particular Content subclasses to return a specific type of Content (co-variant return type). All overriding subclasses must call super.detach();

Returns:
this child detached

getParent

public Parent getParent()
Return this child's parent, or null if this child is currently not attached. The parent can be either an Element or a Document.

This method can be overridden by particular Content subclasses to return a specific type of Parent (co-variant return type). All overriding subclasses must call super.getParent();

Returns:
this child's parent or null if none

getParentElement

public final Element getParentElement()
A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element. This was the original behavior of getParent() in JDOM Beta 9 which began returning Parent in Beta 10. This method provides a convenient upgrade path for JDOM Beta 10 and 1.0 users.

Returns:
the containing Element or null if unattached or a root element

setParent

protected Content setParent(Parent parent)
Sets the parent of this Content. The caller is responsible for removing any pre-existing parentage.

This method can be overridden by particular Content subclasses to return a specific type of Content (co-variant return type). All overriding subclasses must call super.setParent(Parent);

Parameters:
parent - new parent element
Returns:
the target element

getDocument

public Document getDocument()
Return this child's owning document or null if the branch containing this child is currently not attached to a document.

Returns:
this child's owning document or null if none

getValue

public abstract java.lang.String getValue()
Returns the XPath 1.0 string value of this child.

Returns:
xpath string value of this child.

clone

public Content clone()
Return a deep clone of this instance. Even if this instance has a parent, the returned clone will not.

All JDOM core classes are Cloneable, and never throw CloneNotSupportedException. Additionally all Cloneable JDOM classes return the correct type of instance from this method and there is no need to cast the result (co-variant return vaue).

Subclasses of this should still call super.clone() in their clone method.


equals

public final boolean equals(java.lang.Object ob)
This tests for equality of this Content object to the supplied object. Content items are considered equal only if they are referentially equal (i.e. the same object). User code may choose to compare objects based on their properties instead.

Overrides:
equals in class java.lang.Object
Parameters:
ob - Object to compare to.
Returns:
boolean - whether the Content is equal to the supplied Object.

hashCode

public final int hashCode()
This returns the hash code for this Content item.

Overrides:
hashCode in class java.lang.Object
Returns:
int - hash code.

getNamespacesInScope

public java.util.List<Namespace> getNamespacesInScope()
Description copied from interface: NamespaceAware
Obtain a list of all namespaces that are in scope for the current content.

The contents of this list will always be the combination of getNamespacesIntroduced() and getNamespacesInherited().

See NamespaceAware documentation for details on what the order of the Namespaces will be in the returned list.

Specified by:
getNamespacesInScope in interface NamespaceAware
Returns:
a read-only list of Namespaces.

getNamespacesIntroduced

public java.util.List<Namespace> getNamespacesIntroduced()
Description copied from interface: NamespaceAware
Obtain a list of all namespaces that are introduced to the XML tree by this node. Only Elements and Attributes can introduce namespaces, so all other Content types will return an empty list.

The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()

Specified by:
getNamespacesIntroduced in interface NamespaceAware
Returns:
a read-only list of Namespaces.

getNamespacesInherited

public java.util.List<Namespace> getNamespacesInherited()
Description copied from interface: NamespaceAware
Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.

The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()

Specified by:
getNamespacesInherited in interface NamespaceAware
Returns:
a read-only list of Namespaces.

JDOM
2.0.5

Copyright 2013 Jason Hunter, Brett McLaughlin. All Rights Reserved.