org.jdom
Class Entity


public class Entity
implements Cloneable, Serializable

Entity Defines an XML entity in Java.

Author:
Brett McLaughlin, Jason Hunter
Version: 1.0

Constructor Summary
Entity(String name)
           This will create a new Entity with the supplied name.

Method Summary
 EntityaddChild(Element element)
           This will add an Element as a child of this Entity.
 EntityaddChild(String s)
           This will add a String as a child of this Entity.
 EntityaddText(String text)
           This will add text to the content of this Entity.
 Objectclone()
           This will return a clone of this Entity.
 final booleanequals(Object ob)
           This tests for equality of this Entity to the supplied Object.
 ListgetChildren()
           This will return a List of all the XML elements nested directly (one level deep) within this Entity, each in Element form.
 StringgetContent()
           This will return the actual textual content of this Entity.
 DocumentgetDocument()
           This retrieves the owning Document for this Entity, or null if not a currently a member of a Document.
 ListgetMixedContent()
           This will return the content of the entity.
 StringgetName()
           This returns the name of the Entity.
 ElementgetParent()
           This will return the parent of this Entity.
 final StringgetSerializedForm()
           This will return the Comment in XML format, usable in an XML document.
 final inthashCode()
           This returns the hash code for this Entity.
 booleanhasMixedContent()
           This will indicate whether the entity has mixed content or not.
 EntitysetChildren(List children)
           This will set the children of this Entity to the Elements within the supplied :ost.
 EntitysetContent(String textContent)
           This will set the textual content of the Entity.
 EntitysetMixedContent(List mixedContent)
           This will return the content of the element.
 StringtoString()
           This returns a String representation of the Entity, suitable for debugging.

Constructor Detail

Entity

public Entity(String name)

This will create a new Entity with the supplied name.

Parameters:
name - String name of element.
Method Detail

addChild

public Entity addChild(Element element)

This will add an Element as a child of this Entity.

Parameters:
element - Element to add as a child.
Returns: Entity - this Entity modified.

addChild

public Entity addChild(String s)

This will add a String as a child of this Entity.

Parameters:
s - String to add as a child.
Returns: Entity - this Entity modified.

addText

public Entity addText(String text)

This will add text to the content of this Entity.

Parameters:
text - String to add as content.
Returns: Entity - this Entity modified.

clone

public Object clone()

This will return a clone of this Entity.

Returns: Object - clone of this Entity.

equals

public final boolean equals(Object ob)

This tests for equality of this Entity to the supplied Object.

Parameters:
ob - Object to compare to.
Returns: boolean - whether the Entity is equal to the supplied Object.

getChildren

public List getChildren()

This will return a List of all the XML elements nested directly (one level deep) within this Entity, each in Element form. If the Wntity has no nested elements, an empty list will be returned.

This performs no recursion, so an elements nested two levels deep would have to be obtained with:


List nestedElements = currentEntity.getChildren();
for (int i=0; i<nestedElements.size(); i++) {
Element oneLevelDeep = (Element)nestedElements.get(i);
List twoLevelsDeep = oneLevelDeep.getChildren();
// Do something with these children
}

Returns: List - list of nested Element instances for this entity.

getContent

public String getContent()

This will return the actual textual content of this Entity. This will include all text within this single element, including CDATA sections if they exist. If no textual value exists for the Entity, an empty String is returned.

Returns: String - value for this element.

getDocument

public Document getDocument()

This retrieves the owning Document for this Entity, or null if not a currently a member of a Document.

Returns: Document owning this Entity, or null.

getMixedContent

public List getMixedContent()

This will return the content of the entity. This should be used when the hasMixedContent() evaluates to true. When there is no mixed content, it returns a List with a single String (when only data is present) or a List with only elements (when only nested elements are present).

Returns: List - the mixed content of the Element: contains String, Element, and Comment, objects.

getName

public String getName()

This returns the name of the Entity.

Returns: String - entity name.

getParent

public Element getParent()

This will return the parent of this Entity. If there is no parent, then this returns null.

Returns: parent of this Entity

getSerializedForm

public final String getSerializedForm()

This will return the Comment in XML format, usable in an XML document.

Returns: String - the serialized form of the Comment.

hashCode

public final int hashCode()

This returns the hash code for this Entity.

Returns: int - hash code.

hasMixedContent

public boolean hasMixedContent()

This will indicate whether the entity has mixed content or not. Mixed content is when an element contains both textual and element data within it. When this evaluates to true, getMixedContent() should be used for getting element data.

Note:I think there's a better way to do this, maybe store a member variable, but I'm too tired to really think of what it is... (brett).

Returns: boolean - indicating whether there is mixed content (both textual data and elements).

setChildren

public Entity setChildren(List children)

This will set the children of this Entity to the Elements within the supplied :ost. All existing children of this Entity are replaced.

Parameters:
children - List of Elements to add.
Returns: Entity - this element modified.

setContent

public Entity setContent(String textContent)

This will set the textual content of the Entity. If this Entity will have both textual content and nested elements, setMixedContent(java.util.List) should be used instead,

Parameters:
textContent - String content for Entity.
Returns: Entity - this element modified.

setMixedContent

public Entity setMixedContent(List mixedContent)

This will return the content of the element. This should be used when the hasMixedContent() evaluates to true. When there is no mixed content, it returns a List with a single String (when only data is present) or a List with only elements (when only nested elements are present).

Returns: Entity - this entity modified.

toString

public String toString()

This returns a String representation of the Entity, suitable for debugging. If the XML representation of the Entity is desired, getSerializedForm() should be used.

Returns: String - information about the Entity

Association Links

to Class java.lang.String

The name of the Entity

to Class java.util.List

The mixed content of the Entity

to Class org.jdom.Element

Parent element, or null if none

to Class org.jdom.Document

Containing document node, or null if none