org.codehaus.cargo.module
Class AbstractDescriptor

java.lang.Object
  extended byorg.codehaus.cargo.module.AbstractDescriptor
All Implemented Interfaces:
Descriptor
Direct Known Subclasses:
ApplicationXml, EjbJarXml, IbmEjbJarBndXmi, IbmWebBndXmi, JBossWebXml, OrionEjbJarXml, OrionWebXml, ResinWebXml, TomcatContextXml, WeblogicEjbJarXml, WeblogicXml, WebXml

public abstract class AbstractDescriptor
extends java.lang.Object
implements Descriptor

Encapsulates the DOM representation of a deployment descriptor to provide convenience methods for easy access and manipulation.

Version:
$Id: AbstractDescriptor.java 1122 2006-07-22 15:15:43Z vmassol $

Constructor Summary
AbstractDescriptor(org.w3c.dom.Document document, Grammar grammar)
          Constructor.
 
Method Summary
protected  org.w3c.dom.Element addElement(DescriptorTag tag, org.w3c.dom.Element child, org.w3c.dom.Element parent)
          Adds an element of the specified tag to the descriptor.
protected  void checkElement(org.w3c.dom.Element element, DescriptorTag expectedTag)
          Checks an element whether its name matches the specified name.
protected  org.w3c.dom.Element createNestedText(DescriptorTag tag, java.lang.String text)
          Creates an element that contains nested text.
protected  java.lang.String getChildText(org.w3c.dom.Element parent, DescriptorTag tag)
          Returns the text value from a child directly under the parent tag.
 org.w3c.dom.Document getDocument()
          Returns the DOM document representing the deployment descriptor.
 java.util.Iterator getElements(DescriptorTag tag)
          Returns an iterator over the elements that match the specified tag.
protected  org.w3c.dom.Element getImmediateChild(org.w3c.dom.Element parent, DescriptorTag tag)
          Gets a certain tag directly under the parent tag.
protected  org.w3c.dom.Node getInsertionPointFor(DescriptorTag tag, java.lang.String parent)
          Returns the node before which the specified tag should be inserted, or null if the node should be inserted at the end of the descriptor.
protected  java.util.Iterator getNestedElements(org.w3c.dom.Element parent, DescriptorTag tag)
          Returns an iterator over the child elements of the specified element that match the specified tag.
protected  java.lang.String getNestedText(org.w3c.dom.Element parent, DescriptorTag tag)
          Returns the text nested inside a child element of the specified element.
 org.w3c.dom.Element getRootElement()
           
protected  java.lang.String getText(org.w3c.dom.Element element)
          Returns the text value of an element.
 org.w3c.dom.Element replaceElement(DescriptorTag tag, org.w3c.dom.Element child, org.w3c.dom.Element parent)
          Replaces all elements of the specified tag with the provided element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.cargo.module.Descriptor
getFileName
 

Constructor Detail

AbstractDescriptor

public AbstractDescriptor(org.w3c.dom.Document document,
                          Grammar grammar)
Constructor.

Parameters:
document - The DOM document representing the parsed deployment descriptor
grammar - The DTD of the descriptor
Method Detail

getDocument

public org.w3c.dom.Document getDocument()
Returns the DOM document representing the deployment descriptor. The document will contain any modifications made through this instance.

Specified by:
getDocument in interface Descriptor
Returns:
The document representing the deploy descriptor

getRootElement

public org.w3c.dom.Element getRootElement()
Returns:
the DOM root element

getElements

public java.util.Iterator getElements(DescriptorTag tag)
Returns an iterator over the elements that match the specified tag.

Parameters:
tag - The descriptor tag of which the elements should be returned
Returns:
An iterator over the elements matching the tag, in the order they occur in the descriptor

checkElement

protected void checkElement(org.w3c.dom.Element element,
                            DescriptorTag expectedTag)
                     throws java.lang.IllegalArgumentException
Checks an element whether its name matches the specified name.

Parameters:
element - The element to check
expectedTag - The expected tag name
Throws:
java.lang.IllegalArgumentException - If the element name doesn't match

getNestedElements

protected java.util.Iterator getNestedElements(org.w3c.dom.Element parent,
                                               DescriptorTag tag)
Returns an iterator over the child elements of the specified element that match the specified tag.

Parameters:
parent - The element of which the nested elements should be retrieved
tag - The descriptor tag of which the elements should be returned
Returns:
An iterator over the elements matching the tag, in the order they occur in the descriptor

createNestedText

protected org.w3c.dom.Element createNestedText(DescriptorTag tag,
                                               java.lang.String text)
Creates an element that contains nested text.

Parameters:
tag - The tag to create an instance of
text - The text that should be nested in the element
Returns:
The created DOM element

getNestedText

protected java.lang.String getNestedText(org.w3c.dom.Element parent,
                                         DescriptorTag tag)
Returns the text nested inside a child element of the specified element.

Parameters:
parent - The element of which the nested text should be returned
tag - The descriptor tag in which the text is nested
Returns:
The text nested in the element

getText

protected java.lang.String getText(org.w3c.dom.Element element)
Returns the text value of an element.

Parameters:
element - the element of wich the text value should be returned
Returns:
the text value of an element

getImmediateChild

protected org.w3c.dom.Element getImmediateChild(org.w3c.dom.Element parent,
                                                DescriptorTag tag)
Gets a certain tag directly under the parent tag.

Parameters:
parent - the tag to get the cild from
tag - name of the child tag
Returns:
tag directly under the parent tag.

getChildText

protected java.lang.String getChildText(org.w3c.dom.Element parent,
                                        DescriptorTag tag)
Returns the text value from a child directly under the parent tag.

Parameters:
parent - the parent tag to get the child text from
tag - the name of the child tag
Returns:
the text value of a child tag directly under the parent tag

addElement

protected org.w3c.dom.Element addElement(DescriptorTag tag,
                                         org.w3c.dom.Element child,
                                         org.w3c.dom.Element parent)
Adds an element of the specified tag to the descriptor.

Parameters:
tag - The descriptor tag
child - The child element to add
parent - The parent element to add the child to
Returns:
the inserted element

replaceElement

public org.w3c.dom.Element replaceElement(DescriptorTag tag,
                                          org.w3c.dom.Element child,
                                          org.w3c.dom.Element parent)
Replaces all elements of the specified tag with the provided element.

Parameters:
tag - The descriptor tag
child - The element to replace the current elements with
parent - The parent element to add the child to
Returns:
the replaced element

getInsertionPointFor

protected org.w3c.dom.Node getInsertionPointFor(DescriptorTag tag,
                                                java.lang.String parent)
Returns the node before which the specified tag should be inserted, or null if the node should be inserted at the end of the descriptor.

Parameters:
tag - The tag that should be inserted
parent - name of the parent tag
Returns:
The node before which the tag can be inserted


Copyright © 2004-2007 Codehaus. All Rights Reserved.