net.sourceforge.spedit.core
Class XMLElement

java.lang.Object
  |
  +--org.jdom.Element
        |
        +--net.sourceforge.spedit.core.XMLElement
All Implemented Interfaces:
Cloneable, Serializable

public class XMLElement
extends org.jdom.Element

The XMLElement is a subclass of the JDOM Element class that allows it to wrapped by XMLElementWrapper objects.

The interest is that the XMLElement can be used both in a JDOM and in a Swing document model, thus allowing the manipuation with the JDOM API to be reflected visually by the Swing text representation mechanisms.

This class differs in some ways from its JDOM parent, it is a little bit slower but notifies the containing XMLDocument of any ongoing changes, thus allowing to use either the JDOM model or the Swing model for document content manipulation.

See Also:
Serialized Form

Field Summary
protected  int contentLength
           
static int INITIAL_ARRAY_SIZE
           
protected  int startOffset
           
protected  XMLElementWrapper wrapper
           
protected  XMLAttributes xmlAttributes
           
 
Fields inherited from class org.jdom.Element
additionalNamespaces, attributes, content, name, namespace, parent
 
Constructor Summary
XMLElement()
          Creates a new XMLElement with the name "default"
XMLElement(String name)
          Creates a new XMLElement with the given name and parent.
XMLElement(String name, org.jdom.Namespace namespace)
          Creates a new XMLElement with the given name and parent.
XMLElement(String name, String uri)
          Creates a new XMLElement with the given name and parent.
XMLElement(String name, String prefix, String uri)
          Creates a new XMLElement with the given name and parent.
 
Method Summary
 org.jdom.Element addAttribute(org.jdom.Attribute attr)
           
 org.jdom.Element addAttribute(String name, String value)
           
 org.jdom.Element addContent(org.jdom.CDATA cdata)
           
 org.jdom.Element addContent(org.jdom.Comment comment)
           
 org.jdom.Element addContent(org.jdom.Element element)
           
 org.jdom.Element addContent(org.jdom.EntityRef entity)
           
 org.jdom.Element addContent(org.jdom.ProcessingInstruction pi)
           
 org.jdom.Element addContent(String text)
           
 org.jdom.Element addContent(XMLText text)
           
protected  void fireInsertEvent(int offset, String text, Element elt)
          Fires an insertion document event to the containing XMLDocument if it exists.
 List getContent()
           
 org.jdom.Document getDocument()
          Returns the document attached to this XMLElement.
 XMLElementWrapper getWrapper()
          Returns the Wrapper attached to this XMLElement.
protected  void init()
           
 boolean removeAttribute(String name)
           
 boolean removeAttribute(String name, org.jdom.Namespace ns)
           
 org.jdom.Element setAttribute(org.jdom.Attribute attribute)
           
 org.jdom.Element setAttribute(String name, String value)
           
 org.jdom.Element setAttribute(String name, String value, org.jdom.Namespace ns)
           
 org.jdom.Element setAttributes(List attributes)
           
 void setDocument(XMLDocument doc)
          Sets the parent document of this XMLElement.
 void setNewContent(List content)
          This method is provided to set a whole new content that includes XMLText nodes in it.
protected  org.jdom.Element silentAddContent(XMLText text)
          Just the same as the addContent method, but this time no notice is made to the containing document.
 
Methods inherited from class org.jdom.Element
addNamespaceDeclaration, clone, detach, equals, getAdditionalNamespaces, getAttribute, getAttribute, getAttributes, getAttributeValue, getAttributeValue, getChild, getChild, getChildren, getChildren, getChildren, getChildText, getChildText, getChildTextTrim, getChildTextTrim, getCopy, getCopy, getMixedContent, getName, getNamespace, getNamespace, getNamespacePrefix, getNamespaceURI, getParent, getQualifiedName, getSerializedForm, getText, getTextNormalize, getTextTrim, hasChildren, hashCode, hasMixedContent, isRootElement, removeAttribute, removeChild, removeChild, removeChildren, removeChildren, removeChildren, removeContent, removeContent, removeContent, removeContent, removeContent, removeNamespaceDeclaration, setChildren, setContent, setDocument, setMixedContent, setName, setNamespace, setParent, setText, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INITIAL_ARRAY_SIZE

