Package org.codehaus.cargo.module
Class AbstractDescriptor
- java.lang.Object
-
- org.jdom2.Document
-
- org.codehaus.cargo.module.AbstractDescriptor
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Descriptor
,org.jdom2.NamespaceAware
,org.jdom2.Parent
- Direct Known Subclasses:
ApplicationXml
,EjbJarXml
,IbmEjbJarBndXmi
,IbmWebBndXmi
,JBossWebXml
,JBossXml
,OrionEjbJarXml
,OrionWebXml
,ResinWebXml
,TomcatContextXml
,WeblogicEjbJarXml
,WeblogicXml
,WebXml
public abstract class AbstractDescriptor extends org.jdom2.Document implements Descriptor
Encapsulates the DOM representation of a deployment descriptor to provide convenience methods for easy access and manipulation.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractDescriptor(org.jdom2.Element rootElement, DescriptorType descriptorType)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jdom2.Element
addElement(DescriptorTag tag, org.jdom2.Element child, org.jdom2.Element parent)
Adds an element of the specified tag to the descriptor.protected void
checkElement(org.jdom2.Element element, DescriptorTag expectedTag)
Checks an element whether its name matches the specified name.protected boolean
containsElement(List<org.jdom2.Element> haystack, org.jdom2.Element needle)
Checks ifhaystack
containsneedle
.protected org.jdom2.Element
createNestedText(DescriptorTag tag, String text)
Creates an element that contains nested text.protected String
getChildText(org.jdom2.Element parent, String tagName)
Returns the text value from a child directly under the parent tag.protected String
getChildText(org.jdom2.Element parent, DescriptorTag tag)
Returns the text value from a child directly under the parent tag.protected List<org.jdom2.Content>
getContentExceptComments(org.jdom2.Element element)
Gets the content of an element (excluding comments).DescriptorType
getDescriptorType()
Get the descriptor type for this descriptor.org.jdom2.Document
getDocument()
Return the representation as a document.List<org.jdom2.Element>
getElements(String tagName)
Returns a list of the elements that match the specified tag.List<org.jdom2.Element>
getElements(DescriptorTag tag)
Returns a list of the elements that match the specified tag.protected org.jdom2.Element
getImmediateChild(org.jdom2.Element parent, DescriptorTag tag)
Gets a certain tag directly under the parent tag.protected org.jdom2.Element
getInsertionPointFor(DescriptorTag tag, String parent)
Returns the node before which the specified tag should be inserted, ornull
if the node should be inserted at the end of the descriptor.protected List<org.jdom2.Element>
getNestedElements(org.jdom2.Element parent, DescriptorTag tag)
Returns a list of the child elements of the specified element that match the specified tag.protected String
getNestedText(org.jdom2.Element parent, DescriptorTag tag)
Returns the text nested inside a child element of the specified element.org.jdom2.Element
getTagByIdentifier(String tagName, String value)
Get elements of a particular descriptor tag whose identifier matches the passed parameter.org.jdom2.Element
getTagByIdentifier(DescriptorTag tag, String value)
Get elements of a particular descriptor tag whose identifier matches the passed parameter.List<org.jdom2.Element>
getTags(String tagName)
Get tags of a particular type.List<org.jdom2.Element>
getTags(DescriptorTag tag)
Get tags of a particular type.protected String
getText(org.jdom2.Element element)
Returns the text value of an element.protected boolean
sameContent(org.jdom2.Element element1, org.jdom2.Element element2)
Checks if two elements have the same content (excluding comments).protected boolean
sameElement(org.jdom2.Element element1, org.jdom2.Element element2)
Checks if two elements are the same.-
Methods inherited from class org.jdom2.Document
addContent, addContent, addContent, addContent, canContainContent, clone, cloneContent, detachRootElement, equals, getBaseURI, getContent, getContent, getContent, getContentSize, getDescendants, getDescendants, getDocType, getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced, getParent, getProperty, getRootElement, hashCode, hasRootElement, indexOf, removeContent, removeContent, removeContent, removeContent, setBaseURI, setContent, setContent, setContent, setContent, setDocType, setProperty, setRootElement, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.codehaus.cargo.module.Descriptor
getFileName, getRootElement
-
Methods inherited from interface org.jdom2.NamespaceAware
getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced
-
Methods inherited from interface org.jdom2.Parent
addContent, addContent, addContent, addContent, canContainContent, clone, cloneContent, getContent, getContent, getContent, getContentSize, getDescendants, getDescendants, getParent, indexOf, removeContent, removeContent, removeContent, removeContent
-
-
-
-
Constructor Detail
-
AbstractDescriptor
public AbstractDescriptor(org.jdom2.Element rootElement, DescriptorType descriptorType)
Constructor.- Parameters:
rootElement
- The root element of the documentdescriptorType
- The type of the descriptor
-
-
Method Detail
-
getDocument
public org.jdom2.Document getDocument()
Return the representation as a document.- Specified by:
getDocument
in interfaceDescriptor
- Specified by:
getDocument
in interfaceorg.jdom2.Parent
- Overrides:
getDocument
in classorg.jdom2.Document
- Returns:
- JDOM Document
-
getTags
public List<org.jdom2.Element> getTags(DescriptorTag tag)
Get tags of a particular type.- Specified by:
getTags
in interfaceDescriptor
- Parameters:
tag
- type of elements to find- Returns:
- list of tags
-
getTags
public List<org.jdom2.Element> getTags(String tagName)
Get tags of a particular type.- Specified by:
getTags
in interfaceDescriptor
- Parameters:
tagName
- type of elements to find- Returns:
- list of tags
-
getElements
public List<org.jdom2.Element> getElements(DescriptorTag tag)
Returns a list of the elements that match the specified tag.- Parameters:
tag
- The descriptor tag of which the elements should be returned- Returns:
- A list of the elements matching the tag, in the order they occur in the descriptor
-
getElements
public List<org.jdom2.Element> getElements(String tagName)
Returns a list of the elements that match the specified tag.- Parameters:
tagName
- The name of a descriptor tag of which the elements should be returned- Returns:
- A list of the elements matching the tag, in the order they occur in the descriptor
-
checkElement
protected void checkElement(org.jdom2.Element element, DescriptorTag expectedTag) throws IllegalArgumentException
Checks an element whether its name matches the specified name.- Parameters:
element
- The element to checkexpectedTag
- The expected tag name- Throws:
IllegalArgumentException
- If the element name doesn't match
-
getNestedElements
protected List<org.jdom2.Element> getNestedElements(org.jdom2.Element parent, DescriptorTag tag)
Returns a list of the child elements of the specified element that match the specified tag.- Parameters:
parent
- The element of which the nested elements should be retrievedtag
- The descriptor tag of which the elements should be returned- Returns:
- A copy of the list of the elements matching the tag, in the order they occur in the descriptor
-
createNestedText
protected org.jdom2.Element createNestedText(DescriptorTag tag, String text)
Creates an element that contains nested text.- Parameters:
tag
- The tag to create an instance oftext
- The text that should be nested in the element- Returns:
- The created DOM element
-
getNestedText
protected String getNestedText(org.jdom2.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 returnedtag
- The descriptor tag in which the text is nested- Returns:
- The text nested in the element
-
getText
protected String getText(org.jdom2.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.jdom2.Element getImmediateChild(org.jdom2.Element parent, DescriptorTag tag)
Gets a certain tag directly under the parent tag.- Parameters:
parent
- the tag to get the cild fromtag
- name of the child tag- Returns:
- tag directly under the parent tag.
-
getChildText
protected String getChildText(org.jdom2.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 fromtag
- the name of the child tag- Returns:
- the text value of a child tag directly under the parent tag
-
getChildText
protected String getChildText(org.jdom2.Element parent, String tagName)
Returns the text value from a child directly under the parent tag.- Parameters:
parent
- the parent tag to get the child text fromtagName
- the name of the child tag- Returns:
- the text value of a child tag directly under the parent tag
-
addElement
public org.jdom2.Element addElement(DescriptorTag tag, org.jdom2.Element child, org.jdom2.Element parent)
Adds an element of the specified tag to the descriptor.- Specified by:
addElement
in interfaceDescriptor
- Parameters:
tag
- The descriptor tagchild
- The child element to addparent
- The parent element to add the child to- Returns:
- the inserted element
-
containsElement
protected boolean containsElement(List<org.jdom2.Element> haystack, org.jdom2.Element needle)
Checks ifhaystack
containsneedle
.- Parameters:
haystack
- List of element to look into.needle
- Element to look for.- Returns:
- Whether
haystack
containsneedle
.
-
sameElement
protected boolean sameElement(org.jdom2.Element element1, org.jdom2.Element element2)
Checks if two elements are the same.- Parameters:
element1
- First element.element2
- Second element.- Returns:
- Whether
element1
andelement2
are the same.
-
sameContent
protected boolean sameContent(org.jdom2.Element element1, org.jdom2.Element element2)
Checks if two elements have the same content (excluding comments).- Parameters:
element1
- First element.element2
- Second element.- Returns:
- Whether
element1
andelement2
have the same content (excluding comments).
-
getContentExceptComments
protected List<org.jdom2.Content> getContentExceptComments(org.jdom2.Element element)
Gets the content of an element (excluding comments).- Parameters:
element
- Element to get the contents for.- Returns:
- All content for
element
(excluding comments).
-
getInsertionPointFor
protected org.jdom2.Element getInsertionPointFor(DescriptorTag tag, String parent)
Returns the node before which the specified tag should be inserted, ornull
if the node should be inserted at the end of the descriptor.- Parameters:
tag
- The tag that should be insertedparent
- name of the parent tag- Returns:
- The node before which the tag can be inserted
-
getDescriptorType
public DescriptorType getDescriptorType()
Description copied from interface:Descriptor
Get the descriptor type for this descriptor.- Specified by:
getDescriptorType
in interfaceDescriptor
- Returns:
- the descriptorType
-
getTagByIdentifier
public org.jdom2.Element getTagByIdentifier(DescriptorTag tag, String value)
Get elements of a particular descriptor tag whose identifier matches the passed parameter.- Specified by:
getTagByIdentifier
in interfaceDescriptor
- Parameters:
tag
- tag to search forvalue
- value for the identifier to match- Returns:
- the element that matches
-
getTagByIdentifier
public org.jdom2.Element getTagByIdentifier(String tagName, String value)
Get elements of a particular descriptor tag whose identifier matches the passed parameter.- Specified by:
getTagByIdentifier
in interfaceDescriptor
- Parameters:
tagName
- Name of the tag to search forvalue
- value for the identifier to match- Returns:
- the element that matches
-
-