org.inria.ns.reflex.util
Class UnmarshalHelper

java.lang.Object
  extended by org.inria.ns.reflex.util.UnmarshalHelper

public class UnmarshalHelper
extends Object

Helper methods when unmarshalling.

Author:
Philippe Poulard

Constructor Summary
UnmarshalHelper()
           
 
Method Summary
static int getPositionAttributeValue(Element element, String attName, String[] values)
          Return the position of an attribute's value in a list.
static int getPositionAttributeValue(Element element, String attName, String[] values, int defaultValue)
          Return the position of an attribute's value in a list.
static boolean isBoundedElement(Node node, String nsURI)
          Return true if the node is an element bound to the given namespace URI.
static Expression unmarshalTest(Element element)
          XML unmarshaller for the test attribute that is an attribute value template.
static boolean yesOrNoAttributeValue(Element element, String attName, boolean defaultValue)
          Return the boolean value corresponding to an attribute that can be "yes" or "no".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnmarshalHelper

public UnmarshalHelper()
Method Detail

yesOrNoAttributeValue

public static boolean yesOrNoAttributeValue(Element element,
                                            String attName,
                                            boolean defaultValue)
Return the boolean value corresponding to an attribute that can be "yes" or "no".

Parameters:
element - The element that have the attribute to test.
attName - The name of the attribute to test.
defaultValue - The value to return if the attribute doesn't exist.
Returns:
true if the attribute value is "yes", false if the attribute value is "no", the default value given if the attribute doesn't exist.

getPositionAttributeValue

public static int getPositionAttributeValue(Element element,
                                            String attName,
                                            String[] values)
Return the position of an attribute's value in a list.

Parameters:
element - The element that have the attribute to test.
attName - The name of the attribute to test.
values - The list of possible values for the attribute.
Returns:
The position of the attribute's value in the list (that starts from 0), or -1 if the attribute doesn't exist or if its value is not found in the list.

getPositionAttributeValue

public static int getPositionAttributeValue(Element element,
                                            String attName,
                                            String[] values,
                                            int defaultValue)
Return the position of an attribute's value in a list.

Parameters:
element - The element that have the attribute to test.
attName - The name of the attribute to test.
values - The list of possible values for the attribute.
defaultValue - The default value.
Returns:
The position of the attribute's value in the list (that starts from 0), or the default value if the attribute doesn't exist or if its value is not found in the list.

unmarshalTest

public static Expression unmarshalTest(Element element)
                                throws XPathException
XML unmarshaller for the test attribute that is an attribute value template.

Parameters:
element - The XML element to unmarshall. Used for namespace prefix resolution when performing XPath expressions.
Returns:
The compiled Expression corresponding to the expression string of the attribute value.
Throws:
XPathException - If the test is an invalid AVT.

isBoundedElement

public static boolean isBoundedElement(Node node,
                                       String nsURI)
Return true if the node is an element bound to the given namespace URI.

Parameters:
node - The node to test.
nsURI - The namespace URI.
Returns:
true if the node is an element bound to the given namespace URI.