xArch/xADL 2.0 Data Binding Library

edu.uci.isr.xarch
Class XArchUtils

java.lang.Object
  extended byedu.uci.isr.xarch.XArchUtils

public class XArchUtils
extends Object

Utility functions for xArch API implementations. This class is the only one that is XML-parser-dependent.

Author:
Eric M. Dashofy (edashofy@ics.uci.edu)

Constructor Summary
XArchUtils()
           
 
Method Summary
static String capFirstLetter(String s)
           
static IXArch cloneXArch(IXArch xArchToClone)
          Deprecated. Use cloneXArch from an implementation of IXArchImplementation instead.
static IXArch createXArch()
          Deprecated. Use createXArch from an implementation of IXArchImplementation instead.
static IXArch createXArch(Document doc)
          Deprecated. Use parse(Document) from a DOM-based implementation of IXArchImplementation instead.
protected static void fixAttribute(Attr attr, Hashtable prefixMap)
          Fixes a specific attribute.
protected static void fixElement(Element elt, Hashtable prefixMap)
          Fixes a specific element.
protected static void fixNamespaces(Document doc)
          Fixes the namespace prefixes in a document before it is serialized.
protected static void fixNode(Node n, Hashtable prefixMap)
          Fixes a specific node.
protected static void fixXsiTypeAttribute(Attr attr, Hashtable prefixMap)
          Fixes a specific xsi:type attribute.
