org.jtool.jxplatform.wrapper
Class JxElement

java.lang.Object
  extended byorg.jtool.jxplatform.wrapper.JxElement
Direct Known Subclasses:
JxClass, JxDefUseExpression, JxFile, JxImport, JxMethod, JxPackage, JxStaticInit, JxType

public class JxElement
extends java.lang.Object

The root element of all Java-XML wrappers.

Author:
Katsuhisa Maruyama

Field Summary
protected  org.w3c.dom.Element element
          A wrapped DOM element correspoinding to the source code element.
 
Constructor Summary
protected JxElement()
          Creates a new, empty object.
protected JxElement(org.w3c.dom.Element elem)
          Creates a new object wrapping an XML element.
 
Method Summary
 boolean equals(JxElement jelem)
          Indicates whether a given wrapper is equal to this one.
protected  boolean existInTheSameClass(org.w3c.dom.Element elem1, org.w3c.dom.Element elem2)
          Tests if both elements exist in the same class.
protected  boolean existInTheSameField(org.w3c.dom.Element elem1, org.w3c.dom.Element elem2)
          Tests if the elements of a given and this wrappers exist in the same field.
protected  boolean existInTheSameFile(org.w3c.dom.Element elem1, org.w3c.dom.Element elem2)
          Tests if both elements exist in the same file.
protected  boolean existInTheSameMethod(org.w3c.dom.Element elem1, org.w3c.dom.Element elem2)
          Tests if both elements exist in the same method.
 boolean existsInTheSameClass(JxElement jelem)
          Tests if both elements of a given and this wrappers exist in the same class.
 boolean existsInTheSameFile(JxElement jelem)
          Tests if both elements of a given and this wrappers exist in the same file.
 boolean existsInTheSameMethod(JxElement jelem)
          Tests if both elements of a given and this wrappers exist in the same method.
 boolean existsInTheSamePackage(JxElement jelem)
          Tests if both elements of a given and this wrappers exist in the same package.
protected  org.w3c.dom.Element[] getArrayOfElements(java.util.ArrayList nodes)
          Converts ArrayList into the array of its elements.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element elem, java.lang.String elemName, int n)
          Returns the nth element of a specified kind of children of a given element.
 org.w3c.dom.Element getChildElement(java.lang.String elemName, int n)
          Returns the nth element of a specified kind of children of this element.
static org.w3c.dom.Element[] getChildElements(org.w3c.dom.Element elem, java.lang.String elemName)
          Returns an array contains a specified kind of children of a given element.
 org.w3c.dom.Element[] getChildElements(java.lang.String elemName)
          Returns an array contains a specified kind of children of this element.
 org.w3c.dom.Node[] getChildNodes()
          Returns an array contains all children of this element.
static org.w3c.dom.Node[] getChildNodes(org.w3c.dom.Element elem)
          Returns an array contains all children of a given element.
 org.w3c.dom.Element getClassElement()
          Returns the Class or Intf element containing this element.
static org.w3c.dom.Element[] getDescendantElements(org.w3c.dom.Element elem, java.lang.String elemName)
          Returns an array contains a specified kind of descendants of a given element.
static org.w3c.dom.Element[] getDescendantElements(org.w3c.dom.Element elem, java.lang.String elemName, java.lang.String sort)
          Returns an array contains a specified kind of descendants of a given element.
 org.w3c.dom.Element[] getDescendantElements(java.lang.String elemName)
          Returns an array contains a specified kind of descendants of this element.
 org.w3c.dom.Element[] getDescendantElements(java.lang.String elemName, java.lang.String sort)
          Returns an array contains a specified kind of descendants of this element.
 org.w3c.dom.Element getElement()
          Returns the DOM element wrapped in this wrapper.
protected static org.w3c.dom.Element getElementById(org.w3c.dom.NodeList nl, java.lang.String defid)
          Retrieves the element with the specified identifier among a given node list of DOM elements.
 org.w3c.dom.Element[] getExpressionElements()
          Returns all Expression elements appendant to this element.
 org.w3c.dom.Element getFieldElement()
          Returns the Field element containing this element.
 org.w3c.dom.Element getFileElement()
          Returns the File element containing this element.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element elem, java.lang.String elemName)
          Returns the first element of a specified kind of children of a given element.
 org.w3c.dom.Element getFirstChildElement(java.lang.String elemName)
          Returns the first element of a specified kind of children of this element.
 java.lang.String getId()
          Returns the identifier indicating the wrapped element.
