Example usage for org.apache.commons.jxpath Pointer getClass

List of usage examples for org.apache.commons.jxpath Pointer getClass

Introduction

In this page you can find the example usage for org.apache.commons.jxpath Pointer getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.sf.oval.ogn.ObjectGraphNavigatorJXPathImpl.java

public ObjectGraphNavigationResult navigateTo(final Object root, final String xpath)
        throws InvalidConfigurationException {
    Assert.argumentNotNull("root", root);
    Assert.argumentNotNull("xpath", xpath);

    try {//from www. j  a va 2 s  .  co  m
        final JXPathContext ctx = JXPathContext.newContext(root);
        ctx.setLenient(true); // do not throw an exception if object graph is incomplete, e.g. contains null-values

        Pointer pointer = ctx.getPointer(xpath);

        // no match found or invalid xpath
        if (pointer instanceof NullPropertyPointer || pointer instanceof NullPointer)
            return null;

        if (pointer instanceof BeanPointer) {
            final Pointer parent = ((BeanPointer) pointer).getImmediateParentPointer();
            if (parent instanceof PropertyPointer) {
                pointer = parent;
            }
        }

        if (pointer instanceof PropertyPointer) {
            final PropertyPointer pp = (PropertyPointer) pointer;
            final Class<?> beanClass = pp.getBean().getClass();
            AccessibleObject accessor = ReflectionUtils.getField(beanClass, pp.getPropertyName());
            if (accessor == null) {
                accessor = ReflectionUtils.getGetter(beanClass, pp.getPropertyName());
            }
            return new ObjectGraphNavigationResult(root, xpath, pp.getBean(), accessor, pointer.getValue());
        }

        throw new InvalidConfigurationException("Don't know how to handle pointer [" + pointer + "] of type ["
                + pointer.getClass().getName() + "] for xpath [" + xpath + "]");
    } catch (final JXPathNotFoundException ex) {
        // thrown if the xpath is invalid
        throw new InvalidConfigurationException(ex);
    }
}