com.googlecode.jinahya.xml
Class ElementLocator

java.lang.Object
  extended by com.googlecode.jinahya.xml.ElementLocator
Direct Known Subclasses:
DOM4JElementLocator, DOMElementLocator, JDOMElementLocator, KDOMElementLocator, StAXElementLocator, XOMElementLocator

public abstract class ElementLocator
extends Object

Abstract element locator.

Author:
Jin Kwon

Constructor Summary
ElementLocator(ELElement root)
          Creates a new instance.
 
Method Summary
 ElementLocator addChild(String localName)
          Adds a child element and locate it.
 ElementLocator addChild(String namespaceURI, String localName)
          Adds a child element and locate it.
 String getAttribute(String localName)
           
 String getAttribute(String namespaceURI, String localName)
          Finds an attribute and returns its value.
 int getChildCount(String localName)
          Returns the number of child elements which each has given localName in no namespace.
 int getChildCount(String namespaceURI, String localName)
          Returns the number of child elements which each has given localName in specified namespaceURI.
 String getLocalName()
           
 String getNamespaceURI()
           
 String getText()
          Returns text value of currently located element.
 ElementLocator locateChild(String localName, int index)
          Locates child element which has given localName in no namespace at index.
 ElementLocator locateChild(String namespaceURI, String localName, int index)
          Locate a child element which has given localName in given namespaceURI at index.
 ElementLocator locateParent()
          Locates to the parent element.
 ElementLocator locateRoot()
          Locate to the root element.
 ElementLocator removeCurrent()
          Removes currently located element and locate parent.
 ElementLocator setAttribute(String localName, String value)
           
 ElementLocator setAttribute(String namespaceURI, String localName, String value)
          Sets or removes attribute's value.
 ElementLocator setText(String text)
          Sets the text value of currently located element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementLocator

public ElementLocator(ELElement root)
Creates a new instance.

Parameters:
root - root element
Method Detail

getNamespaceURI

public final String getNamespaceURI()
Returns:

getLocalName

public final String getLocalName()
Returns:

getChildCount

public final int getChildCount(String localName)
Returns the number of child elements which each has given localName in no namespace.

Parameters:
localName - local name
Returns:
number of children

getChildCount

public final int getChildCount(String namespaceURI,
                               String localName)
Returns the number of child elements which each has given localName in specified namespaceURI. En empty string("") must be used for no(null) namespace.

Parameters:
namespaceURI - The namespace URI.
localName - The local name.
Returns:
child count
See Also:
#getCount(String)

locateRoot

public final ElementLocator locateRoot()
Locate to the root element. Nothing happens if this locator is already locating the root element.

Returns:
self

locateParent

public final ElementLocator locateParent()
Locates to the parent element.

Returns:
self

locateChild

public final ElementLocator locateChild(String localName,
                                        int index)
Locates child element which has given localName in no namespace at index. An IndexOutOfBoundsException will be thrown if there is no child at specified index.

Parameters:
localName - element's local name
index - child element index
Returns:
self
See Also:
#child(java.lang.String, java.lang.String, int)

locateChild

public final ElementLocator locateChild(String namespaceURI,
                                        String localName,
                                        int index)
Locate a child element which has given localName in given namespaceURI at index. An IndexOutOfBoundsException will be thrown if there is no child at specified index.

Parameters:
namespaceURI - element's namespace URI
localName - element's local name
index - target index to locate
Returns:
self
See Also:
#child(String, int)

addChild

public final ElementLocator addChild(String localName)
Adds a child element and locate it. The new child element will be named as localName in no namespace.

Parameters:
localName - new child element's local name.
Returns:
self

addChild

public final ElementLocator addChild(String namespaceURI,
                                     String localName)
Adds a child element and locate it. The new child element will be named as localName in given namespaceURI.

Parameters:
namespaceURI - child element's namespace URI
localName - child element's local name
Returns:
self

getText

public final String getText()
Returns text value of currently located element.

Returns:
text value; may be null

setText

public final ElementLocator setText(String text)
Sets the text value of currently located element.

Parameters:
text - new text value
Returns:
self

getAttribute

public final String getAttribute(String localName)

getAttribute

public final String getAttribute(String namespaceURI,
                                 String localName)
Finds an attribute and returns its value.

Parameters:
namespaceURI - attribute's namespace URI
localName - attribute's local name
Returns:
attribute's value or null if not found

setAttribute

public final ElementLocator setAttribute(String localName,
                                         String value)

setAttribute

public final ElementLocator setAttribute(String namespaceURI,
                                         String localName,
                                         String value)
Sets or removes attribute's value. If value is null mapped attribute will be removed.

Parameters:
namespaceURI - attribute's namespace URI
localName - attribute's local name
value - attribute's value; null for removing attribute
Returns:
self

removeCurrent

public final ElementLocator removeCurrent()
Removes currently located element and locate parent. An IllegalStateException will be thrown if this locate is currently locating the root element.

Returns:
self


Copyright © 2010-2011. All Rights Reserved.