static java.lang.String getId(org.w3c.dom.Element elem)
          Returns the identifier indicating a given element.
 java.lang.String getIdentName()
          Returns the name appendant to a given element.
static java.lang.String getIdentName(org.w3c.dom.Element elem)
          Returns the name appendant to a given element.
 JxClass getJxClass()
          Obtains a class wrapper defining this element.
 JxField getJxField()
          Obtains a field wrapper defining this element.
 JxFile getJxFile()
          Obtains a file wrapper defining this element.
 JxMethod getJxMethod()
          Obtains a method wrapper defining this element.
 JxStaticInit getJxStaticInit()
          Obtains a static initializer wrapper defining this element.
static java.lang.String getKeyword(org.w3c.dom.Element elem)
          Returns the keyword appendant to a given element.
 int getLine()
          Returns the line number where this element exists in the source code.
 org.w3c.dom.Element getMethodElement()
          Returns the Method or Ctor element containing this element.
 org.w3c.dom.Element getStatementElement()
          Returns the Stmt element containing this element.
 org.w3c.dom.Element getStaticInitElement()
          Returns the SInit element containing this element.
static org.w3c.dom.Element getTypeElement(org.w3c.dom.Element elem)
          Returns the type element appendant to a given element.
 org.w3c.dom.Element[] getTypeElements()
          Returns all Type elements appendant to this element.
 java.lang.String getTypeName()
          Returns the type name appendant to a given element.
static int indexOf(org.w3c.dom.Element elem, java.lang.String elemName)
          Returns the index of the first occurrence of the specified element within the element's children.
 int indexOf(java.lang.String elemName)
          Returns the index of the first occurrence of the specified element within the element's children.
static boolean isBinary(org.w3c.dom.Element elem)
          Tests if a DOM element is contained in a binary class file.
 boolean isClass()
          Tests if this element equals to Class.
 boolean isClassOrInterface()
          Tests if this element equals to either Class or Intf.
 boolean isConstructor()
          Tests if this element equals to Ctor.
 boolean isExpression()
          Tests if this given element equals to Expr.
 boolean isField()
          Tests if this element equals to Field.
 boolean isFile()
          Tests if this element equals to File.
 boolean isImport()
          Tests if this element equals to Import.
 boolean isInterface()
          Tests if this element equals to Intf.
 boolean isInTheSameField(JxElement jelem)
          Tests if the elements of a given and this wrappers exist in the same field.
 boolean isLocal()
          Tests if this element equals to Local.
 boolean isMethod()
          Tests if this element equals to Method.
 boolean isMethodOrConstructor()
          Tests if this element equals to either Method or Ctor.
 boolean isPackage()
          Tests if this element equals to Package.
 boolean isParameter()
          Tests if this element equals to Param.
 boolean isStatement()
          Tests if this element equals to Stmt.
 boolean isStaticInit()
          Tests if this element equals to SInit.
 boolean isTerminalElement(org.w3c.dom.Element elem)
          Tests if a given element is terminal one.
 boolean isType()
          Tests if this element equals to Type.
 java.lang.String toString()
          Obtains the XML text of element indicated by this wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

element

protected org.w3c.dom.Element element
A wrapped DOM element correspoinding to the source code element.

Constructor Detail

JxElement

protected JxElement()
Creates a new, empty object.


JxElement

protected JxElement(org.w3c.dom.Element elem)
Creates a new object wrapping an XML element.

Parameters:
elem - A DOM element to be wrapped.
Method Detail

getElement

public org.w3c.dom.Element getElement()
Returns the DOM element wrapped in this wrapper.

Returns:
The wrapped element.

equals

public boolean equals(JxElement jelem)
Indicates whether a given wrapper is equal to this one.

Parameters:
jelem - A wrapper object.
Returns:
true if the wrapper is equals to this, otherwise false.

getId

public java.lang.String getId()
Returns the identifier indicating the wrapped element.

