|
Commons JXPath example source code file (PropertyOwnerPointer.java)
The Commons JXPath PropertyOwnerPointer.java source code/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jxpath.ri.model.beans;
import java.util.Locale;
import org.apache.commons.jxpath.JXPathInvalidAccessException;
import org.apache.commons.jxpath.ri.Compiler;
import org.apache.commons.jxpath.ri.QName;
import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
import org.apache.commons.jxpath.ri.compiler.NodeTest;
import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.util.ValueUtils;
/**
* A pointer describing a node that has properties, each of which could be
* a collection.
*
* @author Dmitri Plotnikov
* @version $Revision: 652845 $ $Date: 2008-05-02 12:46:46 -0500 (Fri, 02 May 2008) $
*/
public abstract class PropertyOwnerPointer extends NodePointer {
private static final Object UNINITIALIZED = new Object();
private Object value = UNINITIALIZED;
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;
}
/**
* Create a NodeIterator.
* @param property property name
* @param reverse whether to iterate in reverse
* @param startWith first pointer to return
* @return NodeIterator
*/
public NodeIterator createNodeIterator(String property, boolean reverse,
NodePointer startWith) {
return new PropertyIterator(this, property, reverse, startWith);
}
public NodeIterator attributeIterator(QName name) {
return new BeanAttributeIterator(this, name);
}
/**
* Create a new PropertyOwnerPointer.
* @param parent parent pointer
* @param locale Locale
*/
protected PropertyOwnerPointer(NodePointer parent, Locale locale) {
super(parent, locale);
}
/**
* Create a new PropertyOwnerPointer.
* @param parent pointer
*/
protected PropertyOwnerPointer(NodePointer parent) {
super(parent);
}
public void setIndex(int index) {
if (this.index != index) {
super.setIndex(index);
value = UNINITIALIZED;
}
}
public Object getImmediateNode() {
if (value == UNINITIALIZED) {
value = index == WHOLE_COLLECTION ? ValueUtils.getValue(getBaseValue())
: ValueUtils.getValue(getBaseValue(), index);
}
return value;
}
public abstract QName getName();
/**
* Learn whether <code>name is a valid child name for this PropertyOwnerPointer.
* @param name the QName to test
* @return <code>true if
Other Commons JXPath examples (source code examples)Here is a short list of links related to this Commons JXPath PropertyOwnerPointer.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.