
com.avides.xpath.utils.processors.XPathFirstProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xpath-utils Show documentation
Show all versions of xpath-utils Show documentation
Provides some utility-methods to simplify the use of XPath
The newest version!
package com.avides.xpath.utils.processors;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.function.Function;
import com.avides.xpath.utils.XPathUtils;
import com.avides.xpath.utils.annotations.XPathFirst;
import nu.xom.Element;
/**
* @author Martin Schumacher
* @since 1.0.3.RELEASE
*/
public class XPathFirstProcessor extends AbstractAnnotationProcessor
{
public XPathFirstProcessor(Element root, Field field, Object target, Map, Function> defaultToTypeConverters)
{
super(root, field, target, defaultToTypeConverters);
}
public void process()
{
XPathFirst xPathFirst = field.getAnnotation(XPathFirst.class);
if (xPathFirst != null)
{
if (xPathFirst.isSubType())
{
Element subRoot = XPathUtils.queryFirstElement(root, xPathFirst.value());
Object value = subRoot != null ? XPathUtils.fromRoot(subRoot, field.getType()) : null;
setFieldValueSimple(field, target, value, true);
}
else
{
@SuppressWarnings("unchecked") Object value = XPathUtils.queryFirst(root, xPathFirst.value(),
(Class extends Function>) xPathFirst.converterClass());
setFieldValueExtended(field, target, value);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy