Java Code Examples for org.apache.commons.jxpath.JXPathContext#getPointer()

The following examples show how to use org.apache.commons.jxpath.JXPathContext#getPointer() . 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: MetaService.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private void remove(String path, JXPathContext context) throws SpagoBIException {
	if (path.matches(".*\\]$")) {
		int i = path.lastIndexOf("[");
		Pointer obj = context.getPointer(path);
		logger.debug("REMOVE > " + path + " > " + obj.getNode());
		Pointer coll = context.getPointer(path.substring(0, i));
		if (obj.getNode() instanceof SimpleBusinessColumnImpl) {
			((SimpleBusinessColumnImpl) obj.getNode()).setIdentifier(false);
		}
		if (obj.getNode() instanceof BusinessRelationshipImpl) {
			((BusinessRelationshipImpl) obj.getNode()).removeRelationship();
			return;
		}

		((List<?>) coll.getNode()).remove(obj.getNode());
	} else {
		// TODO
		// throw new SpagoBIException("TODO operation \"remove\" not supported for single element");
	}
}
 
Example 2
Source File: MetaService.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private void addValue(String obj, String topath, JXPathContext context) throws SpagoBIException {
	logger.debug("ADD > " + obj + " > " + topath);
	if (topath.endsWith("]")) {
		int i = topath.lastIndexOf("[");
		Pointer toColl = context.getPointer(topath.substring(0, i));
		if (toColl.getNode() instanceof List) {
			if (!((List) toColl.getNode()).contains(obj)) {
				((List) toColl.getNode()).add(obj);
			}
		}
	} else {
		replace(obj, topath, context);
	}
}
 
Example 3
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 4
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 5
Source File: JXPath177Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
private void doTest(String xp, String expected)
{
    JXPathContext xpathContext = JXPathContext.newContext(model);
    xpathContext.setVariables(new JXPathVariablesResolver(model));
    Pointer p = xpathContext.getPointer(xp);
    Object result = p.getNode();
    assertNotNull(result);
    assertEquals(expected, result);

}
 
Example 6
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNotNull()
{
    final JXPathContext context = getContext("ciao", false);
    final Object bRet = context.selectSingleNode("value");
    assertNotNull("null!!", bRet);
    assertEquals("Is " + bRet.getClass(), "ciao", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertEquals("ciao", pointer.getValue());
}
 
Example 7
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNull()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 8
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyDoesNotExist()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 9
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyDoesNotExist_Lenient()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 10
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_nestedpropertyDoesNotExist_Lenient()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("value.unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("value.unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 11
Source File: JXPath172DynamicTest.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_nestedpropertyDoesNotExist_NotLenient()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value.unexisting");
    assertNull(bRet);

    final Pointer pointer = context.getPointer("value.unexisting");
    assertEquals(DynamicPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());

}
 
Example 12
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNotNull()
{
    final JXPathContext context = getContext("ciao", false);
    final Object bRet = context.selectSingleNode("value");
    assertNotNull("null!!", bRet);
    assertEquals("Is " + bRet.getClass(), "ciao", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(BeanPropertyPointer.class, pointer.getClass());
    assertEquals("ciao", pointer.getValue());
}
 
Example 13
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_propertyExistAndIsNull()
{
    final JXPathContext context = getContext(null, false);
    final Object bRet = context.selectSingleNode("value");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value");
    assertNotNull(pointer);
    assertEquals(BeanPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 14
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_PropertyUnexisting()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("unexisting");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("unexisting");
    assertNotNull(pointer);
    assertEquals(NullPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}
 
Example 15
Source File: JXPath172Test.java    From commons-jxpath with Apache License 2.0 5 votes vote down vote up
public void testIssue172_NestedPropertyUnexisting()
{
    final JXPathContext context = getContext(null, true);
    final Object bRet = context.selectSingleNode("value.child");
    assertNull("not null!!", bRet);

    final Pointer pointer = context.getPointer("value.child");
    assertNotNull(pointer);
    assertEquals(NullPropertyPointer.class, pointer.getClass());
    assertNull(pointer.getValue());
}