Open SiteSearch 4.1.1
Final

ORG.oclc.xml.om
Class ElementImpl

java.lang.Object
  |
  +--ORG.oclc.xml.om.ElementImpl
Direct Known Subclasses:
Document, ElementDecl, Entity, Notation

public class ElementImpl
extends Object
implements Element

This class represents the default implementation of the Element interface. These are created by the XML parser when using the default element factory.

See Also:
Element, Parser, ElementFactory, ElementFactoryImpl

Field Summary
protected  Attributes attrlist
          The attribute list.
 
Constructor Summary
ElementImpl()
           
ElementImpl(Name tag, int type)
           
 
Method Summary
 void addChild(Element elem, Element after)
          Adds a child to this element.
 void addChild(Element elem, int pos, int reserved)
          Adds a child to this element.
 Object getAttribute(Name attrName)
          Retrieves an attribute's value given its name.
 Object getAttribute(String name)
          Retrieves an attribute's value given its name.
 Enumeration getAttributes()
          Retrieves an enumeration for the element attributes.
 Element getChild(int index)
          Retrieves the child element by index.
 ElementCollection getChildren()
          Returns an element collection of the children of this element.
 Enumeration getElements()
          Returns an enumeration of the children of this element.
 Element getParent()
          Retrieves the parent of this element.
 Name getTagName()
          Retrieves the name of the tag as a string.
 String getText()
          Returns the non-marked-up text contained by this element.
 int getType()
          Retrieves the type of the element.
 boolean isAttributeQualified(Name attr, DTD dtd)
          Determines if the attribute is qualified.
 int numAttributes()
          Retrieves the number of attributes.
 int numElements()
          Retrieves the number of child elements.
 Name qualifyName(String string)
          This is a useful method for creating a qualified Name object from the given string.
 void removeAttribute(Name attrName)
          Deletes an attribute from an element.
 void removeAttribute(String name)
          Deletes an attribute from an element.
 void removeChild(Element elem)
          Removes a child element from the tree.
 void save(XMLOutputStream o)
          Saves the element in XML format.
 void saveAttributes(Atom ns, XMLOutputStream o)
          Save the element attributes in XML format
 void setAttribute(Name attrName, Object value)
          Sets the attribute of this element.
 void setAttribute(String name, Object value)
          Sets the attribute of this element.
 void setParent(Element parent)
          Sets the parent of this element.
 void setText(String text)
          Sets the text for this element.
 Element toSchema()
          Returns the XML-DATA specification for the DTD element.
 String toString()
          Retrieves the string representation of this element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

attrlist

protected Attributes attrlist
The attribute list.
Constructor Detail

ElementImpl

public ElementImpl()

ElementImpl

public ElementImpl(Name tag,
                   int type)
Method Detail

getTagName

public Name getTagName()
Retrieves the name of the tag as a string. The string will be in uppercase.
Specified by:
getTagName in interface Element
Returns:
the tag name or null for DATA and PCDATA elements.

getType

public int getType()
Retrieves the type of the element. This is always one of the following values: DOCUMENT, ELEMENT, PCDATA, PI, META, COMMENT, or CDATA.
Specified by:
getType in interface Element
Returns:
the element type.

getText

public String getText()
Returns the non-marked-up text contained by this element. For text elements, this is the raw data. For elements with child nodes, this method traverses the entire subtree and appends the text for each terminal text element, effectively stripping out the XML markup for the subtree. For example, if the XML document contains the following: <AUTHOR> <FIRST>William</FIRST> <LAST>Shakespeare</LAST> </AUTHOR>

Document.getText returns "William Shakespeare".

Specified by:
getText in interface Element

setText

public void setText(String text)
Sets the text for this element. This text is Only meaningful in CDATA, PCDATA, and COMMENT nodes.
Specified by:
setText in interface Element
Parameters:
The - text to set.

getParent

public Element getParent()
Retrieves the parent of this element. Every element in the tree except the Document object itself, has a parent.
Specified by:
getParent in interface Element
Returns:
the parent element or null if the element is at the root of the tree.

setParent

public void setParent(Element parent)
Sets the parent of this element.
Specified by:
setParent in interface Element
Parameters:
parent - The element to set as the parent.
Returns:
No return value.

getElements

public Enumeration getElements()
Returns an enumeration of the children of this element. Enumeration.nextElement returns Element objects.
Specified by:
getElements in interface Element
Returns:
an enumeration of child objects. It must not return null. See EnumWrapper for an easy way to return an empty enumeration.

getChildren

