public String asPath() { if (id != null) { return "id(" + id + ")"; } return parent == null ? "null()" : super.asPath(); }
public NodeIterator childIterator(NodeTest test, boolean reverse, NodePointer startWith) { if (test == null) { return createNodeIterator(null, reverse, startWith); } if (test instanceof NodeNameTest) { NodeNameTest nodeNameTest = (NodeNameTest) test; QName testName = nodeNameTest.getNodeName(); if (isValidProperty(testName)) { return createNodeIterator(nodeNameTest.isWildcard() ? null : testName.toString(), reverse, startWith); } return null; } return test instanceof NodeTypeTest && ((NodeTypeTest) test).getNodeType() == Compiler.NODE_TYPE_NODE ? createNodeIterator(null, reverse, startWith) : null; }
public Object getImmediateNode() { if (value == UNINITIALIZED) { value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue()) : ValueUtils.getValue(getBaseValue(), index); } return value; }
public void setValue(Object value) { if (parent == null || parent.isContainer()) { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", the target object is null"); } if (parent instanceof PropertyOwnerPointer && ((PropertyOwnerPointer) parent) .isDynamicPropertyDeclarationSupported()) { // If the parent property owner can create // a property automatically - let it do so PropertyPointer propertyPointer = ((PropertyOwnerPointer) parent).getPropertyPointer(); propertyPointer.setPropertyName(propertyName); propertyPointer.setValue(value); } else { throw new JXPathInvalidAccessException( "Cannot set property " + asPath() + ", path does not match a changeable location"); } }
/** * Create the child pointer for a given step. * @param parentPointer parent pointer * @param step associated step * @return NodePointer */ private static NodePointer createChildPointerForStep( PropertyOwnerPointer parentPointer, Step step) { int axis = step.getAxis(); if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) { QName name = ((NodeNameTest) step.getNodeTest()).getNodeName(); if (axis == Compiler.AXIS_ATTRIBUTE && isLangAttribute(name)) { return new LangAttributePointer(parentPointer); } if (parentPointer.isValidProperty(name)) { NodePointer childPointer = parentPointer.getPropertyPointer(); ((PropertyPointer) childPointer).setPropertyName( name.toString()); childPointer.setAttribute(axis == Compiler.AXIS_ATTRIBUTE); return childPointer; } //invalid property gets nothing, not even a NullPointer return null; } return parentPointer; }
/** * Used for an optimized access to dynamic properties using the * "map[@name = 'name']" syntax * @return whether valid */ private boolean setupDynamicPropertyPointer() { if (nameTestExpression == null) { return false; } NodePointer parent = parentContext.getCurrentNodePointer(); if (parent == null) { return false; } parent = parent.getValuePointer(); if (!(parent instanceof PropertyOwnerPointer)) { return false; } dynamicPropertyPointer = (PropertyPointer) ((PropertyOwnerPointer) parent) .getPropertyPointer() .clone(); return true; }
/** * Learn whether <code>name</code> is a valid child name for this PropertyOwnerPointer. * @param name the QName to test * @return <code>true</code> if <code>QName</code> is a valid property name. * @since JXPath 1.3 */ public boolean isValidProperty(QName name) { return isDefaultNamespace(name.getPrefix()); }
public NodePointer createPath(JXPathContext context, Object value) { NodePointer newParent = parent.createPath(context); if (isAttribute()) { NodePointer pointer = newParent.createAttribute(context, getName()); pointer.setValue(value); return pointer; } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), index, value); }
public NodePointer createPath(JXPathContext context) { NodePointer newParent = parent.createPath(context); if (isAttribute()) { return newParent.createAttribute(context, getName()); } if (parent instanceof NullPointer && parent.equals(newParent)) { throw createBadFactoryException(context.getFactory()); } // Consider these two use cases: // 1. The parent pointer of NullPropertyPointer is // a PropertyOwnerPointer other than NullPointer. When we call // createPath on it, it most likely returns itself. We then // take a PropertyPointer from it and get the PropertyPointer // to expand the collection for the corresponding property. // // 2. The parent pointer of NullPropertyPointer is a NullPointer. // When we call createPath, it may return a PropertyOwnerPointer // or it may return anything else, like a DOMNodePointer. // In the former case we need to do exactly what we did in use // case 1. In the latter case, we simply request that the // non-property pointer expand the collection by itself. if (newParent instanceof PropertyOwnerPointer) { PropertyOwnerPointer pop = (PropertyOwnerPointer) newParent; newParent = pop.getPropertyPointer(); } return newParent.createChild(context, getName(), getIndex()); }
public String asPath() { return parent == null ? "/" : super.asPath(); }
NodePointer startWith) { propertyNodePointer = (PropertyPointer) pointer.getPropertyPointer().clone(); this.name = name; this.reverse = reverse;
public String asPath() { return parent == null ? "/" : super.asPath(); }
if (child instanceof PropertyOwnerPointer) { PropertyPointer pointer = ((PropertyOwnerPointer) child).getPropertyPointer(); pointer.setPropertyName(key); if (pointer.isActual()) {
/** * {@inheritDoc} * If the pointer has a parent, then parent's path. * If the bean is null, "null()". * If the bean is a primitive value, the value itself. * Otherwise - an empty string. */ public String asPath() { if (parent != null) { return super.asPath(); } if (bean == null) { return "null()"; } if (bean instanceof Number) { String string = bean.toString(); if (string.endsWith(".0")) { string = string.substring(0, string.length() - 2); } return string; } if (bean instanceof Boolean) { return ((Boolean) bean).booleanValue() ? "true()" : "false()"; } if (bean instanceof String) { return "'" + bean + "'"; } return "/"; } }