Returns:
The identifier string of the element. This string is unique within an XML document.

getId

public static java.lang.String getId(org.w3c.dom.Element elem)
Returns the identifier indicating a given element.

Parameters:
elem - A DOM element.
Returns:
The identifier string of the element.

getIdentName

public java.lang.String getIdentName()
Returns the name appendant to a given element.

Returns:
The name string, or the empty string if the element has no ident element.

getIdentName

public static java.lang.String getIdentName(org.w3c.dom.Element elem)
Returns the name appendant to a given element.

Parameters:
elem - A DOM element.
Returns:
The name string, or the empty string if the element has no ident element.

getKeyword

public static java.lang.String getKeyword(org.w3c.dom.Element elem)
Returns the keyword appendant to a given element.

Parameters:
elem - A DOM element.
Returns:
The keyword string, or the empty string if the element has no kw element.

getTypeName

public java.lang.String getTypeName()
Returns the type name appendant to a given element.

Returns:
The type string, or the empty string if the element has no Type element.

getTypeElement

public static org.w3c.dom.Element getTypeElement(org.w3c.dom.Element elem)
Returns the type element appendant to a given element.

Parameters:
elem - A DOM element.
Returns:
The element expressing the type of the given element, or null if there is no such element.

getLine

public int getLine()
Returns the line number where this element exists in the source code.

Returns:
The line number, or -1 if no line attribute exists.

getJxFile

public JxFile getJxFile()
Obtains a file wrapper defining this element.

Returns:
The JxFile wrapper defining this element.

getJxClass

public JxClass getJxClass()
Obtains a class wrapper defining this element.

Returns:
The JxClass wrapper defining this element.

getJxMethod

public JxMethod getJxMethod()
Obtains a method wrapper defining this element.

Returns:
The JxMethod wrapper defining this element.

getJxField

public JxField getJxField()
Obtains a field wrapper defining this element.

Returns:
The JxField wrapper defining this element.

getJxStaticInit

public JxStaticInit getJxStaticInit()
Obtains a static initializer wrapper defining this element.

Returns:
The JxStaticInit wrapper defining this element.

getFirstChildElement

public org.w3c.dom.Element getFirstChildElement(java.lang.String elemName)
Returns the first element of a specified kind of children of this element.

Parameters:
elemName - The kind of an element to be returned.
Returns:
The first child element, or null if there is no such element.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element elem,
                                                       java.lang.String elemName)
Returns the first element of a specified kind of children of a given element.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be returned.
Returns:
The first child element, or null if there is no such element.

getChildElement

public org.w3c.dom.Element getChildElement(java.lang.String elemName,
                                           int n)
Returns the nth element of a specified kind of children of this element.

Parameters:
elemName - The kind of an element to be returned.
n - The position number of an element to be returned.
Returns:
The nth child element, or null if there is no such element.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element elem,
                                                  java.lang.String elemName,
                                                  int n)
Returns the nth element of a specified kind of children of a given element.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be returned.
n - The position number of an element to be returned. The origin is 0.
Returns:
The nth child element, or null if there is no such element.

getChildNodes

public org.w3c.dom.Node[] getChildNodes()
Returns an array contains all children of this element.

Returns:
The array of the element's children.

getChildNodes

public static org.w3c.dom.Node[] getChildNodes(org.w3c.dom.Element elem)
Returns an array contains all children of a given element.

Parameters:
elem - An element of the DOM.
Returns:
The array of the element's children.

getChildElements

public org.w3c.dom.Element[] getChildElements(java.lang.String elemName)
Returns an array contains a specified kind of children of this element.

Parameters:
elemName - The kind of an element to be returned.
Returns:
The array of the element's children.

getChildElements

public static org.w3c.dom.Element[] getChildElements(org.w3c.dom.Element elem,
                                                     java.lang.String elemName)
Returns an array contains a specified kind of children of a given element.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be returned.
Returns:
The array of the element's children.

getDescendantElements

public org.w3c.dom.Element[] getDescendantElements(java.lang.String elemName)
Returns an array contains a specified kind of descendants of this element.

Parameters:
elemName - The kind of an element to be returned.
Returns:
The array of element's descendants.

getDescendantElements

