org.apache.commons.jxpath.ri.QName Java Examples
The following examples show how to use
org.apache.commons.jxpath.ri.QName.
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: NodePointer.java From commons-jxpath with Apache License 2.0 | 6 votes |
/** * Allocates an new child NodePointer by iterating through all installed * NodePointerFactories until it finds one that can create a pointer. * @param parent pointer * @param name QName * @param bean Object * @return NodePointer */ public static NodePointer newChildNodePointer( NodePointer parent, QName name, Object bean) { NodePointerFactory[] factories = JXPathContextReferenceImpl.getNodePointerFactories(); for (int i = 0; i < factories.length; i++) { NodePointer pointer = factories[i].createNodePointer(parent, name, bean); if (pointer != null) { return pointer; } } throw new JXPathException( "Could not allocate a NodePointer for object of " + bean.getClass()); }
Example #2
Source File: PropertyOwnerPointer.java From commons-jxpath with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: VariablePointerFactory.java From commons-jxpath with Apache License 2.0 | 6 votes |
public NodePointer createNodePointer(QName name, Object object, Locale locale) { if (object instanceof VariableContextWrapper) { JXPathContext varCtx = ((VariableContextWrapper) object).getContext(); while (varCtx != null) { Variables vars = varCtx.getVariables(); if (vars.isDeclaredVariable(name.toString())) { return new VariablePointer(vars, name); } varCtx = varCtx.getParentContext(); } // The variable is not declared, but we will create // a pointer anyway in case the user wants to set, rather // than get, the value of the variable. return new VariablePointer(name); } return null; }
Example #4
Source File: TestConfigurationIteratorAttributes.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests to iterate over all attributes. */ @Test public void testIterateAllAttributes() { final ConfigurationNodeIteratorAttribute<ImmutableNode> it = new ConfigurationNodeIteratorAttribute<>(pointer, new QName(null, "*")); assertEquals("Wrong number of attributes", 3, iteratorSize(it)); final List<NodePointer> attrs = iterationElements(it); final Set<String> attrNames = new HashSet<>(); for (final NodePointer np : attrs) { attrNames.add(np.getName().getName()); } assertTrue("First attribute not found", attrNames.contains(ATTR_NAME)); assertTrue("Second attribute not found", attrNames.contains(TEST_ATTR)); assertTrue("Namespace attribute not found", attrNames.contains(NS_ATTR)); }
Example #5
Source File: SimplePathInterpreter.java From commons-jxpath with Apache License 2.0 | 6 votes |
/** * Get a NodeIterator. * @param context evaluation context * @param pointer owning pointer * @param step triggering step * @return NodeIterator */ private static NodeIterator getNodeIterator( EvalContext context, NodePointer pointer, Step step) { if (step.getAxis() == Compiler.AXIS_CHILD) { NodeTest nodeTest = step.getNodeTest(); QName qname = ((NodeNameTest) nodeTest).getNodeName(); String prefix = qname.getPrefix(); if (prefix != null) { String namespaceURI = context.getJXPathContext() .getNamespaceURI(prefix); nodeTest = new NodeNameTest(qname, namespaceURI); } return pointer.childIterator(nodeTest, false, null); } // else Compiler.AXIS_ATTRIBUTE if (!(step.getNodeTest() instanceof NodeNameTest)) { throw new UnsupportedOperationException( "Not supported node test for attributes: " + step.getNodeTest()); } return pointer.attributeIterator( ((NodeNameTest) step.getNodeTest()).getNodeName()); }
Example #6
Source File: ConfigurationNodePointerFactory.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Creates a node pointer for the specified bean. If the bean is a * configuration node, a corresponding pointer is returned. * * @param parent the parent node * @param name the name * @param bean the bean * @return a pointer for a configuration node if the bean is such a node */ @Override @SuppressWarnings("unchecked") /* Type casts are safe here, see above. Also, the hierarchy of node pointers is consistent, so a parent is compatible to a child. */ public NodePointer createNodePointer(final NodePointer parent, final QName name, final Object bean) { if (bean instanceof NodeWrapper) { final NodeWrapper<?> wrapper = (NodeWrapper<?>) bean; return new ConfigurationNodePointer((ConfigurationNodePointer) parent, wrapper.getNode(), wrapper.getNodeHandler()); } return null; }
Example #7
Source File: ConfigurationNodeIteratorChildren.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Obtains the list of selected sub nodes for a {@code NodeNameTest} with a * wildcard name. * * @param node the current node * @param name the name to be selected * @return the list with selected sub nodes */ private List<T> createSubNodeListForWildcardName(final T node, final QName name) { final List<T> children = getNodeHandler().getChildren(node); if (name.getPrefix() == null) { return children; } final List<T> prefixChildren = new ArrayList<>(children.size()); final String prefix = prefixName(name.getPrefix(), null); for (final T child : children) { if (StringUtils.startsWith(getNodeHandler().nodeName(child), prefix)) { prefixChildren.add(child); } } return prefixChildren; }
Example #8
Source File: VariablePointer.java From commons-jxpath with Apache License 2.0 | 6 votes |
public NodePointer createChild( JXPathContext context, QName name, int index) { Object collection = createCollection(context, index); if (!isActual() || (index != 0 && index != WHOLE_COLLECTION)) { AbstractFactory factory = getAbstractFactory(context); boolean success = factory.createObject( context, this, collection, getName().toString(), index); if (!success) { throw new JXPathAbstractFactoryException( "Factory could not create object path: " + asPath()); } NodePointer cln = (NodePointer) clone(); cln.setIndex(index); return cln; } return this; }
Example #9
Source File: BeanAttributeIterator.java From commons-jxpath with Apache License 2.0 | 6 votes |
/** * Create a new BeanAttributeIterator. * @param parent parent pointer * @param name name of this bean */ public BeanAttributeIterator(PropertyOwnerPointer parent, QName name) { super( parent, (name.getPrefix() == null && (name.getName() == null || name.getName().equals("*"))) ? null : name.toString(), false, null); this.parent = parent; includeXmlLang = (name.getPrefix() != null && name.getPrefix().equals("xml")) && (name.getName().equals("lang") || name.getName().equals("*")); }
Example #10
Source File: DynamicPointerFactory.java From commons-jxpath with Apache License 2.0 | 6 votes |
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 #11
Source File: NullPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { return createPath(context).createChild(context, name, index, value); }
Example #12
Source File: CollectionPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createChild( JXPathContext context, QName name, int index, Object value) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context, value); }
Example #13
Source File: ConfigurationNodeIteratorAttribute.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Creates a new instance of {@code ConfigurationNodeIteratorAttribute}. * @param parent the parent node pointer * @param name the name of the selected attribute */ public ConfigurationNodeIteratorAttribute( final ConfigurationNodePointer<T> parent, final QName name) { super(parent, false); parentPointer = parent; attributeNames = createAttributeDataList(parent, name); }
Example #14
Source File: JDOMPointerFactory.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createNodePointer( QName name, Object bean, Locale locale) { if (bean instanceof Document) { return new JDOMNodePointer(bean, locale); } if (bean instanceof Element) { return new JDOMNodePointer(bean, locale); } return null; }
Example #15
Source File: ConfigurationNodeIteratorChildren.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Creates the list with sub nodes. This method gets called during * initialization phase. It finds out, based on the given test, which nodes * must be iterated over. * * @param node the current node * @param test the test object * @return a list with the matching nodes */ private List<T> createSubNodeList(final T node, final NodeTest test) { if (test == null) { return getNodeHandler().getChildren(node); } if (test instanceof NodeNameTest) { final NodeNameTest nameTest = (NodeNameTest) test; final QName name = nameTest.getNodeName(); return nameTest.isWildcard() ? createSubNodeListForWildcardName( node, name) : createSubNodeListForName(node, name); } else if (test instanceof NodeTypeTest) { final NodeTypeTest typeTest = (NodeTypeTest) test; if (typeTest.getNodeType() == Compiler.NODE_TYPE_NODE || typeTest.getNodeType() == Compiler.NODE_TYPE_TEXT) { return getNodeHandler().getChildren(node); } } return Collections.emptyList(); }
Example #16
Source File: AttributeContext.java From commons-jxpath with Apache License 2.0 | 5 votes |
public boolean nextNode() { super.setPosition(getCurrentPosition() + 1); if (!setStarted) { setStarted = true; QName name; if (nodeTest instanceof NodeNameTest) { name = ((NodeNameTest) nodeTest).getNodeName(); } else { if (nodeTest instanceof NodeTypeTest && ((NodeTypeTest) nodeTest).getNodeType() == Compiler.NODE_TYPE_NODE) { name = WILDCARD; } else { iterator = null; return false; } } iterator = parentContext.getCurrentNodePointer().attributeIterator( name); } if (iterator == null) { return false; } if (!iterator.setPosition(iterator.getPosition() + 1)) { return false; } currentNodePointer = iterator.getNodePointer(); return true; }
Example #17
Source File: CollectionPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createChild( JXPathContext context, QName name, int index) { NodePointer ptr = (NodePointer) clone(); ptr.setIndex(index); return ptr.createPath(context); }
Example #18
Source File: TestConfigurationIteratorAttributes.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests to iterate over non existing attributes. */ @Test public void testIterateUnknownAttribute() { final ConfigurationNodeIteratorAttribute<ImmutableNode> it = new ConfigurationNodeIteratorAttribute<>(pointer, new QName(null, "unknown")); assertEquals("Found attributes", 0, iteratorSize(it)); }
Example #19
Source File: TestConfigurationIteratorAttributes.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests iteration if an unknown namespace is specified. */ @Test public void testIterateNamespaceUnknown() { final ConfigurationNodeIteratorAttribute<ImmutableNode> it = new ConfigurationNodeIteratorAttribute<>(pointer, new QName("test", "*")); assertEquals("Found attributes", 0, iteratorSize(it)); }
Example #20
Source File: BeanPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Create a new BeanPointer. * @param name is the name given to the first node * @param bean pointed * @param beanInfo JXPathBeanInfo * @param locale Locale */ public BeanPointer(QName name, Object bean, JXPathBeanInfo beanInfo, Locale locale) { super(null, locale); this.name = name; this.bean = bean; this.beanInfo = beanInfo; }
Example #21
Source File: DOMNodePointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
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 ns = null; NamespaceResolver nsr = getNamespaceResolver(); if (nsr != null) { ns = nsr.getNamespaceURI(prefix); } if (ns == null) { throw new JXPathException( "Unknown namespace prefix: " + prefix); } element.setAttributeNS(ns, name.toString(), ""); } else { if (!element.hasAttribute(name.getName())) { element.setAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); }
Example #22
Source File: JDOMPointerFactory.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createNodePointer( NodePointer parent, QName name, Object bean) { if (bean instanceof Document) { return new JDOMNodePointer(parent, bean); } if (bean instanceof Element) { return new JDOMNodePointer(parent, bean); } return null; }
Example #23
Source File: TestConfigurationNodeIteratorChildren.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests using a node test with a wildcard name. */ @Test public void testIterateWithWildcardTest() { final NodeNameTest test = new NodeNameTest(new QName(null, "*")); final ConfigurationNodeIteratorChildren<ImmutableNode> it = new ConfigurationNodeIteratorChildren<>( rootPointer, test, false, null); assertEquals("Wrong number of elements", CHILD_COUNT, iteratorSize(it)); }
Example #24
Source File: TestConfigurationNodeIteratorChildren.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests using a node test that selects a certain sub node name. */ @Test public void testIterateWithNameTest() { final NodeNameTest test = new NodeNameTest(new QName(null, CHILD_NAME2)); final ConfigurationNodeIteratorChildren<ImmutableNode> it = new ConfigurationNodeIteratorChildren<>( rootPointer, test, false, null); assertTrue("No children found", iteratorSize(it) > 0); for (final NodePointer nd : iterationElements(it)) { assertEquals("Wrong child element", CHILD_NAME2, nd.getName().getName()); } }
Example #25
Source File: BeanModelTestCase.java From commons-jxpath with Apache License 2.0 | 5 votes |
private void testMultiple( int propertyIndex, int offset, boolean useStartLocation, boolean reverse, int expected) { PropertyOwnerPointer root = (PropertyOwnerPointer) NodePointer.newNodePointer( new QName(null, "root"), createContextBean(), Locale.getDefault()); NodeIterator it; PropertyPointer start = null; if (useStartLocation) { start = root.getPropertyPointer(); start.setPropertyIndex(propertyIndex); start.setIndex(offset); } it = root.childIterator(null, reverse, start); int size = 0; while (it.setPosition(it.getPosition() + 1)) { // System.err.println("LOC: " + it.getCurrentNodePointer()); size++; } assertEquals( "ITERATIONS: Multiple, propertyIndex=" + propertyIndex + ", offset=" + offset + ", useStartLocation=" + useStartLocation + ", reverse=" + reverse, expected, size); }
Example #26
Source File: CollectionAttributeNodeIterator.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Create a new CollectionAttributeNodeIterator. * @param pointer collection pointer * @param name attribute name */ public CollectionAttributeNodeIterator( CollectionPointer pointer, QName name) { super(pointer, false, null); this.name = name; }
Example #27
Source File: TestConfigurationAttributePointer.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests querying the node name. */ @Test public void testGetName() { final QName name = pointer.getName(); assertEquals("Wrong name", ATTR_NAME, name.getName()); assertNull("Prefix not null", name.getPrefix()); }
Example #28
Source File: TestConfigurationAttributePointer.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests querying an iterator for attributes. Result should be null. */ @Test public void testAttributeIterator() { assertNull("Returned an attribute iterator", pointer .attributeIterator(new QName(null, "test"))); }
Example #29
Source File: PropertyPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
public NodePointer createChild( JXPathContext context, QName name, int index) { PropertyPointer prop = (PropertyPointer) clone(); if (name != null) { prop.setPropertyName(name.toString()); } prop.setIndex(index); return prop.createPath(context); }
Example #30
Source File: BeanPointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Create a new BeanPointer. * @param parent pointer * @param name is the name given to the first node * @param bean pointed * @param beanInfo JXPathBeanInfo */ public BeanPointer(NodePointer parent, QName name, Object bean, JXPathBeanInfo beanInfo) { super(parent); this.name = name; this.bean = bean; this.beanInfo = beanInfo; }