Class DocumentConfigurationHelper

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static XPathExpression compileXPath​(String expression)
      Compiles the given XPath expression.
      ConfigurationMerger<Document> configurationMerger()
      Creates the applicable ConfigurationMerger object for the type associated with this ConfigurationHelper.
      net.obvj.confectory.internal.helper.DocumentConfigurationHelper.NodeListHolder get​(String xpath)
      Returns the NodeList object associated with the specified @{code XPath} in the XML document in context.
      String getAsString()
      Returns a string representation of the bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.
      Document getBean()
      Returns the configuration bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.
      Boolean getBoolean​(String xpath)
      Returns the Boolean object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to boolean.
      Double getDouble​(String xpath)
      Returns the Double object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to double.
      Integer getInteger​(String xpath)
      Returns the Integer object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to int.
      Long getLong​(String xpath)
      Returns the Long object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to long.
      Boolean getMandatoryBoolean​(String xpath)
      Returns the Boolean object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to boolean.
      Double getMandatoryDouble​(String xpath)
      Returns the Double object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to double.
      Integer getMandatoryInteger​(String xpath)
      Returns the Integer object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to int.
      Long getMandatoryLong​(String xpath)
      Returns the Long object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to long.
      String getMandatoryString​(String xpath)
      Returns the String object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element.
      String getString​(String xpath)
      Returns the String object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element.
    • Constructor Detail

      • DocumentConfigurationHelper

        public DocumentConfigurationHelper​(Document document)
        Creates a new helper for the given XML Document.
        Parameters:
        document - the JSON document to set
    • Method Detail

      • getBoolean

        public Boolean getBoolean​(String xpath)
        Returns the Boolean object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to boolean.

        Note: If the evaluation result is a valid string it will parsed according to Boolean.parseBoolean(String), it will return false for any string different than "true" (ignoring case).

        Specified by:
        getBoolean in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Boolean object from the evaluation result of the specified XPath expression; null if the expression is not found
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, or it evaluates to more than a single element
      • getMandatoryBoolean

        public Boolean getMandatoryBoolean​(String xpath)
        Returns the Boolean object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to boolean.

        If no value is found for the given expression, then an exception will be thrown.

        Note: If the evaluation result is a valid string it will parsed according to Boolean.parseBoolean(String), it will return false for any string different than "true" (ignoring case).

        Specified by:
        getMandatoryBoolean in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Boolean object from the evaluation result of the the specified XPath expression; never null
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, not found, or it evaluates to more than a single element
      • getInteger

        public Integer getInteger​(String xpath)
        Returns the Integer object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to int.
        Specified by:
        getInteger in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Integer object from the evaluation result of the specified XPath expression; null if the expression is not found
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to int
      • getMandatoryInteger

        public Integer getMandatoryInteger​(String xpath)
        Returns the Integer object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to int.

        If no value is found for the given expression, then an exception will be thrown.

        Specified by:
        getMandatoryInteger in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Integer object from the evaluation result of the the specified XPath expression; never null
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, not found, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to int
      • getLong

        public Long getLong​(String xpath)
        Returns the Long object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to long.
        Specified by:
        getLong in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Long object from the evaluation result of the specified XPath expression; null if the expression is not found
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to long
      • getMandatoryLong

        public Long getMandatoryLong​(String xpath)
        Returns the Long object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to long.

        If no value is found for the given expression, then an exception will be thrown.

        Specified by:
        getMandatoryLong in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Long object from the evaluation result of the the specified XPath expression; never null
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, not found, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to long
      • getDouble

        public Double getDouble​(String xpath)
        Returns the Double object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to double.
        Specified by:
        getDouble in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Double object from the evaluation result of the specified XPath expression; null if the expression is not found
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to double
      • getMandatoryDouble

        public Double getMandatoryDouble​(String xpath)
        Returns the Double object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element that can be converted to double.

        If no value is found for the given expression, then an exception will be thrown.

        Specified by:
        getMandatoryDouble in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the Double object from the evaluation result of the the specified XPath expression; never null
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, not found, or it evaluates to more than a single element
        NumberFormatException - if the XPath result cannot be assigned to double
      • getString

        public String getString​(String xpath)
        Returns the String object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element.
        Specified by:
        getString in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the String value associated with the specified XPath expression; null if the expression is not found
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, or it evaluates to more than a single element
      • getMandatoryString

        public String getMandatoryString​(String xpath)
        Returns the String object associated with the specified XPath expression in the XML document in context, provided that the expression returns a single element.

        If no value is found for the given expression, then an exception will be thrown.

        Specified by:
        getMandatoryString in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to evaluate
        Returns:
        the String value associated with the specified XPath expression; never null
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is either invalid, not found, or it evaluates to more than a single element
      • get

        public net.obvj.confectory.internal.helper.DocumentConfigurationHelper.NodeListHolder get​(String xpath)
        Returns the NodeList object associated with the specified @{code XPath} in the XML document in context.
        Specified by:
        get in interface ConfigurationDataRetriever<Document>
        Parameters:
        xpath - the XPath expression to read
        Returns:
        the NodeList object associated with the specified XPath
        Throws:
        NullPointerException - if the XPath expression is null
        ConfigurationException - if the XPath expression is not valid
      • compileXPath

        public static XPathExpression compileXPath​(String expression)
                                            throws XPathExpressionException
        Compiles the given XPath expression.
        Parameters:
        expression - the XPath expression to be compiled
        Returns:
        an XPathExpression object that can be used for further evaluation
        Throws:
        XPathExpressionException - if the expression cannot be compiled