com.novell.nds.dirxml.driver.xds.util
Class XDSUtil

java.lang.Object
  extended bycom.novell.nds.dirxml.driver.xds.util.XDSUtil

public abstract class XDSUtil
extends Object

A utilities library for DirXML driver developers.


Method Summary
static void appendNode(Node dest, Node src)
          Appends a DOM source node as a child of a DOM destination node.
static boolean appendStackTrace(Exception e)
          Used to determine whether a stack trace should be appended to a status document.
static XDSStatusElement appendStatus(StatusDocument doc, StatusAttributes attrs, String description)
          Appends a <status> element to a DOM document.
static XDSStatusElement appendStatus(StatusDocument doc, StatusAttributes attrs, String description, Exception exception, boolean stack, com.novell.nds.dirxml.driver.XmlDocument xml)
          Appends one or more <status> elements to a DOM document.
static void appendThrowable(Element root, Throwable t, boolean appendStackTrace)
          Appends a Throwable object to the passed element.
static void appendXML(Element element, String xml)
          Translates an XML string into a DOM and appends it the passed DOM element.
static void checkArg(String argName, Object argValue, int position)
          Throws an IllegalArgumentException if the passed argument value is null.
static void checkArg(String argName, String argValue, int position)
          Throws an IllegalArgumentException if the passed argument value is null.
static void getChildElements(Element parent, List elements)
          Returns the child elements of the passed element.
static void getChildNodes(Element parent, int nodeType, List nodes)
          Returns the children of the passed element of the passed type.
static String getChildText(Element someElement)
          Returns a string that contains the concatenated child/subordinates text nodes of the passed DOM element.
static void getChildTextNodes(Element parent, List textNodes)
          Returns the child text nodes of the passed element.
static Node getFirst(NodeList list)
          Returns the fist Node in a NodeList.
static String getRDN(String slashSrcDN)
          Extracts the Relative Distinguished Name (RDN) from a slash-formatted Distinguished Name (DN).
static String getStackTrace(Throwable t)
          Returns a Throwable object's stack trace as a string.
static boolean isChildOfInputOrOutput(Element element)
          Is the passed element a proper child of input or output.
static boolean isInputOrOutputElement(Element element)
          Is the passed element an input or output element?
static boolean isNDSElement(Element element)
          Is the passed element an nds?
static boolean isNullOrEmpty(NodeList list)
          Is the passed NodeList null or empty?
static boolean isNullOrEmpty(com.novell.nds.dirxml.driver.XmlDocument xml)
          Is the passed XmlDocument null or empty?
static boolean isValue(String string)
          Is the passed string not null and not just whitespace?
static boolean isWhitespace(String s)
          Does the passed string contain only whitespace characters?
static boolean noValue(String string)
          Is null or whitespace?
static long toMillis(int seconds)
          Converts seconds to milliseconds.
static String toNull(String someValue)
          Turns an all whitespace string into null.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isChildOfInputOrOutput

public static boolean isChildOfInputOrOutput(Element element)
Is the passed element a proper child of input or output.

Parameters:
element - may be null
Returns:
true if it is; false otherwise

isInputOrOutputElement

public static final boolean isInputOrOutputElement(Element element)
Is the passed element an input or output element?

Parameters:
element - may be null
Returns:
true if it is; false otherwise

isNDSElement

public static final boolean isNDSElement(Element element)
Is the passed element an nds?

Parameters:
element - may be null
Returns:
true if it is; false otherwise

getStackTrace

public static String getStackTrace(Throwable t)
Returns a Throwable object's stack trace as a string.

Parameters:
t - may be null
Returns:
t's stack trace; "" if t is null; will not return null

toMillis

public static long toMillis(int seconds)
Converts seconds to milliseconds.

Parameters:
seconds - the number of seconds
Returns:
the equivalent number of milliseconds

appendStatus

public static XDSStatusElement appendStatus(StatusDocument doc,
                                            StatusAttributes attrs,
                                            String description)
Appends a <status> element to a DOM document.

Parameters:
doc - the doc to append to; must not be null
attrs - status attribute values; may be null
description - text for <description> element; may be null
Returns:
may return null

appendStatus

public static XDSStatusElement appendStatus(StatusDocument doc,
                                            StatusAttributes attrs,
                                            String description,
                                            Exception exception,
                                            boolean stack,
                                            com.novell.nds.dirxml.driver.XmlDocument xml)
Appends one or more <status> elements to a DOM document.

