Class DocumentConfigurationHelper
- java.lang.Object
-
- net.obvj.confectory.internal.helper.DocumentConfigurationHelper
-
- All Implemented Interfaces:
ConfigurationDataRetriever<Document>,ConfigurationHelper<Document>
public class DocumentConfigurationHelper extends Object implements ConfigurationHelper<Document>
A generic Configuration Helper that retrieves data from an XMLDocumentusing XPath.- Since:
- 2.4.0
- Author:
- oswaldo.bapvic.jr (Oswaldo Junior)
-
-
Constructor Summary
Constructors Constructor Description DocumentConfigurationHelper(Document document)Creates a new helper for the given XMLDocument.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static XPathExpressioncompileXPath(String expression)Compiles the given XPath expression.ConfigurationMerger<Document>configurationMerger()Creates the applicableConfigurationMergerobject for the type associated with thisConfigurationHelper.net.obvj.confectory.internal.helper.DocumentConfigurationHelper.NodeListHolderget(String xpath)Returns theNodeListobject associated with the specified @{code XPath} in the XML document in context.StringgetAsString()Returns a string representation of the bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.DocumentgetBean()Returns the configuration bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.BooleangetBoolean(String xpath)Returns theBooleanobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toboolean.DoublegetDouble(String xpath)Returns theDoubleobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted todouble.IntegergetInteger(String xpath)Returns theIntegerobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toint.LonggetLong(String xpath)Returns theLongobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted tolong.BooleangetMandatoryBoolean(String xpath)Returns theBooleanobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toboolean.DoublegetMandatoryDouble(String xpath)Returns theDoubleobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted todouble.IntegergetMandatoryInteger(String xpath)Returns theIntegerobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toint.LonggetMandatoryLong(String xpath)Returns theLongobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted tolong.StringgetMandatoryString(String xpath)Returns theStringobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element.StringgetString(String xpath)Returns theStringobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element.
-
-
-
Method Detail
-
getBean
public Document getBean()
Description copied from interface:ConfigurationDataRetrieverReturns the configuration bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.- Specified by:
getBeanin interfaceConfigurationDataRetriever<Document>- Returns:
- the XML
Documentin context
-
getAsString
public String getAsString()
Description copied from interface:ConfigurationDataRetrieverReturns a string representation of the bean used by this data retriever, typically for manual handling and/or troubleshooting purposes.- Specified by:
getAsStringin interfaceConfigurationDataRetriever<Document>- Returns:
- the XML
Documentin context, transformed/encoded as string - Since:
- 2.5.0
-
getBoolean
public Boolean getBoolean(String xpath)
Returns theBooleanobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toboolean.Note: If the evaluation result is a valid string it will parsed according to
Boolean.parseBoolean(String), it will returnfalsefor any string different than"true"(ignoring case).- Specified by:
getBooleanin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Booleanobject from the evaluation result of the specifiedXPathexpression;nullif the expression is not found - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, or it evaluates to more than a single element
-
getMandatoryBoolean
public Boolean getMandatoryBoolean(String xpath)
Returns theBooleanobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toboolean.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 returnfalsefor any string different than"true"(ignoring case).- Specified by:
getMandatoryBooleanin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Booleanobject from the evaluation result of the the specifiedXPathexpression; nevernull - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, not found, or it evaluates to more than a single element
-
getInteger
public Integer getInteger(String xpath)
Returns theIntegerobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toint.- Specified by:
getIntegerin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Integerobject from the evaluation result of the specifiedXPathexpression;nullif the expression is not found - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned toint
-
getMandatoryInteger
public Integer getMandatoryInteger(String xpath)
Returns theIntegerobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted toint.If no value is found for the given expression, then an exception will be thrown.
- Specified by:
getMandatoryIntegerin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Integerobject from the evaluation result of the the specifiedXPathexpression; nevernull - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, not found, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned toint
-
getLong
public Long getLong(String xpath)
Returns theLongobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted tolong.- Specified by:
getLongin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Longobject from the evaluation result of the specifiedXPathexpression;nullif the expression is not found - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned tolong
-
getMandatoryLong
public Long getMandatoryLong(String xpath)
Returns theLongobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted tolong.If no value is found for the given expression, then an exception will be thrown.
- Specified by:
getMandatoryLongin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Longobject from the evaluation result of the the specifiedXPathexpression; nevernull - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, not found, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned tolong
-
getDouble
public Double getDouble(String xpath)
Returns theDoubleobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted todouble.- Specified by:
getDoublein interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Doubleobject from the evaluation result of the specifiedXPathexpression;nullif the expression is not found - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned todouble
-
getMandatoryDouble
public Double getMandatoryDouble(String xpath)
Returns theDoubleobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element that can be converted todouble.If no value is found for the given expression, then an exception will be thrown.
- Specified by:
getMandatoryDoublein interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Doubleobject from the evaluation result of the the specifiedXPathexpression; nevernull - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, not found, or it evaluates to more than a single elementNumberFormatException- if theXPathresult cannot be assigned todouble
-
getString
public String getString(String xpath)
Returns theStringobject associated with the specifiedXPathexpression in the XML document in context, provided that the expression returns a single element.- Specified by:
getStringin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Stringvalue associated with the specifiedXPathexpression;nullif the expression is not found - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression is either invalid, or it evaluates to more than a single element
-
getMandatoryString
public String getMandatoryString(String xpath)
Returns theStringobject associated with the specifiedXPathexpression 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:
getMandatoryStringin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to evaluate- Returns:
- the
Stringvalue associated with the specifiedXPathexpression; nevernull - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression 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 theNodeListobject associated with the specified @{code XPath} in the XML document in context.- Specified by:
getin interfaceConfigurationDataRetriever<Document>- Parameters:
xpath- theXPathexpression to read- Returns:
- the
NodeListobject associated with the specifiedXPath - Throws:
NullPointerException- if theXPathexpression is nullConfigurationException- if theXPathexpression 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
XPathExpressionobject that can be used for further evaluation - Throws:
XPathExpressionException- if the expression cannot be compiled
-
configurationMerger
public ConfigurationMerger<Document> configurationMerger()
Description copied from interface:ConfigurationHelperCreates the applicableConfigurationMergerobject for the type associated with thisConfigurationHelper.- Specified by:
configurationMergerin interfaceConfigurationHelper<Document>- Returns:
- a new
ConfigurationMergerinstance
-
-