List of usage examples for org.apache.commons.jxpath JXPathException JXPathException
public JXPathException(Throwable e)
JXPathException
with a given Throwable
base cause of the error. From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
private String getMandatoryData(JXPathContext ctx, String ctxFieldName) { String value = (String) ctx.getValue(ctxFieldName); if (value != null && value.length() == 0) { throw new JXPathException( "Mandatory field " + ctxFieldName + " not provided, uncompliant UPNP device !!"); }/*from w w w .ja va2 s .com*/ return value; }
From source file:org.apache.camel.language.jxpath.JXPathExpression.java
private void assertResultType(Exchange exchange, Object result) { if (result != null && !type.isAssignableFrom(result.getClass())) { throw new JXPathException( "JXPath result type is " + result.getClass() + " instead of required type " + type); }//w w w . j a v a 2 s .c o m }
From source file:org.chiba.xml.xforms.connector.context.ContextResolver.java
/** * Performs a lookup in Chiba's context map and returns the object denoted * by the scheme specific part of the resolver's URI. * * @return the object denoted by the scheme specific part of the * resolver's URI.// w ww.j av a 2 s. c o m * @throws XFormsException if any error occurred during link traversal. */ public Object resolve() throws XFormsException { try { String xpath = new URI(getURI()).getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("resolve: " + xpath); } JXPathContext contextContext = JXPathContext.newContext(getContext()); Pointer pointer = contextContext.getPointer(xpath); if (pointer.getValue() == null) { throw new JXPathException("No pointer for xpath: " + xpath); } return pointer.getNode(); } catch (Exception e) { throw new XFormsException(e); } }
From source file:org.eclipse.e4.emf.internal.xpath.CollectionNodeIterator.java
/** * Prepare...//from w w w . j av a2 s. com */ private void prepare() { collection = new ArrayList<>(); NodePointer ptr = (NodePointer) pointer.clone(); int length = ptr.getLength(); for (int i = 0; i < length; i++) { ptr.setIndex(i); NodePointer elementPointer = ptr.getValuePointer(); NodeIterator iter = getElementNodeIterator(elementPointer); for (int j = 1; iter.setPosition(j); j++) { NodePointer childPointer = iter.getNodePointer(); if (reverse) { collection.add(0, childPointer); } else { collection.add(childPointer); } } } if (startWith != null) { int index = collection.indexOf(startWith); if (index == -1) { throw new JXPathException("Invalid starting pointer for iterator: " + startWith); } while (collection.size() > index) { if (!reverse) { collection.remove(collection.size() - 1); } else { collection.remove(0); } } } }
From source file:org.eclipse.e4.emf.internal.xpath.EStructuralFeatureIterator.java
/** * Create a new PropertyIterator./*from ww w . j a va2 s .c om*/ * @param pointer owning pointer * @param name property name * @param reverse iteration order * @param startWith beginning pointer */ public EStructuralFeatureIterator(EStructuralFeatureOwnerPointer pointer, String name, boolean reverse, NodePointer startWith) { propertyNodePointer = (EStructuralFeaturePointer) pointer.getPropertyPointer().clone(); this.name = name; this.reverse = reverse; this.includeStart = true; if (reverse) { this.startPropertyIndex = EStructuralFeaturePointer.UNSPECIFIED_PROPERTY; this.startIndex = -1; } if (startWith != null) { while (startWith != null && startWith.getImmediateParentPointer() != pointer) { startWith = startWith.getImmediateParentPointer(); } if (startWith == null) { throw new JXPathException( "PropertyIerator startWith parameter is " + "not a child of the supplied parent"); } this.startPropertyIndex = ((EStructuralFeaturePointer) startWith).getPropertyIndex(); this.startIndex = startWith.getIndex(); if (this.startIndex == NodePointer.WHOLE_COLLECTION) { this.startIndex = 0; } this.includeStart = false; if (reverse && startIndex == -1) { this.includeStart = true; } } }
From source file:org.eclipse.e4.emf.internal.xpath.helper.ValueUtils.java
/** * Remove the index'th element from the supplied collection. * @param collection to edit// ww w .jav a2 s . co m * @param index int * @return the resulting collection */ public static Object remove(Object collection, int index) { collection = getValue(collection); if (collection == null) { return null; } if (index >= getLength(collection)) { throw new JXPathException("No such element at index " + index); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); Object smaller = Array.newInstance(collection.getClass().getComponentType(), length - 1); if (index > 0) { System.arraycopy(collection, 0, smaller, 0, index); } if (index < length - 1) { System.arraycopy(collection, index + 1, smaller, index, length - index - 1); } return smaller; } if (collection instanceof List) { int size = ((List<?>) collection).size(); if (index < size) { ((List<?>) collection).remove(index); } return collection; } if (collection instanceof Collection) { Iterator<?> it = ((Collection<?>) collection).iterator(); for (int i = 0; i < index; i++) { if (!it.hasNext()) { break; } it.next(); } if (it.hasNext()) { it.next(); it.remove(); } return collection; } throw new JXPathException("Cannot remove " + collection.getClass().getName() + "[" + index + "]"); }
From source file:org.eclipse.e4.emf.internal.xpath.helper.ValueUtils.java
public static Object expandCollection(Object collection, int size) { if (collection == null) { return null; }//from ww w . j a v a 2 s . c o m if (size < getLength(collection)) { throw new JXPathException("adjustment of " + collection + " to size " + size + " is not an expansion"); } if (collection.getClass().isArray()) { Object bigger = Array.newInstance(collection.getClass().getComponentType(), size); System.arraycopy(collection, 0, bigger, 0, Array.getLength(collection)); return bigger; } if (collection instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> c = (Collection<Object>) collection; while (c.size() < size) { c.add(null); } return collection; } throw new JXPathException( "Cannot turn " + collection.getClass().getName() + " into a collection of size " + size); }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
/** * ??nameattribute//from w w w .j a v a 2s .c o m */ public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String nsUri = null; NamespaceResolver nsr = getNamespaceResolver(); if (nsr != null) { nsUri = nsr.getNamespaceURI(prefix); } if (nsUri == null) { throw new JXPathException("Unknown namespace prefix: " + prefix); } Namespace dom4jNs = Namespace.get(prefix, nsUri); org.dom4j.QName attributeName = new org.dom4j.QName(name.getName(), dom4jNs); Attribute attr = element.attribute(attributeName); if (attr == null) { element.addAttribute(attributeName, ""); } } else { Attribute attr = element.attribute(name.getName()); if (attr == null) { element.addAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
public void remove() { Element parent = nodeParent(node); if (parent == null) { throw new JXPathException("Cannot remove root Dom4J node"); }//from w w w. ja v a 2s . c o m parent.remove(node); }
From source file:org.openvpms.component.system.common.jxpath.OpenVPMSCoreFunction.java
@Override protected Object functionSum(EvalContext context) { Object v = getArg1().compute(context); if (v == null) { return ZERO; } else if (v instanceof EvalContext) { BigDecimal sum = new BigDecimal(0.0); EvalContext ctx = (EvalContext) v; while (ctx.hasNext()) { NodePointer ptr = (NodePointer) ctx.next(); sum = sum.add(TypeConversionUtil.bigDecimalValue(ptr)); }/*from w ww . j a v a 2 s .c o m*/ return sum; } throw new JXPathException("Invalid argument type for 'sum': " + v.getClass().getName()); }