static IXArchImplementation getDefaultXArchImplementation()
          Returns the default (i.e.
static DOMImplementation getDOMImplementation()
          Deprecated. No public replacement.
static String getImplName(String packageName, String xsiTypeName)
          Gets the implementation name for a given xsi:type.
static String getImplNameFromInterfaceName(String interfaceName)
          Gets the implementation name for a given interface name.
static String getInterfaceName(String packageName, String xsiTypeName)
          Gets the interface name for a given xsi:type.
protected static Document getOwnerDocument(Node n)
          Gets the owner document from a DOM node.
static String getPackageName(String packageTitle)
          Gets the full package name given a package title.
static String[] getPackageNames()
          Gets a list of subpackages that represent generated APIs for schemas.
static String getPackageTitle(String schemaURI)
          Guesses the package title where a given schema URI would have been generated by apigen.
static String getPrettyXmlRepresentation(IXArch xArch)
          Deprecated. Use serialize from an implementation of IXArchImplementation instead.
protected static String getReasonablePrefix(String namespaceURI, Hashtable prefixMap)
          Generate a reasonable namespace prefix based on a namespace URI and a prefix map (to prevent collisions).
static QName getXSIType(Element elt)
          Get the xsi:type for a given element.
static boolean isContainedIn(IXArch xArch, IXArchElement elt)
          Deprecated. Use isContainedIn from an implementation of IXArchImplementation instead.
static IXArch parse(Reader r)
          Deprecated. Use parse(Reader) from an implementation of IXArchImplementation instead.
static Document parseToDocument(Reader r)
          Deprecated. No public replacement.
static String uncapFirstLetter(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XArchUtils

public XArchUtils()
Method Detail

getDefaultXArchImplementation

public static IXArchImplementation getDefaultXArchImplementation()
Returns the default (i.e. DOM-based) implementation of the xArch data bindings. This is the entrypoint to all other library APIs.

Returns:
Default DOM-based xArch data binding implementation.

getDOMImplementation

public static DOMImplementation getDOMImplementation()
Deprecated. No public replacement.

DEPRECATED: Gets the DOMImplementation for the preferred parser.

Returns:
DOMImplementation object for the preferred parser.

fixNamespaces

protected static void fixNamespaces(Document doc)
Fixes the namespace prefixes in a document before it is serialized. This is here because the Xerces serializers, as of 1.2.1, are badly broken and do not do this themselves.

Parameters:
doc - Document on which to fix namespaces.

fixNode

protected static void fixNode(Node n,
                              Hashtable prefixMap)
Fixes a specific node. See fixNamespaces

Parameters:
n - Node to fix.
prefixMap - Prefix<->Namespace URI mappings.

fixElement

protected static void fixElement(Element elt,
                                 Hashtable prefixMap)
Fixes a specific element. See fixNamespaces

Parameters:
elt - Element to fix.
prefixMap - Prefix<->Namespace URI mappings.

getReasonablePrefix

protected static String getReasonablePrefix(String namespaceURI,
                                            Hashtable prefixMap)
Generate a reasonable namespace prefix based on a namespace URI and a prefix map (to prevent collisions).

Parameters:
namespaceURI - Namespace URI to use to generate prefix
prefixMap - Prefix map.
Returns:
reasonable namespace prefix not already in prefixMap

fixAttribute

protected static void fixAttribute(Attr attr,
                                   Hashtable prefixMap)
Fixes a specific attribute. See fixNamespaces

Parameters:
attr - Attribute to fix.
prefixMap - Prefix<->Namespace URI mappings.

getOwnerDocument

protected static Document getOwnerDocument(Node n)
Gets the owner document from a DOM node. This works even if the node is an Attr, which has no owner document apparently, by getting the Attr's owner element's owner document.

Parameters:
n - Node for which to get the owner document.
Returns:
Owner document for this node.

fixXsiTypeAttribute

protected static void fixXsiTypeAttribute(Attr attr,
                                          Hashtable prefixMap)
Fixes a specific xsi:type attribute. See fixNamespaces

Parameters:
attr - xsi:type attribute to fix.
prefixMap - Prefix<->Namespace URI mappings.

getPrettyXmlRepresentation

public static String getPrettyXmlRepresentation(IXArch xArch)
                                         throws DOMException
Deprecated. Use serialize from an implementation of IXArchImplementation instead.

DEPRECATED: Returns a nice-looking representation of the given XML document. Sub-elements are properly indented, and long lines are indent-wrapped nicely, too.

Parameters:
xArch - Document to turn into a string.
Returns:
String representation of the document, prettyprinted.
Throws:
DOMException

parseToDocument

public static Document parseToDocument(Reader r)
                                throws SAXException,
                                       IOException
Deprecated. No public replacement.

DEPRECATED: Parse a stream into a DOM document.

Parameters:
r - Reader to parse from.
Returns:
new DOM document corresponding to the parsed stream
Throws:
SAXException - on parse failure
IOException - on I/O failure.

parse

public static IXArch parse(Reader r)
                    throws SAXException,
                           IOException
Deprecated. Use parse(Reader) from an implementation of IXArchImplementation instead.

DEPRECATED: Parse an xArch document from a reader, returning an IXArch object.

Parameters:
r - Reader from which to parse xArch document.
Returns:
IXArch object representing the document.
Throws:
SAXException - if there was a problem parsing the document.
IOException - if there was an I/O error while reading the document.

createXArch

public static IXArch createXArch()
Deprecated. Use createXArch from an implementation of IXArchImplementation instead.

DEPRECATED: Create an IXArch object based on a new DOM Document.

Returns:
New IXArch object.

cloneXArch

public static IXArch cloneXArch(IXArch xArchToClone)
Deprecated. Use cloneXArch from an implementation of IXArchImplementation instead.

DEPRECATED: Clones an xArch document, given its IXArch (root) element. Changes to one document will not affect the other.

Parameters:
xArchToClone - The root xArch element of the document to clone.
Returns:
Root element of cloned document.

createXArch

public static IXArch createXArch(Document doc)
Deprecated. Use parse(Document) from a DOM-based implementation of IXArchImplementation instead.

DEPRECATED: Create an IXArch object based on a given DOM Document.

Returns:
New IXArch object.

isContainedIn

public static boolean isContainedIn(IXArch xArch,
                                    IXArchElement elt)
Deprecated. Use isContainedIn from an implementation of IXArchImplementation instead.

DEPRECATED: Determines if a given IXArchElement is contained (a child of) a given IXArch.

Parameters:
xArch - IXArch to check for the element.
elt - Element to check for parentage.
Returns:
true if the element is attached, false otherwise.

getPackageTitle

public static String getPackageTitle(String schemaURI)
Guesses the package title where a given schema URI would have been generated by apigen. Used internally; not for external use.

Parameters:
schemaURI - Schema URI (Namespace URI) from which to guess package title.
Returns:
Probable package title.

getPackageName

public static String getPackageName(String packageTitle)
Gets the full package name given a package title. Used internally; not for external use.

Parameters:
packageTitle - Package Title from getPackageTitle()
Returns:
Package name.

getInterfaceName

public static String getInterfaceName(String packageName,
                                      String xsiTypeName)
Gets the interface name for a given xsi:type. Not for public use.

Parameters:
packageName - Package name for the interface.
xsiTypeName - xsi:type name.
Returns:
Interface name.

getImplName

public static String getImplName(String packageName,
                                 String xsiTypeName)
Gets the implementation name for a given xsi:type. Not for public use.

Parameters:
packageName - Package name for the interface.
xsiTypeName - xsi:type name.
Returns:
Implementation name.

getImplNameFromInterfaceName

public static String getImplNameFromInterfaceName(String interfaceName)
Gets the implementation name for a given interface name. Not for public use.

Parameters:
interfaceName - Interface class name.
Returns:
Implementation name.

getPackageNames

public static String[] getPackageNames()
Gets a list of subpackages that represent generated APIs for schemas. Package names are in the form "edu.uci.isr.xarch.packagename"

Returns:
List of package names.

getXSIType

public static QName getXSIType(Element elt)
Get the xsi:type for a given element. This function is superior to the one in DOMUtils because it will actually guess the xsi:type using a tree-walking/reflection based algorithm when possible. Not for public use.

Parameters:
elt - Element whose type you want to get.
Returns:
Element's xsi:type or null if it can't be determined.

capFirstLetter

public static String capFirstLetter(String s)

uncapFirstLetter

public static String uncapFirstLetter(String s)

xArch/xADL 2.0 Data Binding Library