public static final int INITIAL_ARRAY_SIZE

contentLength

protected int contentLength

startOffset

protected int startOffset

wrapper

protected XMLElementWrapper wrapper

xmlAttributes

protected XMLAttributes xmlAttributes
Constructor Detail

XMLElement

public XMLElement()
Creates a new XMLElement with the name "default"

XMLElement

public XMLElement(String name)
Creates a new XMLElement with the given name and parent.

XMLElement

public XMLElement(String name,
                  org.jdom.Namespace namespace)
Creates a new XMLElement with the given name and parent.

XMLElement

public XMLElement(String name,
                  String uri)
Creates a new XMLElement with the given name and parent.

XMLElement

public XMLElement(String name,
                  String prefix,
                  String uri)
Creates a new XMLElement with the given name and parent.
Method Detail

init

protected void init()

addAttribute

public org.jdom.Element addAttribute(org.jdom.Attribute attr)
Overrides:
addAttribute in class org.jdom.Element

addAttribute

public org.jdom.Element addAttribute(String name,
                                     String value)
Overrides:
addAttribute in class org.jdom.Element

setAttribute

public org.jdom.Element setAttribute(org.jdom.Attribute attribute)
Overrides:
setAttribute in class org.jdom.Element

setAttribute

public org.jdom.Element setAttribute(String name,
                                     String value)
Overrides:
setAttribute in class org.jdom.Element

setAttribute

public org.jdom.Element setAttribute(String name,
                                     String value,
                                     org.jdom.Namespace ns)
Overrides:
setAttribute in class org.jdom.Element

setAttributes

public org.jdom.Element setAttributes(List attributes)
Overrides:
setAttributes in class org.jdom.Element

removeAttribute

public boolean removeAttribute(String name)
Overrides:
removeAttribute in class org.jdom.Element

removeAttribute

public boolean removeAttribute(String name,
                               org.jdom.Namespace ns)
Overrides:
removeAttribute in class org.jdom.Element

getContent

public List getContent()
Overrides:
getContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(org.jdom.Element element)
Overrides:
addContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(String text)
Overrides:
addContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(XMLText text)

silentAddContent

protected org.jdom.Element silentAddContent(XMLText text)
Just the same as the addContent method, but this time no notice is made to the containing document. This is used by the newContent method.
Parameters:
text - The XMLText to be inserted.
See Also:
#newContent

setNewContent

public void setNewContent(List content)

This method is provided to set a whole new content that includes XMLText nodes in it. The current implementation (Beta7) of JDOM does not allow redefine the setContent method, so the actual is a kind of turnaround.

Note that this method does not notify the document of changes that occured. This is important because every other addition or removal method notifies the containing document. This method allows the wrapper to modify the actual content without duplicating notifications, even allowing optimizations in the notification.

If this seems unclear, just don't use this method ;)

Parameters:
content - The new content of this XMLElement

addContent

public org.jdom.Element addContent(org.jdom.Comment comment)
Overrides:
addContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(org.jdom.EntityRef entity)
Overrides:
addContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(org.jdom.ProcessingInstruction pi)
Overrides:
addContent in class org.jdom.Element

addContent

public org.jdom.Element addContent(org.jdom.CDATA cdata)
Overrides:
addContent in class org.jdom.Element

fireInsertEvent

protected void fireInsertEvent(int offset,
                               String text,
                               Element elt)
Fires an insertion document event to the containing XMLDocument if it exists. This allows the XMLElement to notify the Swing document model of changes in the textual representation of the JDOM document.
Parameters:
offset - The offset at which the insertion occurs.
text - The actual text that will be inserted.
elt - The element concernced by the change.

getWrapper

public XMLElementWrapper getWrapper()
Returns the Wrapper attached to this XMLElement. This allow to make a bridge between the JDOM and the Swing Document Model.
Returns:
The associated Wrapper.

getDocument

public org.jdom.Document getDocument()
Returns the document attached to this XMLElement.
Overrides:
getDocument in class org.jdom.Element
Returns:
The belonging document.

setDocument

public void setDocument(XMLDocument doc)

Sets the parent document of this XMLElement. This does not automatically add the XMLElement to the document.

Parameters:
doc - The belonging document which whould be an XMLDocument instance.

This method has been redefined to make this method public rather than protected.