org.jdom
Class Entity

java.lang.Object
  |
  +--org.jdom.Entity

public class Entity
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Entity Defines an XML entity in Java.

Version:
1.0
Author:
Brett McLaughlin, Jason Hunter
See Also:
Serialized Form

Field Summary
protected  java.util.List content
          The mixed content of the Entity
protected  java.lang.String name
          The name of the Entity
 
Constructor Summary
protected Entity()
           Default, no-args constructor for implementations to use if needed.
  Entity(java.lang.String name)
           This will create a new Entity with the supplied name.
 
Method Summary
 Entity addChild(Element element)
           This will add an Element as a child of this Entity.
 Entity addChild(java.lang.String s)
           This will add a String as a child of this Entity.
 Entity addText(java.lang.String text)
           This will add text to the content of this Entity.
 java.lang.Object clone()
           This will return a clone of this Entity.
 boolean equals(java.lang.Object ob)
           This tests for equality of this Entity to the supplied Object.
 java.util.List getChildren()
           This will return a List of all the XML elements nested directly (one level deep) within this Entity, each in Element form.
 java.lang.String getContent()
           This will return the actual textual content of this Entity.
 java.util.List getMixedContent()
           This will return the content of the entity.
 java.lang.String getName()
           This returns the name of the Entity.
 java.lang.String getSerializedForm()
           This will return the Comment in XML format, usable in an XML document.
 int hashCode()
           This returns the hash code for this Entity.
 boolean hasMixedContent()
           This will indicate whether the entity has mixed content or not.
 Entity setChildren(java.util.List children)
           This will set the children of this Entity to the Elements within the supplied :ost.
 Entity setContent(java.lang.String textContent)
           This will set the textual content of the Entity.
 Entity setMixedContent(java.util.List mixedContent)
           This will return the content of the element.
 java.lang.String toString()
           This returns a String representation of the Entity, suitable for debugging.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of the Entity

content

protected java.util.List content
The mixed content of the Entity
Constructor Detail

Entity

protected Entity()

Default, no-args constructor for implementations to use if needed.


Entity

public Entity(java.lang.String name)

This will create a new Entity with the supplied name.

Parameters:
name - String name of element.
Method Detail

getName

public java.lang.String getName()

This returns the name of the Entity.

Returns:
String - entity name.

getContent

public java.lang.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.

setContent

public Entity setContent(java.lang.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.

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

getMixedContent

public java.util.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.

setMixedContent

public Entity setMixedContent(java.util.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.

getChildren

public java.util.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.

setChildren

public Entity setChildren(java.util.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.

addText

public Entity addText(java.lang.String text)

This will add text to the content of this Entity.

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

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(java.lang.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.

toString

public final java.lang.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
Overrides:
toString in class java.lang.Object

getSerializedForm

public final java.lang.String getSerializedForm()

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

Returns:
String - the serialized form of the Comment.

equals

public final boolean equals(java.lang.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.
Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()

This returns the hash code for this Entity.

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

clone

public final java.lang.Object clone()

This will return a clone of this Entity.

Returns:
Object - clone of this Entity.
Overrides:
clone in class java.lang.Object


Copyright © 2000 Brett McLaughlin, Jason Hunter. All Rights Reserved.