public static org.w3c.dom.Element[] getDescendantElements(org.w3c.dom.Element elem,
                                                          java.lang.String elemName)
Returns an array contains a specified kind of descendants of a given element.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be returned.
Returns:
The array of element's descendants.

getDescendantElements

public org.w3c.dom.Element[] getDescendantElements(java.lang.String elemName,
                                                   java.lang.String sort)
Returns an array contains a specified kind of descendants of this element.

Parameters:
elemName - The kind of an element to be returned.
sort - The sort of a source code element corresponding to the element.
Returns:
The array of element's descendants.

getDescendantElements

public static org.w3c.dom.Element[] getDescendantElements(org.w3c.dom.Element elem,
                                                          java.lang.String elemName,
                                                          java.lang.String sort)
Returns an array contains a specified kind of descendants of a given element.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be returned.
sort - The sort of a source code element corresponding to the element.
Returns:
The array of element's descendants.

getTypeElements

public org.w3c.dom.Element[] getTypeElements()
Returns all Type elements appendant to this element.

Returns:
The array of appendant Type elements.

getExpressionElements

public org.w3c.dom.Element[] getExpressionElements()
Returns all Expression elements appendant to this element.

Returns:
The array of appendant Expression elements.

indexOf

public int indexOf(java.lang.String elemName)
Returns the index of the first occurrence of the specified element within the element's children.

Parameters:
elemName - The kind of an element to be checked.
Returns:
The index of the first occurrence, or -1 if the specified element does not occur.

indexOf

public static int indexOf(org.w3c.dom.Element elem,
                          java.lang.String elemName)
Returns the index of the first occurrence of the specified element within the element's children.

Parameters:
elem - An element of the DOM.
elemName - The kind of an element to be checked.
Returns:
The index of the first occurrence, or -1 if the specified element does not occur.

isFile

public boolean isFile()
Tests if this element equals to File.

Returns:
true if this element equals to File.

isPackage

public boolean isPackage()
Tests if this element equals to Package.

Returns:
true if this element equals to Package, otherwise false.

isImport

public boolean isImport()
Tests if this element equals to Import.

Returns:
true if this element equals to Import, otherwise false.

isClassOrInterface

public boolean isClassOrInterface()
Tests if this element equals to either Class or Intf.

Returns:
if this element equals to Class or Intf, otherwise false.

isClass

public boolean isClass()
Tests if this element equals to Class.

Returns:
true if this element equals to Class, otherwise false.

isInterface

public boolean isInterface()
Tests if this element equals to Intf.

Returns:
true if this element equals to Intf, otherwise false.

isStaticInit

public boolean isStaticInit()
Tests if this element equals to SInit.

Returns:
true if this element equals to SInit, otherwise false.

isMethodOrConstructor

public boolean isMethodOrConstructor()
Tests if this element equals to either Method or Ctor.

Returns:
true if this element equals to Method or Ctor, otherwise false.

isMethod

public boolean isMethod()
Tests if this element equals to Method.

Returns:
true if this element equals to Method, otherwise false.

isConstructor

public boolean isConstructor()
Tests if this element equals to Ctor.

Returns:
true if this element equals to Ctor, otherwise false.

isField

public boolean isField()
Tests if this element equals to Field.

Returns:
true if this element equals to Field, otherwise false.

isParameter

public boolean isParameter()
Tests if this element equals to Param.

Returns:
true if this element equals to Param, otherwise false.

isLocal

public boolean isLocal()
Tests if this element equals to Local.

Returns:
true if this element equals to Local, otherwise false.

isType

public boolean isType()
Tests if this element equals to Type.

Returns:
true if this element equals to Type, otherwise false.

isStatement

public boolean isStatement()
Tests if this element equals to Stmt.

Returns:
true if this element equals to Stmt, otherwise false.

isExpression

public boolean isExpression()
Tests if this given element equals to Expr.

Returns:
true if this element equals to Expr, otherwise false.

getFileElement

public org.w3c.dom.Element getFileElement()
Returns the File element containing this element.

Returns:
The File element, or null if there is no element found.

getClassElement

public org.w3c.dom.Element getClassElement()
Returns the Class or Intf element containing this element.