public ElementCollection getChildren()
Returns an element collection of the children of this element. This method must not return null. See EnumWrapper for an empty enumeration.
Specified by:
getChildren in interface Element
Returns:
element collection of child objects.

numAttributes

public int numAttributes()
Retrieves the number of attributes.
Specified by:
numAttributes in interface Element
Returns:
the number of attributes.

numElements

public int numElements()
Retrieves the number of child elements.
Specified by:
numElements in interface Element
Returns:
the number of child elements.

addChild

public void addChild(Element elem,
                     Element after)
Adds a child to this element. Any element can only have one parent element, and so the previous parent will lose this child from its subtree.
Specified by:
addChild in interface Element
Parameters:
elem - The element to add. The child element becomes the last element if after is null. The child is added to the beginning of the list if after is this object.
after - The element after which to add it.
Returns:
No return value.

addChild

public void addChild(Element elem,
                     int pos,
                     int reserved)
Adds a child to this element.
Specified by:
addChild in interface Element
Parameters:
elem - The element to add.
pos - The position to add this element (calling getChild(pos) will return this element). If pos is less than 0, elem becomes the new last element.
reserved - The reserved parameter.
Returns:
No return value.

getChild

public Element getChild(int index)
Retrieves the child element by index.
Specified by:
getChild in interface Element
Parameters:
index - The index of the child element.
Returns:
null if there is no child by that index.

removeChild

public void removeChild(Element elem)
Removes a child element from the tree.
Specified by:
removeChild in interface Element
Parameters:
elem - The element to remove.
Returns:
No return value.

getAttributes

public Enumeration getAttributes()
Retrieves an enumeration for the element attributes. The enumeration returns Attribute objects.
Specified by:
getAttributes in interface Element
Returns:
the enumeration. This method must not return null (see EnumWrapper for returning empty enumerations).
See Also:
Attribute

getAttribute

public Object getAttribute(String name)
Retrieves an attribute's value given its name.
Specified by:
getAttribute in interface Element
Parameters:
name - The name of the attribute.
Returns:
the value of the attribute; returns null if the attribute is not found.

getAttribute

public Object getAttribute(Name attrName)
Retrieves an attribute's value given its name.
Specified by:
getAttribute in interface Element
Parameters:
name - The name of the attribute.
Returns:
the value of the attribute; returns null if the attribute is not found.

setAttribute

public void setAttribute(String name,
                         Object value)
Sets the attribute of this element.
Specified by:
setAttribute in interface Element
Parameters:
name - The attribute name.
value - The attribute value.
Returns:
any previous value, if any.

removeAttribute

public void removeAttribute(String name)
Deletes an attribute from an element.
Specified by:
removeAttribute in interface Element
Parameters:
name - The attribute to delete.
Returns:
No return value.

removeAttribute

public void removeAttribute(Name attrName)
Deletes an attribute from an element.
Specified by:
removeAttribute in interface Element
Parameters:
attrName - The attribute name to delete.

toString

public String toString()
Retrieves the string representation of this element.
Returns:
a string representing the element.
Overrides:
toString in class Object

setAttribute

public void setAttribute(Name attrName,
                         Object value)
Sets the attribute of this element.
Specified by:
setAttribute in interface Element
Parameters:
attrName - The attribute name.
value - The attribute value.

saveAttributes

public void saveAttributes(Atom ns,
                           XMLOutputStream o)
                    throws IOException
Save the element attributes in XML format

isAttributeQualified

public boolean isAttributeQualified(Name attr,
                                    DTD dtd)
Determines if the attribute is qualified.
Parameters:
attr - The name of the attribute.
dtd - The Document Definition Type (DTD) in which the attribute is found.
Returns:
true if the attribute is qualified; otherwise, returns false.

toSchema

public Element toSchema()
Returns the XML-DATA specification for the DTD element. (Only applies to ElementDecl and Entity nodes). This is DTD information represented in an XML Object Model. See Specification for XML-Data for details.
Specified by:
toSchema in interface Element

save

public void save(XMLOutputStream o)
          throws IOException
Saves the element in XML format.
Specified by:
save in interface Element
Parameters:
o - The output stream to save to.
Returns:
No return value.
Throws:
IOException - if an error occurs when writing to the output stream.

qualifyName

public Name qualifyName(String string)
This is a useful method for creating a qualified Name object from the given string. This will parse the string and lookup the namespace, if specified, and create the fully qualified name. If no namespace is given, it will inherit the namespace from this element.

Open SiteSearch 4.1.1
Final