List of usage examples for org.apache.commons.jxpath JXPathException JXPathException
public JXPathException(String msg, Throwable e)
JXPathException
with the given Exception
base cause and detail message. From source file:org.eclipse.e4.emf.internal.xpath.helper.ValueUtils.java
@SuppressWarnings("unchecked") public static Object getValue(EObject bean, EStructuralFeature pd, int index) { if (pd.isMany()) { try {//from ww w . j a v a 2 s . co m return ((List<Object>) bean.eGet(pd)).get(index); } catch (IndexOutOfBoundsException ex) { return null; } catch (Throwable ex) { throw new JXPathException("Cannot access property: " + pd.getName(), ex); } } // We will fall through if there is no indexed read return getValue(getValue(bean, pd), index); }
From source file:org.eclipse.e4.emf.internal.xpath.helper.ValueUtils.java
@SuppressWarnings("unchecked") public static void setValue(EObject bean, EStructuralFeature pd, Object value) { try {/*from ww w . j av a 2s.c o m*/ if (pd.isMany()) { List<Object> l = (List<Object>) bean.eGet(pd); l.clear(); l.addAll((Collection<Object>) value); } else { bean.eSet(pd, value); } } catch (Exception ex) { throw new JXPathException("Cannot modify property: " + (bean == null ? "null" : bean.getClass().getName()) + "." + pd.getName(), ex); } }
From source file:org.eclipse.e4.emf.internal.xpath.helper.ValueUtils.java
private static Object convert(Object value, Class<?> type) { try {/*from www .j a v a 2 s .co m*/ return TypeUtils.convert(value, type); } catch (Exception ex) { throw new JXPathException("Cannot convert value of class " + (value == null ? "null" : value.getClass().getName()) + " to type " + type, ex); } }
From source file:org.xchain.framework.jxpath.GenericsWisePackageFunctions.java
public Function getFunction(String namespace, String name, Object[] parameters) { if ((namespace == null && this.namespace != null) //NOPMD || (namespace != null && !namespace.equals(this.namespace))) { return null; }//from w w w.j a v a 2 s.c o m if (parameters == null) { parameters = EMPTY_ARRAY; } if (parameters.length >= 1) { Object target = TypeUtils.convert(parameters[0], Object.class); if (target != null) { Method method = MethodLookupUtils.lookupMethod(target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof NodeSet) { target = ((NodeSet) target).getPointers(); } method = MethodLookupUtils.lookupMethod(target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } if (target instanceof Collection) { Iterator iter = ((Collection) target).iterator(); if (iter.hasNext()) { target = iter.next(); if (target instanceof Pointer) { target = ((Pointer) target).getValue(); } } else { target = null; } } } if (target != null) { Method method = MethodLookupUtils.lookupMethod(target.getClass(), name, parameters); if (method != null) { return new MethodFunction(method); } } } String fullName = classPrefix + name; int inx = fullName.lastIndexOf('.'); if (inx == -1) { return null; } String className = fullName.substring(0, inx); String methodName = fullName.substring(inx + 1); Class functionClass; try { functionClass = Class.forName(className, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException ex) { throw new JXPathException( "Cannot invoke extension function " + (namespace != null ? namespace + ":" + name : name), ex); } if (methodName.equals("new")) { Constructor constructor = MethodLookupUtils.lookupConstructor(functionClass, parameters); if (constructor != null) { return new ConstructorFunction(constructor); } } else { Method method = MethodLookupUtils.lookupStaticMethod(functionClass, methodName, parameters); if (method != null) { return new MethodFunction(method); } } return null; }