org.hibernate.ejb.packaging
Class XmlHelper

java.lang.Object
  extended by org.hibernate.ejb.packaging.XmlHelper

public final class XmlHelper
extends Object

A utility class to cover up the rough bits of xml parsing


Method Summary
static Iterator getChildrenByTagName(Element element, String tagName)
          Returns an iterator over the children of the given element with the given tag name.
static String getElementContent(Element element)
          Get the content of the given element.
static String getElementContent(Element element, String defaultStr)
          Get the content of the given element.
static Element getOptionalChild(Element element, String tagName)
          Gets the child of the specified element having the specified name.
static Element getOptionalChild(Element element, String tagName, Element defaultElement)
          Gets the child of the specified element having the specified name.
static boolean getOptionalChildBooleanContent(Element element, String name)
           
static String getOptionalChildContent(Element element, String tagName)
          Macro to get the content of an optional child element.
static Element getUniqueChild(Element element, String tagName)
          Gets the child of the specified element having the specified unique name.
static String getUniqueChildContent(Element element, String tagName)
          Macro to get the content of a unique child element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChildrenByTagName

public static Iterator getChildrenByTagName(Element element,
                                            String tagName)
Returns an iterator over the children of the given element with the given tag name.

Parameters:
element - The parent element
tagName - The name of the desired child
Returns:
An interator of children or null if element is null.

getUniqueChild

public static Element getUniqueChild(Element element,
                                     String tagName)
                              throws Exception
Gets the child of the specified element having the specified unique name. If there are more than one children elements with the same name and exception is thrown.

Parameters:
element - The parent element
tagName - The name of the desired child
Returns:
The named child.
Throws:
Exception - Child was not found or was not unique.

getOptionalChild

public static Element getOptionalChild(Element element,
                                       String tagName)
                                throws Exception
Gets the child of the specified element having the specified name. If the child with this name doesn't exist then null is returned instead.

Parameters:
element - the parent element
tagName - the name of the desired child
Returns:
either the named child or null
Throws:
Exception

getOptionalChild

public static Element getOptionalChild(Element element,
                                       String tagName,
                                       Element defaultElement)
                                throws Exception
Gets the child of the specified element having the specified name. If the child with this name doesn't exist then the supplied default element is returned instead.

Parameters:
element - the parent element
tagName - the name of the desired child
defaultElement - the element to return if the child doesn't exist
Returns:
either the named child or the supplied default
Throws:
Exception

getElementContent

public static String getElementContent(Element element)
                                throws Exception
Get the content of the given element.

Parameters:
element - The element to get the content for.
Returns:
The content of the element or null.
Throws:
Exception

getElementContent

public static String getElementContent(Element element,
                                       String defaultStr)
                                throws Exception
Get the content of the given element.

Parameters:
element - The element to get the content for.
defaultStr - The default to return when there is no content.
Returns:
The content of the element or the default.
Throws:
Exception

getUniqueChildContent

public static String getUniqueChildContent(Element element,
                                           String tagName)
                                    throws Exception
Macro to get the content of a unique child element.

Parameters:
element - The parent element.
tagName - The name of the desired child.
Returns:
The element content or null.
Throws:
Exception

getOptionalChildContent

public static String getOptionalChildContent(Element element,
                                             String tagName)
                                      throws Exception
Macro to get the content of an optional child element.

Parameters:
element - The parent element.
tagName - The name of the desired child.
Returns:
The element content or null.
Throws:
Exception

getOptionalChildBooleanContent

public static boolean getOptionalChildBooleanContent(Element element,
                                                     String name)
                                              throws Exception
Throws:
Exception


Copyright © 2001-2013 Red Hat, Inc. All Rights Reserved.