uk.ac.soton.itinnovation.grid.utils
Class AxisUtils

java.lang.Object
  extended by uk.ac.soton.itinnovation.grid.utils.AxisUtils

public class AxisUtils
extends Object

Utility methods for axis.


Constructor Summary
AxisUtils()
           
 
Method Summary
static SOAPHeaderElement[] createFederationHeaders(org.apache.axis.message.addressing.EndpointReferenceType[] eprs)
          Create the SOAP headers to hold the federation information, if any.
static
<T> T
elementToObject(Element element, Class<T> cls)
          Convert an Element to a Java object, using the client type mappings.
static Element getChildElement(Element parent, QName qname)
          Return the single direct child element with the given name.
static Element getChildElement(Element parent, QName qname, boolean required)
          Return the single direct child element with the given name.
static Element getChildElement(Element parent, String namespace, String localName)
          Return the single direct child element with the given name.
static Element getChildElement(Element parent, String namespace, String localName, boolean required)
          Return the single direct child element with the given name.
static Element[] getChildElements(Element parent, String namespace, String localName)
          Return all direct children with the given name.
static String getExceptionName(RemoteException ex)
          Get the name of the exception given by a remote service.
static String getHostName(RemoteException ex)
          Get the name of the host that threw an exception.
static Element getOptionalChildElement(Element parent, QName qname)
          Return the single direct child element with the given name, if present
static Element getOptionalChildElement(Element parent, String namespace, String localName)
          Return the single direct child element with the given name, if present
static String getSingletonElementText(Element parent, QName qname)
          Return the contents of the named child element.
static String getSingletonElementText(Element parent, String namespace, String localName)
          Return the contents of the named child element.
static String getTextContent(Element parent)
          Deprecated. 
static String objectToString(QName name, Object object)
          Convert a Java object to an XML fragment, using our configured type-mappings.
static boolean remoteExceptionIs(RemoteException fault, Class<? extends Exception> type)
          Check whether this exception was caused by the remote service throwing a given type of exception.
static
<T> T[]
toArray(Class<T> type, Object possibleArrayList)
          Convert a return value that should be an array to a sane form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AxisUtils

public AxisUtils()
Method Detail

toArray

public static <T> T[] toArray(Class<T> type,
                              Object possibleArrayList)
Convert a return value that should be an array to a sane form. When a document/literal service returns an array, there are three possibilities: - If zero elements are returned, axis returns null. => Convert to empty array. - If one element is returned, axis returns just that element. => Pack into 1-element array. - If multiple elements are returns, axis returns an ArrayList. => Convert to an array. If you were expecting null, but you got an empty string, you might be missing a type mapping.


getTextContent

@Deprecated
public static String getTextContent(Element parent)
Deprecated. 

Return the concatenation of all text/cdata child nodes.

Returns:
String text context of the element (deprecated Use XMLUtils.getChildCharacterData() instead)

getExceptionName

public static String getExceptionName(RemoteException ex)
Get the name of the exception given by a remote service. When a service throws an exception the client just gets a RemoteException. This may be an AxisFault, in which case the fault's detail element contains the name of the exception as thrown by the service.

Parameters:
ex - a fault from Call.invoke().
Returns:
the name of the exception thrown by the service, or null if not available

getHostName

public static String getHostName(RemoteException ex)
Get the name of the host that threw an exception.

Parameters:
ex - a fault from Call.invoke().
Returns:
the name of the host that returned the fault, or null if not available

remoteExceptionIs

public static boolean remoteExceptionIs(RemoteException fault,
                                        Class<? extends Exception> type)
Check whether this exception was caused by the remote service throwing a given type of exception.

Parameters:
fault - a fault from Call.invoke().
type - the class of an exception
Returns:
true if the exception's type is equal to the name of the given exception

getChildElement

public static Element getChildElement(Element parent,
                                      String namespace,
                                      String localName)
                               throws IllegalArgumentException
Return the single direct child element with the given name.

Returns:
the single found element
Throws:
IllegalArgumentException - if there is not exactly one such element

getOptionalChildElement

public static Element getOptionalChildElement(Element parent,
                                              String namespace,
                                              String localName)
                                       throws IllegalArgumentException
Return the single direct child element with the given name, if present

Returns:
the single found element
Throws:
IllegalArgumentException - only if there are multiple elements present

getChildElement

public static Element getChildElement(Element parent,
                                      String namespace,
                                      String localName,
                                      boolean required)
                               throws IllegalArgumentException
Return the single direct child element with the given name.

Parameters:
required - a boolean flag to indicate if the element is required, or is optional
Returns:
the single found element, or null if it does not exist
Throws:
IllegalArgumentException - if there is not exactly one such element, if one is required

getChildElement

public static Element getChildElement(Element parent,
                                      QName qname)
                               throws IllegalArgumentException
Return the single direct child element with the given name.

Returns:
the single found element
Throws:
IllegalArgumentException - if there is not exactly one such element

getOptionalChildElement

public static Element getOptionalChildElement(Element parent,
                                              QName qname)
                                       throws IllegalArgumentException
Return the single direct child element with the given name, if present

Returns:
the single found element
Throws:
IllegalArgumentException - only if there are multiple elements present

getChildElement

public static Element getChildElement(Element parent,
                                      QName qname,
                                      boolean required)
                               throws IllegalArgumentException
Return the single direct child element with the given name.

Parameters:
required - a boolean flag to indicate if the element is required, or is optional
Returns:
the single found element, or null if it does not exist
Throws:
IllegalArgumentException - if there is not exactly one such element, if one is required

getSingletonElementText

public static String getSingletonElementText(Element parent,
                                             String namespace,
                                             String localName)
                                      throws IllegalArgumentException
Return the contents of the named child element.

Throws:
IllegalArgumentException - if there isn't exactly one such child

getSingletonElementText

public static String getSingletonElementText(Element parent,
                                             QName qname)
                                      throws IllegalArgumentException
Return the contents of the named child element.

Throws:
IllegalArgumentException - if there isn't exactly one such child

getChildElements

public static Element[] getChildElements(Element parent,
                                         String namespace,
                                         String localName)
Return all direct children with the given name.


objectToString

public static String objectToString(QName name,
                                    Object object)
Convert a Java object to an XML fragment, using our configured type-mappings.

Parameters:
object - object to convert
Returns:
XML fragment
Since:
5.1

elementToObject

public static <T> T elementToObject(Element element,
                                    Class<T> cls)
Convert an Element to a Java object, using the client type mappings.

Parameters:
element - DOM element to read
cls - Java class of expected result
Returns:
an instance of cls
Since:
5.1

createFederationHeaders

public static SOAPHeaderElement[] createFederationHeaders(org.apache.axis.message.addressing.EndpointReferenceType[] eprs)
Create the SOAP headers to hold the federation information, if any.

Parameters:
info - EPRs of a management resources, or empty if none is required
Returns:
an array of SOAP headers that should be added to the message
See Also:
createFederationHeader(org.apache.axis.message.addressing.EndpointReferenceType)


Copyright © 2001-2008 University of Southampton IT Innovation Centre. All Rights Reserved.