Returns:
The Class or Intf element, or null if there is no element found.

getMethodElement

public org.w3c.dom.Element getMethodElement()
Returns the Method or Ctor element containing this element.

Returns:
The Method or Ctor element, or null if there is no element found.

getFieldElement

public org.w3c.dom.Element getFieldElement()
Returns the Field element containing this element.

Returns:
The Field element, or null if there is no element found.

getStaticInitElement

public org.w3c.dom.Element getStaticInitElement()
Returns the SInit element containing this element.

Returns:
The SInit element, or null if there is no element found.

getStatementElement

public org.w3c.dom.Element getStatementElement()
Returns the Stmt element containing this element.

Returns:
The Stmt element, or null if there is no element found.

existsInTheSamePackage

public boolean existsInTheSamePackage(JxElement jelem)
Tests if both elements of a given and this wrappers exist in the same package.

Parameters:
jelem - A wrapper.
Returns:
true if the elements exist in the same package.

existsInTheSameFile

public boolean existsInTheSameFile(JxElement jelem)
Tests if both elements of a given and this wrappers exist in the same file.

Parameters:
jelem - A wrapper.
Returns:
true if the elements exist in the same file.

existInTheSameFile

protected boolean existInTheSameFile(org.w3c.dom.Element elem1,
                                     org.w3c.dom.Element elem2)
Tests if both elements exist in the same file.

Parameters:
elem1 - An element.
elem2 - An element.
Returns:
true if the elements exist in the same file.

existsInTheSameClass

public boolean existsInTheSameClass(JxElement jelem)
Tests if both elements of a given and this wrappers exist in the same class.

Parameters:
jelem - A wrapper.
Returns:
true if the elements exist in the same class.

existInTheSameClass

protected boolean existInTheSameClass(org.w3c.dom.Element elem1,
                                      org.w3c.dom.Element elem2)
Tests if both elements exist in the same class.

Parameters:
elem1 - An element.
elem2 - An element.
Returns:
true if the elements exist in the same class.

existsInTheSameMethod

public boolean existsInTheSameMethod(JxElement jelem)
Tests if both elements of a given and this wrappers exist in the same method.

Parameters:
jelem - A wrapper.
Returns:
true if the elements exist in the same method.

existInTheSameMethod

protected boolean existInTheSameMethod(org.w3c.dom.Element elem1,
                                       org.w3c.dom.Element elem2)
Tests if both elements exist in the same method.

Parameters:
elem1 - An element.
elem2 - An element.
Returns:
true if the elements exist in the same method.

isInTheSameField

public boolean isInTheSameField(JxElement jelem)
Tests if the elements of a given and this wrappers exist in the same field.

Parameters:
jelem - A wrapper.
Returns:
true if the elements exist in the same field.

existInTheSameField

protected boolean existInTheSameField(org.w3c.dom.Element elem1,
                                      org.w3c.dom.Element elem2)
Tests if the elements of a given and this wrappers exist in the same field.

Parameters:
elem1 - A wrapper.
elem2 - A wrapper.
Returns:
true if the elements exist in the same field.

isTerminalElement

public boolean isTerminalElement(org.w3c.dom.Element elem)
Tests if a given element is terminal one.

Parameters:
elem - An element.
Returns:
true if the element is terminal.

getArrayOfElements

protected org.w3c.dom.Element[] getArrayOfElements(java.util.ArrayList nodes)
Converts ArrayList into the array of its elements.

Parameters:
nodes - An object of ArrayList
Returns:
The array of elements contained in the given list.

getElementById

protected static org.w3c.dom.Element getElementById(org.w3c.dom.NodeList nl,
                                                    java.lang.String defid)
Retrieves the element with the specified identifier among a given node list of DOM elements.

Parameters:
nl - The node list of DOM elements.
defid - An identifier.
Returns:
The matched element, or null if there is no element found.

isBinary

public static boolean isBinary(org.w3c.dom.Element elem)
Tests if a DOM element is contained in a binary class file.

Parameters:
elem - A DOM node to be wrapped.
Throws:
if - the element is contained in a binary class file.

toString

public java.lang.String toString()
Obtains the XML text of element indicated by this wrapper.

Returns:
The XML text of the wrapped element.