org.apache.commons.jxpath.ri.model.beans.NullPointer Java Examples

The following examples show how to use org.apache.commons.jxpath.ri.model.beans.NullPointer. 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: VariablePointer.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
public NodePointer getImmediateValuePointer() {
    if (valuePointer == null) {
        Object value;
        if (actual) {
            value = getImmediateNode();
            valuePointer =
                NodePointer.newChildNodePointer(this, null, value);
        }
        else {
            return new NullPointer(this, getName()) {
                public Object getImmediateNode() {
                    throw new JXPathException(
                        "Undefined variable: " + name);
                }
            };
        }
    }
    return valuePointer;
}
 
Example #2
Source File: DynamicPointerFactory.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
public NodePointer createNodePointer(
    NodePointer parent,
    QName name,
    Object bean) {
    if (bean == null) {
        return new NullPointer(parent, name);
    }

    JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
    if (bi.isDynamic()) {
        DynamicPropertyHandler handler =
            ValueUtils.getDynamicPropertyHandler(
                bi.getDynamicPropertyHandlerClass());
        return new DynamicPointer(parent, name, bean, handler);
    }
    return null;
}
 
Example #3
Source File: SimplePathInterpreterTest.java    From commons-jxpath with Apache License 2.0 6 votes vote down vote up
/**
 * Since we need to test the internal Signature of a pointer,
 * we will get a signature which will contain a single character
 * per pointer in the chain, representing that pointer's type.
 */
private String pointerSignature(Pointer pointer) {
    if (pointer == null) {
        return "";
    }

    char type = '?';
    if (pointer instanceof NullPointer) {                 type = 'N'; }
    else if (pointer instanceof NullPropertyPointer) {    type = 'n'; }
    else if (pointer instanceof NullElementPointer) {     type = 'E'; }
    else if (pointer instanceof VariablePointer) {        type = 'V'; }
    else if (pointer instanceof CollectionPointer) {      type = 'C'; }
    else if (pointer instanceof BeanPointer) {            type = 'B'; }
    else if (pointer instanceof BeanPropertyPointer) {    type = 'b'; }
    else if (pointer instanceof DynamicPointer) {         type = 'D'; }
    else if (pointer instanceof DynamicPropertyPointer) { type = 'd'; }
    else if (pointer instanceof DOMNodePointer) {         type = 'M'; }
    else {
        System.err.println("UNKNOWN TYPE: " + pointer.getClass());
    }
    NodePointer parent = 
        ((NodePointer) pointer).getImmediateParentPointer();
    return pointerSignature(parent) + type;
}
 
Example #4
Source File: ObjectGraphNavigatorJXPathImpl.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public NodePointer createNodePointer(final NodePointer parent, final QName name, final Object bean) {
   if (bean == null)
      return new NullPointer(parent, name);

   final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
   return new BeanPointerEx(parent, name, bean, bi);
}
 
Example #5
Source File: ObjectGraphNavigatorJXPathImpl.java    From oval with Eclipse Public License 2.0 5 votes vote down vote up
@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 #6
Source File: PathExistsMessageFilter.java    From suro with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(Object input) {
    JXPathContext jxpath = JXPathContext.newContext(input);
    // We should allow non-existing path, and let predicate handle it.
    jxpath.setLenient(true);

    Pointer pointer = jxpath.getPointer(xpath);
   
    return pointer != null && !(pointer instanceof NullPointer) && pointer.getValue() != null;
}
 
Example #7
Source File: DOMNodePointer.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
/**
 * Locates a node by ID.
 * @param context starting context
 * @param id to find
 * @return Pointer
 */
public Pointer getPointerByID(JXPathContext context, String id) {
    Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node
            : node.getOwnerDocument();
    Element element = document.getElementById(id);
    return element == null ? (Pointer) new NullPointer(getLocale(), id)
            : new DOMNodePointer(element, getLocale(), id);
}