org.apache.commons.jxpath.JXPathNotFoundException Java Examples
The following examples show how to use
org.apache.commons.jxpath.JXPathNotFoundException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodePointer.java From commons-jxpath with Apache License 2.0 | 6 votes |
/** * Verify the structure of a given NodePointer. * @param nodePointer to check * @return nodePointer * @throws JXPathNotFoundException */ public static NodePointer verify(NodePointer nodePointer) { if (!nodePointer.isActual()) { // We need to differentiate between pointers representing // a non-existing property and ones representing a property // whose value is null. In the latter case, the pointer // is going to have isActual == false, but its parent, // which is a non-node pointer identifying the bean property, // will return isActual() == true. NodePointer parent = nodePointer.getImmediateParentPointer(); if (parent == null || !parent.isContainer() || !parent.isActual()) { throw new JXPathNotFoundException("No value for xpath: " + nodePointer); } } return nodePointer; }
Example #2
Source File: ObjectGraphNavigatorJXPathImpl.java From oval with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isValidProperty(final QName name) { if (!super.isValidProperty(name)) return false; // JXPath's default implementation returns true, even if the given property does not exit if (beanInfo.getPropertyDescriptor(name.getName()) == null) throw new JXPathNotFoundException("No pointer for xpath: " + toString() + "/" + name); return true; }
Example #3
Source File: ObjectGraphNavigatorJXPathImpl.java From oval with Eclipse Public License 2.0 | 5 votes |
@Override public ObjectGraphNavigationResult navigateTo(final Object root, final String xpath) throws InvalidConfigurationException { Assert.argumentNotNull("root", root); Assert.argumentNotNull("xpath", xpath); try { 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); } }
Example #4
Source File: JXPathContextReferenceImpl.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Get the value indicated. * @param xpath String * @param expr Expression * @return Object */ public Object getValue(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result == null) { if (expr instanceof Path && !isLenient()) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } return null; } if (result instanceof EvalContext) { EvalContext ctx = (EvalContext) result; result = ctx.getSingleNodePointer(); if (!isLenient() && result == null) { throw new JXPathNotFoundException("No value for xpath: " + xpath); } } if (result instanceof NodePointer) { result = ((NodePointer) result).getValuePointer(); if (!isLenient()) { NodePointer.verify((NodePointer) result); } result = ((NodePointer) result).getValue(); } return result; }
Example #5
Source File: JXPathContextReferenceImpl.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Get a pointer to the specified path/expression. * @param xpath String * @param expr compiled Expression * @return Pointer */ public Pointer getPointer(String xpath, Expression expr) { Object result = expr.computeValue(getEvalContext()); if (result instanceof EvalContext) { result = ((EvalContext) result).getSingleNodePointer(); } if (result instanceof Pointer) { if (!isLenient() && !((NodePointer) result).isActual()) { throw new JXPathNotFoundException("No pointer for xpath: " + xpath); } return (Pointer) result; } return NodePointer.newNodePointer(null, result, getLocale()); }
Example #6
Source File: LazyDynaBeanTest.java From commons-jxpath with Apache License 2.0 | 5 votes |
public void testStrictLazyDynaBeanPropertyFactory() { JXPathContextReferenceImpl.addNodePointerFactory(new StrictLazyDynaBeanPointerFactory()); try { testLazyProperty(); fail(); } catch (JXPathNotFoundException e) { //okay } }
Example #7
Source File: LazyDynaBeanTest.java From commons-jxpath with Apache License 2.0 | 4 votes |
public void testLazyProperty() throws JXPathNotFoundException { LazyDynaBean bean = new LazyDynaBean(); JXPathContext context = JXPathContext.newContext(bean); context.getValue("nosuch"); }