Parameters:
doc - the doc to append to; may be null
attrs - status attribute values; may be null
description - text for <description> element; may be null; if null, the message from exception is used
exception - may be null
stack - append a stack trace of exception?
xml - the XML document to append; may be null
Returns:
the last appended <status> element; may return null

appendXML

public static void appendXML(Element element,
                             String xml)
Translates an XML string into a DOM and appends it the passed DOM element. NOTE: the passed String must not contain illegal XML characters (i.e., '<' and '?').

Parameters:
element - the parent; may be null
xml - the XML to append; may be null

appendThrowable

public static final void appendThrowable(Element root,
                                         Throwable t,
                                         boolean appendStackTrace)
Appends a Throwable object to the passed element.

Parameters:
root - the element to append to; may be null
t - may be null
appendStackTrace - should the stack trace be appended?

appendNode

public static void appendNode(Node dest,
                              Node src)
Appends a DOM source node as a child of a DOM destination node.

Parameters:
dest - the parent node; may be null
src - the node to append append under dest; dest can be from a different document than src

appendStackTrace

public static boolean appendStackTrace(Exception e)
Used to determine whether a stack trace should be appended to a status document.

In general, a stack trace is only useful if an exception runtime exception (e.g., NullPointerException) is thrown.

Parameters:
e - may be null
Returns:
true:
if a stack trace should be included
false:
if a stack trace should not be included

isWhitespace

public static boolean isWhitespace(String s)
Does the passed string contain only whitespace characters?

Parameters:
s - the string to test; may be null
Returns:
true if empty string or s is whitespace; false if s is null or contains a non-whitespace character

isValue

public static final boolean isValue(String string)
Is the passed string not null and not just whitespace?

Parameters:
string - the string to evaluate; may be null
Returns:
true if non-null or contains characters other than whitespace; false otherwise

noValue

public static final boolean noValue(String string)
Is null or whitespace?

Parameters:
string - the string to evaluate; may be null
Returns:
true if null or contains characters only whitespace characters; false otherwise

toNull

public static String toNull(String someValue)
Turns an all whitespace string into null.

Parameters:
someValue - may be null
Returns:
will not return an all-whitespace string

getChildText

public static String getChildText(Element someElement)
Returns a string that contains the concatenated child/subordinates text nodes of the passed DOM element.

Parameters:
someElement - must not be null
Returns:
may return null; will not return empty string

isNullOrEmpty

public static final boolean isNullOrEmpty(NodeList list)
Is the passed NodeList null or empty?

Parameters:
list - may be null
Returns:
true if it is; false otherwise

getFirst

public static final Node getFirst(NodeList list)
Returns the fist Node in a NodeList.

Parameters:
list - may be null
Returns:
may return null

getChildElements

public static void getChildElements(Element parent,
                                    List elements)
Returns the child elements of the passed element.

Parameters:
parent - must not be null
elements - must not be null; will be empty after this method is invoked if there are no child elements

getChildTextNodes

public static void getChildTextNodes(Element parent,
                                     List textNodes)
Returns the child text nodes of the passed element.

Parameters:
parent - must not be null
textNodes - must not be null; will be empty after this method is invoked if there are no child text nodes

getChildNodes

public static void getChildNodes(Element parent,
                                 int nodeType,
                                 List nodes)
Returns the children of the passed element of the passed type.

Parameters:
parent - must not be null
nodeType - should be a standard node type
nodes - must not be null; will be empty after this method is invoked if there are no matching child node types

checkArg

public static final void checkArg(String argName,
                                  Object argValue,
                                  int position)
Throws an IllegalArgumentException if the passed argument value is null.

Parameters:
argName - the name of the argument
argValue - the value of the argument
position - the position of the argument
Throws:
IllegalArgumentException - when argValue is null

checkArg

public static final void checkArg(String argName,
                                  String argValue,
                                  int position)
Throws an IllegalArgumentException if the passed argument value is null.

Parameters:
argName - the name of the argument
argValue - the value of the argument
position - the position of the argument
Throws:
IllegalArgumentException - when argValue is null

getRDN

public static final String getRDN(String slashSrcDN)
Extracts the Relative Distinguished Name (RDN) from a slash-formatted Distinguished Name (DN).

Parameters:
slashSrcDN - a slash-formatted DN
Returns:
the RDN; may return null

isNullOrEmpty

public static boolean isNullOrEmpty(com.novell.nds.dirxml.driver.XmlDocument xml)
Is the passed XmlDocument null or empty?

Parameters:
xml - the document; may be null
Returns:
true if xml is null or there's no document element; false otherwise