jInfer

cz.cuni.mff.ksi.jinfer.xsdimportdom
Class DOMHelper

java.lang.Object
  extended by cz.cuni.mff.ksi.jinfer.xsdimportdom.DOMHelper

public final class DOMHelper
extends Object

Helper class for DOMHandler, provides convenience methods used during parsing. It is best NOT to use these methods outside this package. Please read package info.


Method Summary
static Element createSentinel(Element domElem, List<String> context, XSDAttribute useAsName)
          Create an Element with type RegexpType.LAMBDA with proper constraints and metadata containing sentinel info.
static RegexpInterval determineInterval(Element node)
          Create valid interval from current node.
static String errorWrongNested(XSDTag child, XSDTag parent)
          Helper method for retrieving error message when tags are not nested correctly.
static void extractSubnodesFromContainer(Element subtree, Element destination, String containerType)
          Extract subnodes and attributes from subtree stored in container and put them directly under the destination element.
static void finalizeElement(Element ret, List<String> newContext)
          Check if Element is properly defined; redefine it to lambda when it was empty, or redefine it to token if it only contained a simple data type.
static Map<String,Object> getAttributeMetadata(Element child)
          Prepare metadata of attribute tag from the child node.
static String getAttributeName(Element child)
          Extract value of name or ref from an attribute tag.
static Element getDOMElement(Node node)
          Determine if given node is in fact a DOM.Element and return a type cast if so.
static String warnUnsupported(XSDTag child, XSDTag parent)
          Helper method for retrieving warning message when unsupported structure occurs in schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDOMElement

public static Element getDOMElement(Node node)
Determine if given node is in fact a DOM.Element and return a type cast if so.

Parameters:
node - Entity to be checked.
Returns:
Parameter cast to DOM.Element, or null.
See Also:
Element

determineInterval

public static RegexpInterval determineInterval(Element node)
Create valid interval from current node. If node has attributes minOccurs or maxOccurs, their values are used. Otherwise a default interval is returned (RegexpInterval.getOnce()).

Parameters:
node - Node from which the information is extracted.
Returns:
Valid interval.
See Also:
XSDOccurences.createInterval(java.lang.String, java.lang.String)

errorWrongNested

public static String errorWrongNested(XSDTag child,
                                      XSDTag parent)
Helper method for retrieving error message when tags are not nested correctly.

Parameters:
child - Tag of the child node.
parent - Tag of the parent node.
Returns:
Error message.

warnUnsupported

public static String warnUnsupported(XSDTag child,
                                     XSDTag parent)
Helper method for retrieving warning message when unsupported structure occurs in schema.

Parameters:
child - Tag of the child node.
parent - Tag of the parent node.
Returns:
Warning message.

createSentinel

public static Element createSentinel(Element domElem,
                                     List<String> context,
                                     XSDAttribute useAsName)
                              throws XSDException
Create an Element with type RegexpType.LAMBDA with proper constraints and metadata containing sentinel info. This kind of element is used when it was defined previously and it is unnecessary to build a rule subtree for it again (it is either a reference, or a leaf in recursion).

Parameters:
domElem - Node in the DOM tree from which the sentinel is made.
context - Context of the node in the rule tree.
useAsName - Name of the attribute to be used as a name of the new Element.
Returns:
Sentinel element.
Throws:
XSDException - Raise exception when schema contains errors.
See Also:
IGGUtils.METADATA_SENTINEL

extractSubnodesFromContainer

public static void extractSubnodesFromContainer(Element subtree,
                                                Element destination,
                                                String containerType)
                                         throws XSDException
Extract subnodes and attributes from subtree stored in container and put them directly under the destination element. This is a helper method for omitting containers.

Parameters:
subtree - Container element, from which the subnodes will be extracted.
destination - Destination element, where the subnodes are copied to.
containerType - Expected name of the subtree element, this is just a consistency check.
Throws:
XSDException - Raise exception when schema contains errors.

finalizeElement

public static void finalizeElement(Element ret,
                                   List<String> newContext)
Check if Element is properly defined; redefine it to lambda when it was empty, or redefine it to token if it only contained a simple data type. This method should be used only when the tag of a node was ELEMENT!

Parameters:
ret - Element to be finalized.

getAttributeName

public static String getAttributeName(Element child)
Extract value of name or ref from an attribute tag.

Parameters:
child - Node containing the attribute tag.
Returns:
Value of tag attribute name or ref or empty string.

getAttributeMetadata

public static Map<String,Object> getAttributeMetadata(Element child)
Prepare metadata of attribute tag from the child node. If the child has defined tag attribute use, add this information to metadata.

Parameters:
child - DOM node of the attribute tag.
Returns:
New metadata.

jInfer

Generated on Fri Dec 9 00:01:25 CET 2011