You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/03/16 17:34:17 UTC

(commons-jxpath) branch master updated (2cfa094 -> 1d0b912)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git


    from 2cfa094  Merge pull request #229 from apache/dependabot/github_actions/github/codeql-action-3.28.11
     new d25a753  Sort members
     new fcb6303  Sort imports
     new 44cadb5  Use final
     new be4c125  No need to nest else
     new c0240aa  No need to nest else
     new 7c01db1  No need to nest else
     new d4d218b  No need to nest else
     new 867a743  No need to nest else
     new 452f5f4  Use final
     new c71f011  Type casts are not needed
     new 447adc6  No need to nest else
     new 8dea6ed  No need to nest else
     new 21fb8df  No need to nest else
     new c57b627  No need to nest else
     new 459a318  No need to nest else
     new 9c1b79d  Remove trailing whitespace
     new 4757ea8  Move less edited sections to the bottom
     new 1d0b912  Make Java 23 build a production build

The 18 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/maven.yml                        |    5 +-
 pom.xml                                            |   85 +-
 .../org/apache/commons/jxpath/BasicNodeSet.java    |   58 +-
 .../org/apache/commons/jxpath/BasicVariables.java  |   30 +-
 .../org/apache/commons/jxpath/ClassFunctions.java  |   20 +-
 .../apache/commons/jxpath/CompiledExpression.java  |   80 +-
 .../commons/jxpath/DynamicPropertyHandler.java     |   14 +-
 .../apache/commons/jxpath/ExpressionContext.java   |   10 +-
 .../org/apache/commons/jxpath/FunctionLibrary.java |   86 +-
 .../java/org/apache/commons/jxpath/Functions.java  |   14 +-
 .../apache/commons/jxpath/JXPathBasicBeanInfo.java |   50 +-
 .../org/apache/commons/jxpath/JXPathBeanInfo.java  |   44 +-
 .../org/apache/commons/jxpath/JXPathContext.java   |  684 +--
 .../commons/jxpath/JXPathContextFactory.java       |  146 +-
 .../JXPathContextFactoryConfigurationError.java    |   42 +-
 .../org/apache/commons/jxpath/JXPathException.java |   52 +-
 .../apache/commons/jxpath/JXPathIntrospector.java  |  134 +-
 .../commons/jxpath/MapDynamicPropertyHandler.java  |   10 +-
 .../apache/commons/jxpath/PackageFunctions.java    |   20 +-
 .../java/org/apache/commons/jxpath/Pointer.java    |   62 +-
 .../java/org/apache/commons/jxpath/Variables.java  |   16 +-
 .../commons/jxpath/XMLDocumentContainer.java       |   16 +-
 .../commons/jxpath/functions/MethodFunction.java   |    2 +-
 .../org/apache/commons/jxpath/ri/Compiler.java     |  200 +-
 .../org/apache/commons/jxpath/ri/EvalContext.java  |  328 +-
 .../org/apache/commons/jxpath/ri/InfoSetUtil.java  |  122 +-
 .../jxpath/ri/JXPathCompiledExpression.java        |   62 +-
 .../jxpath/ri/JXPathContextReferenceImpl.java      |  762 +--
 .../commons/jxpath/ri/NamespaceResolver.java       |  124 +-
 .../java/org/apache/commons/jxpath/ri/Parser.java  |   54 +-
 .../java/org/apache/commons/jxpath/ri/QName.java   |   34 +-
 .../commons/jxpath/ri/axes/AncestorContext.java    |   40 +-
 .../commons/jxpath/ri/axes/AttributeContext.java   |   42 +-
 .../commons/jxpath/ri/axes/ChildContext.java       |   26 +-
 .../commons/jxpath/ri/axes/DescendantContext.java  |   66 +-
 .../commons/jxpath/ri/axes/InitialContext.java     |   22 +-
 .../commons/jxpath/ri/axes/NamespaceContext.java   |   50 +-
 .../commons/jxpath/ri/axes/NodeSetContext.java     |   20 +-
 .../commons/jxpath/ri/axes/ParentContext.java      |   24 +-
 .../ri/axes/PrecedingOrFollowingContext.java       |   40 +-
 .../commons/jxpath/ri/axes/PredicateContext.java   |   92 +-
 .../apache/commons/jxpath/ri/axes/RootContext.java |  104 +-
 .../apache/commons/jxpath/ri/axes/SelfContext.java |   10 +-
 .../jxpath/ri/axes/SimplePathInterpreter.java      |  944 ++--
 .../commons/jxpath/ri/compiler/Constant.java       |   14 +-
 .../commons/jxpath/ri/compiler/CoreFunction.java   |  890 ++--
 .../commons/jxpath/ri/compiler/CoreOperation.java  |   46 +-
 .../jxpath/ri/compiler/CoreOperationAdd.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationAnd.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationCompare.java   |   86 +-
 .../jxpath/ri/compiler/CoreOperationDivide.java    |    8 +-
 .../jxpath/ri/compiler/CoreOperationMod.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationMultiply.java  |    8 +-
 .../jxpath/ri/compiler/CoreOperationNegate.java    |    8 +-
 .../jxpath/ri/compiler/CoreOperationOr.java        |    8 +-
 .../CoreOperationRelationalExpression.java         |   72 +-
 .../jxpath/ri/compiler/CoreOperationSubtract.java  |    8 +-
 .../jxpath/ri/compiler/CoreOperationUnion.java     |    8 +-
 .../commons/jxpath/ri/compiler/Expression.java     |  172 +-
 .../commons/jxpath/ri/compiler/ExpressionPath.java |  128 +-
 .../jxpath/ri/compiler/ExtensionFunction.java      |   58 +-
 .../commons/jxpath/ri/compiler/LocationPath.java   |   56 +-
 .../jxpath/ri/compiler/NameAttributeTest.java      |   10 +-
 .../commons/jxpath/ri/compiler/NodeNameTest.java   |   16 +-
 .../commons/jxpath/ri/compiler/NodeTypeTest.java   |   40 +-
 .../commons/jxpath/ri/compiler/Operation.java      |   16 +-
 .../apache/commons/jxpath/ri/compiler/Path.java    |  310 +-
 .../apache/commons/jxpath/ri/compiler/Step.java    |   80 +-
 .../commons/jxpath/ri/compiler/TreeCompiler.java   |  182 +-
 .../jxpath/ri/compiler/VariableReference.java      |   40 +-
 .../commons/jxpath/ri/model/NodeIterator.java      |   12 +-
 .../commons/jxpath/ri/model/NodePointer.java       | 1226 ++---
 .../jxpath/ri/model/NodePointerFactory.java        |   28 +-
 .../commons/jxpath/ri/model/VariablePointer.java   |  342 +-
 .../jxpath/ri/model/VariablePointerFactory.java    |   18 +-
 .../commons/jxpath/ri/model/beans/BeanPointer.java |  148 +-
 .../jxpath/ri/model/beans/BeanPointerFactory.java  |   20 +-
 .../jxpath/ri/model/beans/BeanPropertyPointer.java |  302 +-
 .../ri/model/beans/CollectionNodeIterator.java     |   36 +-
 .../jxpath/ri/model/beans/CollectionPointer.java   |  240 +-
 .../ri/model/beans/CollectionPointerFactory.java   |   10 +-
 .../ri/model/beans/LangAttributePointer.java       |   84 +-
 .../jxpath/ri/model/beans/NullElementPointer.java  |  120 +-
 .../commons/jxpath/ri/model/beans/NullPointer.java |  118 +-
 .../jxpath/ri/model/beans/NullPropertyPointer.java |  205 +-
 .../jxpath/ri/model/beans/PropertyIterator.java    |  198 +-
 .../ri/model/beans/PropertyOwnerPointer.java       |  152 +-
 .../jxpath/ri/model/beans/PropertyPointer.java     |  296 +-
 .../ri/model/container/ContainerPointer.java       |  118 +-
 .../model/container/ContainerPointerFactory.java   |   12 +-
 .../jxpath/ri/model/dom/DOMAttributeIterator.java  |   66 +-
 .../jxpath/ri/model/dom/DOMAttributePointer.java   |  108 +-
 .../jxpath/ri/model/dom/DOMNodeIterator.java       |   68 +-
 .../jxpath/ri/model/dom/DOMNodePointer.java        |  938 ++--
 .../jxpath/ri/model/dom/DOMPointerFactory.java     |   14 +-
 .../jxpath/ri/model/dom/NamespacePointer.java      |  100 +-
 .../jxpath/ri/model/dynabeans/DynaBeanPointer.java |   90 +-
 .../ri/model/dynabeans/DynaBeanPointerFactory.java |   10 +-
 .../model/dynabeans/DynaBeanPropertyPointer.java   |  242 +-
 .../StrictLazyDynaBeanPointerFactory.java          |   10 +-
 .../jxpath/ri/model/dynamic/DynamicPointer.java    |   94 +-
 .../ri/model/dynamic/DynamicPointerFactory.java    |   30 +-
 .../ri/model/dynamic/DynamicPropertyPointer.java   |  316 +-
 .../jxpath/ri/model/jdom/JDOMAttributePointer.java |   96 +-
 .../jxpath/ri/model/jdom/JDOMNamespacePointer.java |   82 +-
 .../jxpath/ri/model/jdom/JDOMNodeIterator.java     |   86 +-
 .../jxpath/ri/model/jdom/JDOMNodePointer.java      |  974 ++--
 .../jxpath/ri/model/jdom/JDOMPointerFactory.java   |   22 +-
 .../commons/jxpath/ri/parser/ParseException.java   |  196 +-
 .../commons/jxpath/ri/parser/SimpleCharStream.java |  416 +-
 .../org/apache/commons/jxpath/ri/parser/Token.java |   44 +-
 .../commons/jxpath/ri/parser/TokenMgrError.java    |   56 +-
 .../commons/jxpath/ri/parser/XPathParser.java      | 5408 ++++++++++----------
 .../jxpath/ri/parser/XPathParserTokenManager.java  | 3076 +++++------
 .../servlet/HttpSessionAndServletContext.java      |   16 +-
 .../commons/jxpath/servlet/HttpSessionHandler.java |    6 +-
 .../jxpath/servlet/JXPathServletContexts.java      |   44 +-
 .../commons/jxpath/servlet/KeywordVariables.java   |   10 +-
 .../commons/jxpath/servlet/PageContextHandler.java |   22 +-
 .../commons/jxpath/servlet/PageScopeContext.java   |   16 +-
 .../jxpath/servlet/PageScopeContextHandler.java    |   10 +-
 .../jxpath/servlet/ServletContextHandler.java      |   14 +-
 .../jxpath/servlet/ServletRequestAndContext.java   |   12 +-
 .../commons/jxpath/util/BasicTypeConverter.java    |  416 +-
 .../commons/jxpath/util/ClassLoaderUtil.java       |   50 +-
 .../commons/jxpath/util/MethodLookupUtils.java     |   64 +-
 .../org/apache/commons/jxpath/util/TypeUtils.java  |   32 +-
 .../org/apache/commons/jxpath/util/ValueUtils.java |  704 +--
 .../commons/jxpath/xml/DocumentContainer.java      |   64 +-
 .../org/apache/commons/jxpath/xml/XMLParser2.java  |  106 +-
 .../apache/commons/jxpath/AbstractJXPathTest.java  |  438 +-
 .../apache/commons/jxpath/BasicNodeSetTest.java    |  114 +-
 .../org/apache/commons/jxpath/NestedTestBean.java  |   36 +-
 .../java/org/apache/commons/jxpath/TestBean.java   |  124 +-
 .../apache/commons/jxpath/TestMixedModelBean.java  |   24 +-
 .../java/org/apache/commons/jxpath/TestNull.java   |   24 +-
 .../commons/jxpath/issues/JXPath113Test.java       |   40 +-
 .../commons/jxpath/issues/JXPath118Test.java       |   47 +-
 .../commons/jxpath/issues/JXPath149Test.java       |    2 +-
 .../jxpath/issues/JXPath172DynamicTest.java        |   97 +-
 .../commons/jxpath/issues/JXPath172Test.java       |  125 +-
 .../commons/jxpath/issues/JXPath177Test.java       |  107 +-
 .../commons/jxpath/ri/ExceptionHandlerTest.java    |   40 +-
 .../jxpath/ri/JXPathCompiledExpressionTest.java    |  132 +-
 .../ri/JXPathContextReferenceImplTestCase.java     |    1 -
 .../org/apache/commons/jxpath/ri/StressTest.java   |   49 +-
 .../commons/jxpath/ri/axes/RecursiveAxesTest.java  |    2 +-
 .../commons/jxpath/ri/axes/RecursiveBean.java      |   12 +-
 .../jxpath/ri/axes/SimplePathInterpreterTest.java  |  665 ++-
 .../commons/jxpath/ri/axes/TestBeanWithNode.java   |   36 +-
 .../jxpath/ri/compiler/ContextDependencyTest.java  |    4 +-
 .../jxpath/ri/compiler/CoreFunctionTest.java       |   68 +-
 .../jxpath/ri/compiler/CoreOperationTest.java      |   66 +-
 .../jxpath/ri/compiler/ExtensionFunctionTest.java  |  362 +-
 .../commons/jxpath/ri/compiler/TestFunctions.java  |  146 +-
 .../commons/jxpath/ri/compiler/VariableTest.java   |  248 +-
 .../jxpath/ri/model/AbstractBeanModelTest.java     | 1200 ++---
 .../jxpath/ri/model/AbstractXMLModelTest.java      |  976 ++--
 .../ri/model/AliasedNamespaceIterationTest.java    |   18 +-
 .../jxpath/ri/model/EmbeddedColonMapKeysTest.java  |    2 +-
 .../jxpath/ri/model/EmptyCollectionTest.java       |   32 +-
 .../jxpath/ri/model/ExceptionPropertyTestBean.java |    8 +-
 .../jxpath/ri/model/ExternalXMLNamespaceTest.java  |   34 +-
 .../commons/jxpath/ri/model/JXPath151Test.java     |    2 +-
 .../commons/jxpath/ri/model/JXPath154Test.java     |    6 +-
 .../commons/jxpath/ri/model/MixedModelTest.java    |  622 +--
 .../jxpath/ri/model/XMLPreserveSpaceTest.java      |   46 +-
 .../commons/jxpath/ri/model/XMLSpaceTest.java      |   46 +-
 .../jxpath/ri/model/XMLUpperCaseElementsTest.java  |   14 +-
 .../model/beans/BadlyImplementedFactoryTest.java   |    9 +-
 .../ri/model/container/ContainerModelTest.java     |   86 +-
 .../commons/jxpath/ri/model/dom/DOMModelTest.java  |   90 +-
 .../jxpath/ri/model/dom/TestDOMFactory.java        |   50 +-
 .../ri/model/dynabeans/LazyDynaBeanTest.java       |    6 +-
 .../model/dynamic/DynamicPropertiesModelTest.java  |  256 +-
 .../jxpath/ri/model/jdom/JDOMModelTest.java        |  104 +-
 .../jxpath/ri/model/jdom/TestJDOMFactory.java      |   54 +-
 .../jxpath/servlet/JXPathServletContextTest.java   |  145 +-
 .../jxpath/util/BasicTypeConverterTest.java        |  155 +-
 .../commons/jxpath/util/ClassLoaderUtilTest.java   |  213 +-
 .../apache/commons/jxpath/util/ValueUtilsTest.java |   58 +-
 181 files changed, 16077 insertions(+), 16111 deletions(-)


(commons-jxpath) 18/18: Make Java 23 build a production build

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 1d0b9123a735cc65e10ce5dbff0790ac72d6ff55
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:34:12 2025 -0400

    Make Java 23 build a production build
---
 .github/workflows/maven.yml | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 070c70e..265775c 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -28,12 +28,9 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, windows-latest, macos-13]
-        java: [ 8, 11, 17, 21 ]
+        java: [ 8, 11, 17, 21, 23 ]
         experimental: [false]
         include:
-          - java: 23
-            os: windows-latest
-            experimental: false        
           - java: 24-ea
             os: macos-latest
             experimental: true        


(commons-jxpath) 08/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 867a7431f959e3e5581c91840d40bf99516e766a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:26:44 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
index 288d443..8b3d820 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
@@ -392,7 +392,7 @@ public class JDOMNodePointer extends NodePointer {
                 if (n == node1) {
                     return -1;
                 }
-                else if (n == node2) {
+                if (n == node2) {
                     return 1;
                 }
             }


(commons-jxpath) 01/18: Sort members

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit d25a75322f3d3f03dec9501caeb9416d47f34b0c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:22:46 2025 -0400

    Sort members
---
 .../org/apache/commons/jxpath/BasicNodeSet.java    |   58 +-
 .../org/apache/commons/jxpath/BasicVariables.java  |   30 +-
 .../org/apache/commons/jxpath/ClassFunctions.java  |   20 +-
 .../apache/commons/jxpath/CompiledExpression.java  |   80 +-
 .../commons/jxpath/DynamicPropertyHandler.java     |   14 +-
 .../apache/commons/jxpath/ExpressionContext.java   |   10 +-
 .../org/apache/commons/jxpath/FunctionLibrary.java |   86 +-
 .../java/org/apache/commons/jxpath/Functions.java  |   14 +-
 .../apache/commons/jxpath/JXPathBasicBeanInfo.java |   50 +-
 .../org/apache/commons/jxpath/JXPathBeanInfo.java  |   44 +-
 .../org/apache/commons/jxpath/JXPathContext.java   |  684 +--
 .../commons/jxpath/JXPathContextFactory.java       |  146 +-
 .../JXPathContextFactoryConfigurationError.java    |   42 +-
 .../org/apache/commons/jxpath/JXPathException.java |   52 +-
 .../apache/commons/jxpath/JXPathIntrospector.java  |  134 +-
 .../commons/jxpath/MapDynamicPropertyHandler.java  |   10 +-
 .../apache/commons/jxpath/PackageFunctions.java    |   20 +-
 .../java/org/apache/commons/jxpath/Pointer.java    |   62 +-
 .../java/org/apache/commons/jxpath/Variables.java  |   16 +-
 .../commons/jxpath/XMLDocumentContainer.java       |   16 +-
 .../commons/jxpath/functions/MethodFunction.java   |    2 +-
 .../org/apache/commons/jxpath/ri/Compiler.java     |  200 +-
 .../org/apache/commons/jxpath/ri/EvalContext.java  |  328 +-
 .../org/apache/commons/jxpath/ri/InfoSetUtil.java  |  122 +-
 .../jxpath/ri/JXPathCompiledExpression.java        |   62 +-
 .../jxpath/ri/JXPathContextReferenceImpl.java      |  758 +--
 .../commons/jxpath/ri/NamespaceResolver.java       |  124 +-
 .../java/org/apache/commons/jxpath/ri/Parser.java  |   54 +-
 .../java/org/apache/commons/jxpath/ri/QName.java   |   34 +-
 .../commons/jxpath/ri/axes/AncestorContext.java    |   40 +-
 .../commons/jxpath/ri/axes/AttributeContext.java   |   42 +-
 .../commons/jxpath/ri/axes/ChildContext.java       |   26 +-
 .../commons/jxpath/ri/axes/DescendantContext.java  |   66 +-
 .../commons/jxpath/ri/axes/InitialContext.java     |   22 +-
 .../commons/jxpath/ri/axes/NamespaceContext.java   |   42 +-
 .../commons/jxpath/ri/axes/NodeSetContext.java     |   20 +-
 .../commons/jxpath/ri/axes/ParentContext.java      |   24 +-
 .../ri/axes/PrecedingOrFollowingContext.java       |   40 +-
 .../commons/jxpath/ri/axes/PredicateContext.java   |   92 +-
 .../apache/commons/jxpath/ri/axes/RootContext.java |  104 +-
 .../apache/commons/jxpath/ri/axes/SelfContext.java |   10 +-
 .../jxpath/ri/axes/SimplePathInterpreter.java      |  942 ++--
 .../commons/jxpath/ri/compiler/Constant.java       |   14 +-
 .../commons/jxpath/ri/compiler/CoreFunction.java   |  886 ++--
 .../commons/jxpath/ri/compiler/CoreOperation.java  |   46 +-
 .../jxpath/ri/compiler/CoreOperationAdd.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationAnd.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationCompare.java   |   86 +-
 .../jxpath/ri/compiler/CoreOperationDivide.java    |    8 +-
 .../jxpath/ri/compiler/CoreOperationMod.java       |    8 +-
 .../jxpath/ri/compiler/CoreOperationMultiply.java  |    8 +-
 .../jxpath/ri/compiler/CoreOperationNegate.java    |    8 +-
 .../jxpath/ri/compiler/CoreOperationOr.java        |    8 +-
 .../CoreOperationRelationalExpression.java         |   72 +-
 .../jxpath/ri/compiler/CoreOperationSubtract.java  |    8 +-
 .../jxpath/ri/compiler/CoreOperationUnion.java     |    8 +-
 .../commons/jxpath/ri/compiler/Expression.java     |  172 +-
 .../commons/jxpath/ri/compiler/ExpressionPath.java |  128 +-
 .../jxpath/ri/compiler/ExtensionFunction.java      |   58 +-
 .../commons/jxpath/ri/compiler/LocationPath.java   |   56 +-
 .../jxpath/ri/compiler/NameAttributeTest.java      |   10 +-
 .../commons/jxpath/ri/compiler/NodeNameTest.java   |   16 +-
 .../commons/jxpath/ri/compiler/NodeTypeTest.java   |   40 +-
 .../commons/jxpath/ri/compiler/Operation.java      |   16 +-
 .../apache/commons/jxpath/ri/compiler/Path.java    |  310 +-
 .../apache/commons/jxpath/ri/compiler/Step.java    |   80 +-
 .../commons/jxpath/ri/compiler/TreeCompiler.java   |  182 +-
 .../jxpath/ri/compiler/VariableReference.java      |   40 +-
 .../commons/jxpath/ri/model/NodeIterator.java      |   12 +-
 .../commons/jxpath/ri/model/NodePointer.java       | 1226 ++---
 .../jxpath/ri/model/NodePointerFactory.java        |   28 +-
 .../commons/jxpath/ri/model/VariablePointer.java   |  344 +-
 .../jxpath/ri/model/VariablePointerFactory.java    |   18 +-
 .../commons/jxpath/ri/model/beans/BeanPointer.java |  148 +-
 .../jxpath/ri/model/beans/BeanPointerFactory.java  |   20 +-
 .../jxpath/ri/model/beans/BeanPropertyPointer.java |  302 +-
 .../ri/model/beans/CollectionNodeIterator.java     |   36 +-
 .../jxpath/ri/model/beans/CollectionPointer.java   |  240 +-
 .../ri/model/beans/CollectionPointerFactory.java   |   10 +-
 .../ri/model/beans/LangAttributePointer.java       |   84 +-
 .../jxpath/ri/model/beans/NullElementPointer.java  |  120 +-
 .../commons/jxpath/ri/model/beans/NullPointer.java |  118 +-
 .../jxpath/ri/model/beans/NullPropertyPointer.java |  208 +-
 .../jxpath/ri/model/beans/PropertyIterator.java    |  198 +-
 .../ri/model/beans/PropertyOwnerPointer.java       |  140 +-
 .../jxpath/ri/model/beans/PropertyPointer.java     |  296 +-
 .../ri/model/container/ContainerPointer.java       |  118 +-
 .../model/container/ContainerPointerFactory.java   |   12 +-
 .../jxpath/ri/model/dom/DOMAttributeIterator.java  |   66 +-
 .../jxpath/ri/model/dom/DOMAttributePointer.java   |  108 +-
 .../jxpath/ri/model/dom/DOMNodeIterator.java       |   68 +-
 .../jxpath/ri/model/dom/DOMNodePointer.java        |  938 ++--
 .../jxpath/ri/model/dom/DOMPointerFactory.java     |   14 +-
 .../jxpath/ri/model/dom/NamespacePointer.java      |  100 +-
 .../jxpath/ri/model/dynabeans/DynaBeanPointer.java |   90 +-
 .../ri/model/dynabeans/DynaBeanPointerFactory.java |   10 +-
 .../model/dynabeans/DynaBeanPropertyPointer.java   |  244 +-
 .../StrictLazyDynaBeanPointerFactory.java          |   10 +-
 .../jxpath/ri/model/dynamic/DynamicPointer.java    |   94 +-
 .../ri/model/dynamic/DynamicPointerFactory.java    |   30 +-
 .../ri/model/dynamic/DynamicPropertyPointer.java   |  316 +-
 .../jxpath/ri/model/jdom/JDOMAttributePointer.java |   96 +-
 .../jxpath/ri/model/jdom/JDOMNamespacePointer.java |   82 +-
 .../jxpath/ri/model/jdom/JDOMNodeIterator.java     |   86 +-
 .../jxpath/ri/model/jdom/JDOMNodePointer.java      |  974 ++--
 .../jxpath/ri/model/jdom/JDOMPointerFactory.java   |   22 +-
 .../commons/jxpath/ri/parser/ParseException.java   |  196 +-
 .../commons/jxpath/ri/parser/SimpleCharStream.java |  416 +-
 .../org/apache/commons/jxpath/ri/parser/Token.java |   44 +-
 .../commons/jxpath/ri/parser/TokenMgrError.java    |   56 +-
 .../commons/jxpath/ri/parser/XPathParser.java      | 5410 ++++++++++----------
 .../jxpath/ri/parser/XPathParserTokenManager.java  | 3076 +++++------
 .../servlet/HttpSessionAndServletContext.java      |   16 +-
 .../jxpath/servlet/JXPathServletContexts.java      |   44 +-
 .../commons/jxpath/servlet/KeywordVariables.java   |   10 +-
 .../commons/jxpath/servlet/PageContextHandler.java |   22 +-
 .../commons/jxpath/servlet/PageScopeContext.java   |   16 +-
 .../jxpath/servlet/PageScopeContextHandler.java    |   10 +-
 .../jxpath/servlet/ServletContextHandler.java      |   14 +-
 .../jxpath/servlet/ServletRequestAndContext.java   |   12 +-
 .../commons/jxpath/util/BasicTypeConverter.java    |  416 +-
 .../commons/jxpath/util/ClassLoaderUtil.java       |   50 +-
 .../commons/jxpath/util/MethodLookupUtils.java     |   64 +-
 .../org/apache/commons/jxpath/util/TypeUtils.java  |   32 +-
 .../org/apache/commons/jxpath/util/ValueUtils.java |  704 +--
 .../commons/jxpath/xml/DocumentContainer.java      |   64 +-
 .../org/apache/commons/jxpath/xml/XMLParser2.java  |  106 +-
 .../apache/commons/jxpath/AbstractJXPathTest.java  |  432 +-
 .../apache/commons/jxpath/BasicNodeSetTest.java    |  110 +-
 .../org/apache/commons/jxpath/NestedTestBean.java  |   36 +-
 .../java/org/apache/commons/jxpath/TestBean.java   |  124 +-
 .../apache/commons/jxpath/TestMixedModelBean.java  |   24 +-
 .../java/org/apache/commons/jxpath/TestNull.java   |   24 +-
 .../commons/jxpath/issues/JXPath113Test.java       |   32 +-
 .../commons/jxpath/issues/JXPath118Test.java       |   42 +-
 .../jxpath/issues/JXPath172DynamicTest.java        |   86 +-
 .../commons/jxpath/issues/JXPath172Test.java       |  112 +-
 .../commons/jxpath/issues/JXPath177Test.java       |  100 +-
 .../commons/jxpath/ri/ExceptionHandlerTest.java    |   32 +-
 .../jxpath/ri/JXPathCompiledExpressionTest.java    |  126 +-
 .../org/apache/commons/jxpath/ri/StressTest.java   |   42 +-
 .../commons/jxpath/ri/axes/RecursiveBean.java      |   12 +-
 .../jxpath/ri/axes/SimplePathInterpreterTest.java  |  738 +--
 .../commons/jxpath/ri/axes/TestBeanWithNode.java   |   36 +-
 .../jxpath/ri/compiler/CoreFunctionTest.java       |   66 +-
 .../jxpath/ri/compiler/CoreOperationTest.java      |   64 +-
 .../jxpath/ri/compiler/ExtensionFunctionTest.java  |  354 +-
 .../commons/jxpath/ri/compiler/TestFunctions.java  |  146 +-
 .../commons/jxpath/ri/compiler/VariableTest.java   |  238 +-
 .../jxpath/ri/model/AbstractBeanModelTest.java     |  976 ++--
 .../jxpath/ri/model/AbstractXMLModelTest.java      |  966 ++--
 .../ri/model/AliasedNamespaceIterationTest.java    |   16 +-
 .../jxpath/ri/model/EmptyCollectionTest.java       |   30 +-
 .../jxpath/ri/model/ExceptionPropertyTestBean.java |    8 +-
 .../jxpath/ri/model/ExternalXMLNamespaceTest.java  |   32 +-
 .../commons/jxpath/ri/model/MixedModelTest.java    |  582 +--
 .../jxpath/ri/model/XMLPreserveSpaceTest.java      |   40 +-
 .../commons/jxpath/ri/model/XMLSpaceTest.java      |   40 +-
 .../jxpath/ri/model/XMLUpperCaseElementsTest.java  |    8 +-
 .../ri/model/container/ContainerModelTest.java     |   80 +-
 .../commons/jxpath/ri/model/dom/DOMModelTest.java  |   86 +-
 .../jxpath/ri/model/dom/TestDOMFactory.java        |   50 +-
 .../model/dynamic/DynamicPropertiesModelTest.java  |  248 +-
 .../jxpath/ri/model/jdom/JDOMModelTest.java        |  100 +-
 .../jxpath/ri/model/jdom/TestJDOMFactory.java      |   54 +-
 .../jxpath/servlet/JXPathServletContextTest.java   |  128 +-
 .../jxpath/util/BasicTypeConverterTest.java        |  146 +-
 .../commons/jxpath/util/ClassLoaderUtilTest.java   |  204 +-
 .../apache/commons/jxpath/util/ValueUtilsTest.java |   52 +-
 169 files changed, 15826 insertions(+), 15826 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/BasicNodeSet.java b/src/main/java/org/apache/commons/jxpath/BasicNodeSet.java
index aa1a293..b486871 100644
--- a/src/main/java/org/apache/commons/jxpath/BasicNodeSet.java
+++ b/src/main/java/org/apache/commons/jxpath/BasicNodeSet.java
@@ -30,16 +30,6 @@ public class BasicNodeSet implements NodeSet {
     private List nodes;
     private List values;
 
-    /**
-     * Add a pointer to this NodeSet.
-     * @param pointer to add
-     */
-    public void add(final Pointer pointer) {
-        if (pointers.add(pointer)) {
-            clearCacheLists();
-        }
-    }
-
     /**
      * Add the specified NodeSet to this NodeSet.
      * @param nodeSet to add
@@ -51,21 +41,22 @@ public class BasicNodeSet implements NodeSet {
     }
 
     /**
-     * Remove a pointer from this NodeSet.
-     * @param pointer to remove
+     * Add a pointer to this NodeSet.
+     * @param pointer to add
      */
-    public void remove(final Pointer pointer) {
-        if (pointers.remove(pointer)) {
+    public void add(final Pointer pointer) {
+        if (pointers.add(pointer)) {
             clearCacheLists();
         }
     }
 
-    @Override
-    public synchronized List getPointers() {
-        if (readOnlyPointers == null) {
-            readOnlyPointers = Collections.unmodifiableList(pointers);
-        }
-        return readOnlyPointers;
+    /**
+     * Clear cache list members.
+     */
+    private synchronized void clearCacheLists() {
+        readOnlyPointers = null;
+        nodes = null;
+        values = null;
     }
 
     @Override
@@ -81,6 +72,14 @@ public class BasicNodeSet implements NodeSet {
         return nodes;
     }
 
+    @Override
+    public synchronized List getPointers() {
+        if (readOnlyPointers == null) {
+            readOnlyPointers = Collections.unmodifiableList(pointers);
+        }
+        return readOnlyPointers;
+    }
+
     @Override
     public synchronized List getValues() {
         if (values == null) {
@@ -94,18 +93,19 @@ public class BasicNodeSet implements NodeSet {
         return values;
     }
 
+    /**
+     * Remove a pointer from this NodeSet.
+     * @param pointer to remove
+     */
+    public void remove(final Pointer pointer) {
+        if (pointers.remove(pointer)) {
+            clearCacheLists();
+        }
+    }
+
     @Override
     public String toString() {
         return pointers.toString();
     }
 
-    /**
-     * Clear cache list members.
-     */
-    private synchronized void clearCacheLists() {
-        readOnlyPointers = null;
-        nodes = null;
-        values = null;
-    }
-
 }
diff --git a/src/main/java/org/apache/commons/jxpath/BasicVariables.java b/src/main/java/org/apache/commons/jxpath/BasicVariables.java
index 04726da..bad0d7d 100644
--- a/src/main/java/org/apache/commons/jxpath/BasicVariables.java
+++ b/src/main/java/org/apache/commons/jxpath/BasicVariables.java
@@ -30,15 +30,15 @@ public class BasicVariables implements Variables {
     private final HashMap vars = new HashMap();
 
     /**
-     * Returns true if the variable has been defined, even if the
-     * value of the variable is null.
+     * Defines a new variable with the specified value or modifies
+     * the value of an existing variable.
      *
      * @param varName is a variable name without the "$" sign
-     * @return true if the variable is declared
+     * @param value is the new value for the variable, which can be null
      */
     @Override
-    public boolean isDeclaredVariable(final String varName) {
-        return vars.containsKey(varName);
+    public void declareVariable(final String varName, final Object value) {
+        vars.put(varName, value);
     }
 
     /**
@@ -61,15 +61,20 @@ public class BasicVariables implements Variables {
     }
 
     /**
-     * Defines a new variable with the specified value or modifies
-     * the value of an existing variable.
+     * Returns true if the variable has been defined, even if the
+     * value of the variable is null.
      *
      * @param varName is a variable name without the "$" sign
-     * @param value is the new value for the variable, which can be null
+     * @return true if the variable is declared
      */
     @Override
-    public void declareVariable(final String varName, final Object value) {
-        vars.put(varName, value);
+    public boolean isDeclaredVariable(final String varName) {
+        return vars.containsKey(varName);
+    }
+
+    @Override
+    public String toString() {
+        return vars.toString();
     }
 
     /**
@@ -81,9 +86,4 @@ public class BasicVariables implements Variables {
     public void undeclareVariable(final String varName) {
         vars.remove(varName);
     }
-
-    @Override
-    public String toString() {
-        return vars.toString();
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ClassFunctions.java b/src/main/java/org/apache/commons/jxpath/ClassFunctions.java
index 9c397a7..ab1af31 100644
--- a/src/main/java/org/apache/commons/jxpath/ClassFunctions.java
+++ b/src/main/java/org/apache/commons/jxpath/ClassFunctions.java
@@ -64,16 +64,6 @@ public class ClassFunctions implements Functions {
         this.namespace = namespace;
     }
 
-    /**
-     * Returns a set of one namespace - the one specified in the constructor.
-     *
-     * @return a singleton
-     */
-    @Override
-    public Set getUsedNamespaces() {
-        return Collections.singleton(namespace);
-    }
-
     /**
      * Returns a {@link Function}, if any, for the specified namespace,
      * name and parameter types.
@@ -126,4 +116,14 @@ public class ClassFunctions implements Functions {
 
         return null;
     }
+
+    /**
+     * Returns a set of one namespace - the one specified in the constructor.
+     *
+     * @return a singleton
+     */
+    @Override
+    public Set getUsedNamespaces() {
+        return Collections.singleton(namespace);
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/CompiledExpression.java b/src/main/java/org/apache/commons/jxpath/CompiledExpression.java
index dfa2284..9d4b860 100644
--- a/src/main/java/org/apache/commons/jxpath/CompiledExpression.java
+++ b/src/main/java/org/apache/commons/jxpath/CompiledExpression.java
@@ -34,35 +34,6 @@ import java.util.Iterator;
  */
 public interface CompiledExpression {
 
-    /**
-     * Evaluates the xpath and returns the resulting object. Primitive
-     * types are wrapped into objects.
-     * @param context to evaluate
-     * @return Object
-     */
-    Object getValue(JXPathContext context);
-
-    /**
-     * Evaluates the xpath, converts the result to the specified class and
-     * returns the resulting object.
-     * @param context to evaluate
-     * @param requiredType return type
-     * @return Object
-     */
-    Object getValue(JXPathContext context, Class requiredType);
-
-    /**
-     * Modifies the value of the property described by the supplied xpath.
-     * Will throw an exception if one of the following conditions occurs:
-     * <ul>
-     * <li>The xpath does not in fact describe an existing property
-     * <li>The property is not writable (no public, non-static set method)
-     * </ul>
-     * @param context base
-     * @param value to set
-     */
-    void setValue(JXPathContext context, Object value);
-
     /**
      * Creates intermediate elements of
      * the path by invoking an {@link AbstractFactory}, which should first be
@@ -91,15 +62,6 @@ public interface CompiledExpression {
      */
     Pointer createPathAndSetValue(JXPathContext context, Object value);
 
-    /**
-     * Traverses the xpath and returns a Iterator of all results found
-     * for the path. If the xpath matches no properties
-     * in the graph, the Iterator will not be null.
-     * @param context base
-     * @return Iterator
-     */
-    Iterator iterate(JXPathContext context);
-
     /**
      * Traverses the xpath and returns a Pointer.
      * A Pointer provides easy access to a property.
@@ -111,6 +73,32 @@ public interface CompiledExpression {
      */
     Pointer getPointer(JXPathContext context, String xpath);
 
+    /**
+     * Evaluates the xpath and returns the resulting object. Primitive
+     * types are wrapped into objects.
+     * @param context to evaluate
+     * @return Object
+     */
+    Object getValue(JXPathContext context);
+
+    /**
+     * Evaluates the xpath, converts the result to the specified class and
+     * returns the resulting object.
+     * @param context to evaluate
+     * @param requiredType return type
+     * @return Object
+     */
+    Object getValue(JXPathContext context, Class requiredType);
+
+    /**
+     * Traverses the xpath and returns a Iterator of all results found
+     * for the path. If the xpath matches no properties
+     * in the graph, the Iterator will not be null.
+     * @param context base
+     * @return Iterator
+     */
+    Iterator iterate(JXPathContext context);
+
     /**
      * Traverses the xpath and returns an Iterator of Pointers.
      * A Pointer provides easy access to a property.
@@ -121,6 +109,12 @@ public interface CompiledExpression {
      */
     Iterator iteratePointers(JXPathContext context);
 
+    /**
+     * Remove all graph elements described by this expression.
+     * @param context base
+     */
+    void removeAll(JXPathContext context);
+
     /**
      * Remove the graph element described by this expression.
      * @param context base
@@ -128,8 +122,14 @@ public interface CompiledExpression {
     void removePath(JXPathContext context);
 
     /**
-     * Remove all graph elements described by this expression.
+     * Modifies the value of the property described by the supplied xpath.
+     * Will throw an exception if one of the following conditions occurs:
+     * <ul>
+     * <li>The xpath does not in fact describe an existing property
+     * <li>The property is not writable (no public, non-static set method)
+     * </ul>
      * @param context base
+     * @param value to set
      */
-    void removeAll(JXPathContext context);
+    void setValue(JXPathContext context, Object value);
 }
diff --git a/src/main/java/org/apache/commons/jxpath/DynamicPropertyHandler.java b/src/main/java/org/apache/commons/jxpath/DynamicPropertyHandler.java
index 397342c..2f5fdf3 100644
--- a/src/main/java/org/apache/commons/jxpath/DynamicPropertyHandler.java
+++ b/src/main/java/org/apache/commons/jxpath/DynamicPropertyHandler.java
@@ -36,13 +36,6 @@ package org.apache.commons.jxpath;
  */
 public interface DynamicPropertyHandler {
 
-    /**
-     * Returns a list of dynamic property names for the supplied object.
-     * @param object to inspect
-     * @return String[]
-     */
-    String[] getPropertyNames(Object object);
-
     /**
      * Returns the value of the specified dynamic property.
      * @param object to search
@@ -51,6 +44,13 @@ public interface DynamicPropertyHandler {
      */
     Object getProperty(Object object, String propertyName);
 
+    /**
+     * Returns a list of dynamic property names for the supplied object.
+     * @param object to inspect
+     * @return String[]
+     */
+    String[] getPropertyNames(Object object);
+
     /**
      * Modifies the value of the specified dynamic property.
      * @param object to modify
diff --git a/src/main/java/org/apache/commons/jxpath/ExpressionContext.java b/src/main/java/org/apache/commons/jxpath/ExpressionContext.java
index 3cd44ed..b9ec61b 100644
--- a/src/main/java/org/apache/commons/jxpath/ExpressionContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ExpressionContext.java
@@ -45,11 +45,12 @@ import java.util.List;
 public interface ExpressionContext {
 
     /**
-     * Gets the JXPathContext in which this function is being evaluated.
+     * Gets the current context node list.  Each element of the list is
+     * a Pointer.
      *
      * @return A list representing the current context nodes.
      */
-    JXPathContext getJXPathContext();
+    List getContextNodeList();
 
     /**
      * Gets the current context node.
@@ -59,12 +60,11 @@ public interface ExpressionContext {
     Pointer getContextNodePointer();
 
     /**
-     * Gets the current context node list.  Each element of the list is
-     * a Pointer.
+     * Gets the JXPathContext in which this function is being evaluated.
      *
      * @return A list representing the current context nodes.
      */
-    List getContextNodeList();
+    JXPathContext getJXPathContext();
 
     /**
      * Returns the current context position.
diff --git a/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java b/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java
index dfd4e75..fa429e2 100644
--- a/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java
+++ b/src/main/java/org/apache/commons/jxpath/FunctionLibrary.java
@@ -45,24 +45,35 @@ public class FunctionLibrary implements Functions {
     }
 
     /**
-     * Remove functions from the library.
-     * @param functions to remove
+     * Prepare the cache.
+     * @return cache map keyed by namespace
      */
-    public void removeFunctions(final Functions functions) {
-        allFunctions.remove(functions);
-        synchronized (this) {
-            byNamespace = null;
+    private synchronized Map functionCache() {
+        if (byNamespace == null) {
+            byNamespace = new HashMap();
+            final int count = allFunctions.size();
+            for (int i = 0; i < count; i++) {
+                final Functions funcs = (Functions) allFunctions.get(i);
+                final Set namespaces = funcs.getUsedNamespaces();
+                for (final Iterator it = namespaces.iterator(); it.hasNext();) {
+                    final String ns = (String) it.next();
+                    final Object candidates = byNamespace.get(ns);
+                    if (candidates == null) {
+                        byNamespace.put(ns, funcs);
+                    }
+                    else if (candidates instanceof Functions) {
+                        final List lst = new ArrayList();
+                        lst.add(candidates);
+                        lst.add(funcs);
+                        byNamespace.put(ns, lst);
+                    }
+                    else {
+                        ((List) candidates).add(funcs);
+                    }
+                }
+            }
         }
-    }
-
-    /**
-     * Returns a set containing all namespaces used by the aggregated
-     * Functions.
-     * @return Set
-     */
-    @Override
-    public Set getUsedNamespaces() {
-        return functionCache().keySet();
+        return byNamespace;
     }
 
     /**
@@ -101,34 +112,23 @@ public class FunctionLibrary implements Functions {
     }
 
     /**
-     * Prepare the cache.
-     * @return cache map keyed by namespace
+     * Returns a set containing all namespaces used by the aggregated
+     * Functions.
+     * @return Set
      */
-    private synchronized Map functionCache() {
-        if (byNamespace == null) {
-            byNamespace = new HashMap();
-            final int count = allFunctions.size();
-            for (int i = 0; i < count; i++) {
-                final Functions funcs = (Functions) allFunctions.get(i);
-                final Set namespaces = funcs.getUsedNamespaces();
-                for (final Iterator it = namespaces.iterator(); it.hasNext();) {
-                    final String ns = (String) it.next();
-                    final Object candidates = byNamespace.get(ns);
-                    if (candidates == null) {
-                        byNamespace.put(ns, funcs);
-                    }
-                    else if (candidates instanceof Functions) {
-                        final List lst = new ArrayList();
-                        lst.add(candidates);
-                        lst.add(funcs);
-                        byNamespace.put(ns, lst);
-                    }
-                    else {
-                        ((List) candidates).add(funcs);
-                    }
-                }
-            }
+    @Override
+    public Set getUsedNamespaces() {
+        return functionCache().keySet();
+    }
+
+    /**
+     * Remove functions from the library.
+     * @param functions to remove
+     */
+    public void removeFunctions(final Functions functions) {
+        allFunctions.remove(functions);
+        synchronized (this) {
+            byNamespace = null;
         }
-        return byNamespace;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/Functions.java b/src/main/java/org/apache/commons/jxpath/Functions.java
index d3788c5..ffb3e7d 100644
--- a/src/main/java/org/apache/commons/jxpath/Functions.java
+++ b/src/main/java/org/apache/commons/jxpath/Functions.java
@@ -27,13 +27,6 @@ import java.util.Set;
  */
 public interface Functions {
 
-    /**
-     * Returns all namespaces in which this function collection defines
-     * functions.
-     * @return Set
-     */
-    Set getUsedNamespaces();
-
     /**
      * Returns a Function, if any, for the specified namespace,
      * name and parameter types.
@@ -43,4 +36,11 @@ public interface Functions {
      * @return Function
      */
     Function getFunction(String namespace, String name, Object[] parameters);
+
+    /**
+     * Returns all namespaces in which this function collection defines
+     * functions.
+     * @return Set
+     */
+    Set getUsedNamespaces();
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java b/src/main/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
index dedd522..8fdbad0 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathBasicBeanInfo.java
@@ -75,22 +75,25 @@ public class JXPathBasicBeanInfo implements JXPathBeanInfo {
     }
 
     /**
-     * Returns true if objects of this class are treated as atomic
-     * objects which have no properties of their own.
-     * @return boolean
+     * For a dynamic class, returns the corresponding DynamicPropertyHandler
+     * class.
+     * @return Class
      */
     @Override
-    public boolean isAtomic() {
-        return atomic;
+    public Class getDynamicPropertyHandlerClass() {
+        return dynamicPropertyHandlerClass;
     }
 
-    /**
-     * Return true if the corresponding objects have dynamic properties.
-     * @return boolean
-     */
     @Override
-    public boolean isDynamic() {
-        return dynamicPropertyHandlerClass != null;
+    public synchronized PropertyDescriptor getPropertyDescriptor(final String propertyName) {
+        if (propertyDescriptorMap == null) {
+            propertyDescriptorMap = new HashMap();
+            final PropertyDescriptor[] pds = getPropertyDescriptors();
+            for (final PropertyDescriptor pd : pds) {
+                propertyDescriptorMap.put(pd.getName(), pd);
+            }
+        }
+        return (PropertyDescriptor) propertyDescriptorMap.get(propertyName);
     }
 
     @Override
@@ -128,26 +131,23 @@ public class JXPathBasicBeanInfo implements JXPathBeanInfo {
         return result;
     }
 
+    /**
+     * Returns true if objects of this class are treated as atomic
+     * objects which have no properties of their own.
+     * @return boolean
+     */
     @Override
-    public synchronized PropertyDescriptor getPropertyDescriptor(final String propertyName) {
-        if (propertyDescriptorMap == null) {
-            propertyDescriptorMap = new HashMap();
-            final PropertyDescriptor[] pds = getPropertyDescriptors();
-            for (final PropertyDescriptor pd : pds) {
-                propertyDescriptorMap.put(pd.getName(), pd);
-            }
-        }
-        return (PropertyDescriptor) propertyDescriptorMap.get(propertyName);
+    public boolean isAtomic() {
+        return atomic;
     }
 
     /**
-     * For a dynamic class, returns the corresponding DynamicPropertyHandler
-     * class.
-     * @return Class
+     * Return true if the corresponding objects have dynamic properties.
+     * @return boolean
      */
     @Override
-    public Class getDynamicPropertyHandlerClass() {
-        return dynamicPropertyHandlerClass;
+    public boolean isDynamic() {
+        return dynamicPropertyHandlerClass != null;
     }
 
     @Override
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathBeanInfo.java b/src/main/java/org/apache/commons/jxpath/JXPathBeanInfo.java
index 667bef1..6a439e8 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathBeanInfo.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathBeanInfo.java
@@ -34,22 +34,20 @@ import java.io.Serializable;
 public interface JXPathBeanInfo extends Serializable {
 
     /**
-     * Returns true if objects of this class are treated as atomic
-     * objects which have no properties of their own.
-     * For example, {@link String} and {@link Number} are atomic.
-     * @return boolean
+     * For dynamic objects, returns the class implementing
+     * the {@link DynamicPropertyHandler} interface. That class can
+     * be used to access dynamic properties.
+     * @return Class
      */
-    boolean isAtomic();
+    Class getDynamicPropertyHandlerClass();
 
     /**
-     * Returns true if the objects of this class have dynamic properties
-     * (e.g. java.util.Map). If this method returns true, {@link #getPropertyDescriptors}
-     * should return null and {@link #getDynamicPropertyHandlerClass} should return
-     * a valid class name.  An object cannot have both static and dynamic
-     * properties at the same time.
-     * @return boolean
+     * Returns a PropertyDescriptor for the specified name or null if there
+     * is no such property.
+     * @param propertyName property name
+     * @return PropertyDescriptor
      */
-    boolean isDynamic();
+    PropertyDescriptor getPropertyDescriptor(String propertyName);
 
     /**
      * Returns a list of property descriptors for the beans described by this
@@ -59,18 +57,20 @@ public interface JXPathBeanInfo extends Serializable {
     PropertyDescriptor[] getPropertyDescriptors();
 
     /**
-     * Returns a PropertyDescriptor for the specified name or null if there
-     * is no such property.
-     * @param propertyName property name
-     * @return PropertyDescriptor
+     * Returns true if objects of this class are treated as atomic
+     * objects which have no properties of their own.
+     * For example, {@link String} and {@link Number} are atomic.
+     * @return boolean
      */
-    PropertyDescriptor getPropertyDescriptor(String propertyName);
+    boolean isAtomic();
 
     /**
-     * For dynamic objects, returns the class implementing
-     * the {@link DynamicPropertyHandler} interface. That class can
-     * be used to access dynamic properties.
-     * @return Class
+     * Returns true if the objects of this class have dynamic properties
+     * (e.g. java.util.Map). If this method returns true, {@link #getPropertyDescriptors}
+     * should return null and {@link #getDynamicPropertyHandlerClass} should return
+     * a valid class name.  An object cannot have both static and dynamic
+     * properties at the same time.
+     * @return boolean
      */
-    Class getDynamicPropertyHandlerClass();
+    boolean isDynamic();
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathContext.java b/src/main/java/org/apache/commons/jxpath/JXPathContext.java
index 17056e9..1a0fed6 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathContext.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathContext.java
@@ -404,6 +404,52 @@ public abstract class JXPathContext {
     private static final PackageFunctions GENERIC_FUNCTIONS =
         new PackageFunctions("", null);
 
+    /**
+     * Compiles the supplied XPath and returns an internal representation
+     * of the path that can then be evaluated.  Use CompiledExpressions
+     * when you need to evaluate the same expression multiple times
+     * and there is a convenient place to cache CompiledExpression
+     * between invocations.
+     * @param xpath to compile
+     * @return CompiledExpression
+     */
+    public static CompiledExpression compile(final String xpath) {
+        if (compilationContext == null) {
+            compilationContext = newContext(null);
+        }
+        return compilationContext.compilePath(xpath);
+    }
+    /**
+     * Acquires a context factory and caches it.
+     * @return JXPathContextFactory
+     */
+    private static JXPathContextFactory getContextFactory () {
+        if (contextFactory == null) {
+            contextFactory = JXPathContextFactory.newInstance();
+        }
+        return contextFactory;
+    }
+    /**
+     * Creates a new JXPathContext with the specified bean as the root node and
+     * the specified parent context. Variables defined in a parent context can
+     * be referenced in XPaths passed to the child context.
+     * @param parentContext parent context
+     * @param contextBean Object
+     * @return JXPathContext
+     */
+    public static JXPathContext newContext(
+            final JXPathContext parentContext,
+            final Object contextBean) {
+        return getContextFactory().newContext(parentContext, contextBean);
+    }
+    /**
+     * Creates a new JXPathContext with the specified object as the root node.
+     * @param contextBean Object
+     * @return JXPathContext
+     */
+    public static JXPathContext newContext(final Object contextBean) {
+        return getContextFactory().newContext(null, contextBean);
+    }
     /** Parent context */
     protected JXPathContext parentContext;
     /** Context bean */
@@ -412,71 +458,71 @@ public abstract class JXPathContext {
     protected Variables vars;
     /** Functions */
     protected Functions functions;
+
     /** AbstractFactory */
     protected AbstractFactory factory;
     /** IdentityManager */
     protected IdentityManager idManager;
     /** KeyManager */
     protected KeyManager keyManager;
+
     /** Decimal format map */
     protected HashMap<String, DecimalFormatSymbols> decimalFormats;
 
     private Locale locale;
+
     private boolean lenientSet = false;
-    private boolean lenient = false;
 
-    /**
-     * Creates a new JXPathContext with the specified object as the root node.
-     * @param contextBean Object
-     * @return JXPathContext
-     */
-    public static JXPathContext newContext(final Object contextBean) {
-        return getContextFactory().newContext(null, contextBean);
-    }
+    private boolean lenient = false;
 
     /**
-     * Creates a new JXPathContext with the specified bean as the root node and
-     * the specified parent context. Variables defined in a parent context can
-     * be referenced in XPaths passed to the child context.
+     * This constructor should remain protected - it is to be overridden by
+     * subclasses, but never explicitly invoked by clients.
      * @param parentContext parent context
      * @param contextBean Object
-     * @return JXPathContext
      */
-    public static JXPathContext newContext(
-            final JXPathContext parentContext,
-            final Object contextBean) {
-        return getContextFactory().newContext(parentContext, contextBean);
+    protected JXPathContext(final JXPathContext parentContext, final Object contextBean) {
+        this.parentContext = parentContext;
+        this.contextBean = contextBean;
     }
 
     /**
-     * Acquires a context factory and caches it.
-     * @return JXPathContextFactory
+     * Overridden by each concrete implementation of JXPathContext
+     * to perform compilation. Is called by {@code compile()}.
+     * @param xpath to compile
+     * @return CompiledExpression
      */
-    private static JXPathContextFactory getContextFactory () {
-        if (contextFactory == null) {
-            contextFactory = JXPathContextFactory.newInstance();
-        }
-        return contextFactory;
-    }
+    protected abstract CompiledExpression compilePath(String xpath);
 
     /**
-     * This constructor should remain protected - it is to be overridden by
-     * subclasses, but never explicitly invoked by clients.
-     * @param parentContext parent context
-     * @param contextBean Object
+     * Creates missing elements of the path by invoking an {@link AbstractFactory},
+     * which should first be installed on the context by calling {@link #setFactory}.
+     * <p>
+     * Will throw an exception if the AbstractFactory fails to create
+     * an instance for a path element.
+     * @param xpath indicating destination to create
+     * @return pointer to new location
      */
-    protected JXPathContext(final JXPathContext parentContext, final Object contextBean) {
-        this.parentContext = parentContext;
-        this.contextBean = contextBean;
-    }
+    public abstract Pointer createPath(String xpath);
 
     /**
-     * Returns the parent context of this context or null.
-     * @return JXPathContext
+     * The same as setValue, except it creates intermediate elements of
+     * the path by invoking an {@link AbstractFactory}, which should first be
+     * installed on the context by calling {@link #setFactory}.
+     * <p>
+     * Will throw an exception if one of the following conditions occurs:
+     * <ul>
+     * <li>Elements of the xpath aleady exist, but the path does not in
+     *  fact describe an existing property
+     * <li>The AbstractFactory fails to create an instance for an intermediate
+     * element.
+     * <li>The property is not writable (no public, non-static set method)
+     * </ul>
+     * @param xpath indicating position to create
+     * @param value to set
+     * @return pointer to new location
      */
-    public JXPathContext getParentContext() {
-        return parentContext;
-    }
+    public abstract Pointer createPathAndSetValue(String xpath, Object value);
 
     /**
      * Returns the JavaBean associated with this context.
@@ -493,44 +539,29 @@ public abstract class JXPathContext {
     public abstract Pointer getContextPointer();
 
     /**
-     * Returns a JXPathContext that is relative to the current JXPathContext.
-     * The supplied pointer becomes the context pointer of the new context.
-     * The relative context inherits variables, extension functions, locale etc
-     * from the parent context.
-     * @param pointer Pointer
-     * @return JXPathContext
-     */
-    public abstract JXPathContext getRelativeContext(Pointer pointer);
-
-    /**
-     * Installs a custom implementation of the Variables interface.
-     * @param vars Variables
-     */
-    public void setVariables(final Variables vars) {
-        this.vars = vars;
-    }
-
-    /**
-     * Returns the variable pool associated with the context. If no such
-     * pool was specified with the {@link #setVariables} method,
-     * returns the default implementation of Variables,
-     * {@link BasicVariables BasicVariables}.
-     * @return Variables
+     * Gets the named DecimalFormatSymbols.
+     * @param name key
+     * @return DecimalFormatSymbols
+     * @see #setDecimalFormatSymbols(String, DecimalFormatSymbols)
      */
-    public Variables getVariables() {
-        if (vars == null) {
-            vars = new BasicVariables();
+    public synchronized DecimalFormatSymbols getDecimalFormatSymbols(final String name) {
+        if (decimalFormats == null) {
+            return parentContext == null ? null : parentContext.getDecimalFormatSymbols(name);
         }
-        return vars;
+        return decimalFormats.get(name);
     }
 
     /**
-     * Install a library of extension functions.
-     * @param functions Functions
-     * @see FunctionLibrary
+     * Returns the AbstractFactory installed on this context.
+     * If none has been installed and this context has a parent context,
+     * returns the parent's factory.  Otherwise returns null.
+     * @return AbstractFactory
      */
-    public void setFunctions(final Functions functions) {
-        this.functions = functions;
+    public AbstractFactory getFactory() {
+        if (factory == null && parentContext != null) {
+            return parentContext.getFactory();
+        }
+        return factory;
     }
 
     /**
@@ -548,37 +579,27 @@ public abstract class JXPathContext {
     }
 
     /**
-     * Install an abstract factory that should be used by the
-     * {@code createPath()} and {@code createPathAndSetValue()}
-     * methods.
-     * @param factory AbstractFactory
-     */
-    public void setFactory(final AbstractFactory factory) {
-        this.factory = factory;
-    }
-
-    /**
-     * Returns the AbstractFactory installed on this context.
-     * If none has been installed and this context has a parent context,
-     * returns the parent's factory.  Otherwise returns null.
-     * @return AbstractFactory
+     * Returns this context's identity manager. If none has been installed,
+     * returns the identity manager of the parent context.
+     * @return IdentityManager
      */
-    public AbstractFactory getFactory() {
-        if (factory == null && parentContext != null) {
-            return parentContext.getFactory();
+    public IdentityManager getIdentityManager() {
+        if (idManager == null && parentContext != null) {
+            return parentContext.getIdentityManager();
         }
-        return factory;
+        return idManager;
     }
 
     /**
-     * Sets the locale for this context.  The value of the "lang"
-     * attribute as well as the lang() function will be
-     * affected by the locale.  By default, JXPath uses
-     * {@code Locale.getDefault()}
-     * @param locale Locale
+     * Returns this context's key manager. If none has been installed,
+     * returns the key manager of the parent context.
+     * @return KeyManager
      */
-    public synchronized void setLocale(final Locale locale) {
-        this.locale = locale;
+    public KeyManager getKeyManager() {
+        if (keyManager == null && parentContext != null) {
+            return parentContext.getKeyManager();
+        }
+        return keyManager;
     }
 
     /**
@@ -598,116 +619,128 @@ public abstract class JXPathContext {
     }
 
     /**
-     * Sets {@link DecimalFormatSymbols} for a given name. The DecimalFormatSymbols
-     * can be referenced as the third, optional argument in the invocation of
-     * {@code format-number (number,format,decimal-format-name)} function.
-     * By default, JXPath uses the symbols for the current locale.
+     * Returns the namespace context pointer set with
+     * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer()}
+     * or, if none has been specified, the context pointer otherwise.
      *
-     * @param name the format name or null for default format.
-     * @param symbols DecimalFormatSymbols
+     * @return The namespace context pointer.
      */
-    public synchronized void setDecimalFormatSymbols(final String name,
-            final DecimalFormatSymbols symbols) {
-        if (decimalFormats == null) {
-            decimalFormats = new HashMap<>();
-        }
-        decimalFormats.put(name, symbols);
+    public Pointer getNamespaceContextPointer() {
+        throw new UnsupportedOperationException(
+                "Namespace registration is not implemented by " + getClass());
     }
 
     /**
-     * Gets the named DecimalFormatSymbols.
-     * @param name key
-     * @return DecimalFormatSymbols
-     * @see #setDecimalFormatSymbols(String, DecimalFormatSymbols)
+     * Given a prefix, returns a registered namespace URI. If the requested
+     * prefix was not defined explicitly using the registerNamespace method,
+     * JXPathContext will then check the context node to see if the prefix is
+     * defined there. See
+     * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer}.
+     *
+     * @param prefix The namespace prefix to look up
+     * @return namespace URI or null if the prefix is undefined.
      */
-    public synchronized DecimalFormatSymbols getDecimalFormatSymbols(final String name) {
-        if (decimalFormats == null) {
-            return parentContext == null ? null : parentContext.getDecimalFormatSymbols(name);
-        }
-        return decimalFormats.get(name);
+    public String getNamespaceURI(final String prefix) {
+        throw new UnsupportedOperationException(
+                "Namespace registration is not implemented by " + getClass());
     }
 
     /**
-     * If the context is in the lenient mode, then getValue() returns null
-     * for inexistent paths.  Otherwise, a path that does not map to
-     * an existing property will throw an exception.  Note that if the
-     * property exists, but its value is null, the exception is <em>not</em>
-     * thrown.
-     * <p>
-     * By default, lenient = false
-     * @param lenient flag
+     * Locates a NodeSet by key/value.
+     * @param key string
+     * @param value object
+     * @return NodeSet found
      */
-    public synchronized void setLenient(final boolean lenient) {
-        this.lenient = lenient;
-        lenientSet = true;
+    public NodeSet getNodeSetByKey(final String key, final Object value) {
+        final KeyManager manager = getKeyManager();
+        if (manager != null) {
+            return KeyManagerUtils.getExtendedKeyManager(manager)
+                    .getNodeSetByKey(this, key, value);
+        }
+        throw new JXPathException("Cannot find an element by key - "
+                + "no KeyManager has been specified");
     }
 
     /**
-     * Learn whether this JXPathContext is lenient.
-     * @return boolean
-     * @see #setLenient(boolean)
+     * Returns the parent context of this context or null.
+     * @return JXPathContext
      */
-    public synchronized boolean isLenient() {
-        if (!lenientSet && parentContext != null) {
-            return parentContext.isLenient();
-        }
-        return lenient;
+    public JXPathContext getParentContext() {
+        return parentContext;
     }
 
     /**
-     * Compiles the supplied XPath and returns an internal representation
-     * of the path that can then be evaluated.  Use CompiledExpressions
-     * when you need to evaluate the same expression multiple times
-     * and there is a convenient place to cache CompiledExpression
-     * between invocations.
-     * @param xpath to compile
-     * @return CompiledExpression
+     * Traverses the xpath and returns a Pointer. A Pointer provides easy access
+     * to a property.
+     * <p>
+     * If the xpath <a href='#matches_no_property_in_the_graph'>matches no
+     * properties in the graph</a> the behavior depends on the value that has
+     * been configured with {@link #setLenient(boolean)}:</p>
+     * <ul>
+     * <li> {@code false} (default) the method will throw a
+     * {@link JXPathNotFoundException}.
+     * <li> {@code true} the method returns a pointer whose
+     * {@link Pointer#getValue()} method will always return null.
+     * </ul>
+     *
+     * @param xpath desired
+     * @return Pointer A {@link Pointer}, never {@code null}.
+     * @throws JXPathNotFoundException see method description.
      */
-    public static CompiledExpression compile(final String xpath) {
-        if (compilationContext == null) {
-            compilationContext = newContext(null);
+    public abstract Pointer getPointer(String xpath);
+
+    /**
+     * Locates a Node by its ID.
+     *
+     * @param id is the ID of the sought node.
+     * @return Pointer
+     */
+    public Pointer getPointerByID(final String id) {
+        final IdentityManager manager = getIdentityManager();
+        if (manager != null) {
+            return manager.getPointerByID(this, id);
         }
-        return compilationContext.compilePath(xpath);
+        throw new JXPathException(
+            "Cannot find an element by ID - "
+                + "no IdentityManager has been specified");
     }
 
     /**
-     * Overridden by each concrete implementation of JXPathContext
-     * to perform compilation. Is called by {@code compile()}.
-     * @param xpath to compile
-     * @return CompiledExpression
+     * Locates a Node by a key value.
+     * @param key string
+     * @param value string
+     * @return Pointer found
      */
-    protected abstract CompiledExpression compilePath(String xpath);
+    public Pointer getPointerByKey(final String key, final String value) {
+        final KeyManager manager = getKeyManager();
+        if (manager != null) {
+            return manager.getPointerByKey(this, key, value);
+        }
+        throw new JXPathException(
+            "Cannot find an element by key - "
+                + "no KeyManager has been specified");
+    }
 
     /**
-     * Finds the first object that matches the specified XPath. It is equivalent
-     * to {@code getPointer(xpath).getNode()}. Note that this method
-     * produces the same result as {@code getValue()} on object models
-     * like JavaBeans, but a different result for DOM/JDOM etc., because it
-     * returns the Node itself, rather than its textual contents.
-     *
-     * @param xpath the xpath to be evaluated
-     * @return the found object
+     * Gets the prefix associated with the specifed namespace URI.
+     * @param namespaceURI the ns URI to check.
+     * @return String prefix
+     * @since JXPath 1.3
      */
-    public Object selectSingleNode(final String xpath) {
-        final Pointer pointer = getPointer(xpath);
-        return pointer == null ? null : pointer.getNode();
+    public String getPrefix(final String namespaceURI) {
+        throw new UnsupportedOperationException(
+                "Namespace registration is not implemented by " + getClass());
     }
 
     /**
-     * Finds all nodes that match the specified XPath.
-     *
-     * @param xpath the xpath to be evaluated
-     * @return a list of found objects
+     * Returns a JXPathContext that is relative to the current JXPathContext.
+     * The supplied pointer becomes the context pointer of the new context.
+     * The relative context inherits variables, extension functions, locale etc
+     * from the parent context.
+     * @param pointer Pointer
+     * @return JXPathContext
      */
-    public List selectNodes(final String xpath) {
-        final ArrayList list = new ArrayList();
-        final Iterator<Pointer> iterator = iteratePointers(xpath);
-        while (iterator.hasNext()) {
-            final Pointer pointer = iterator.next();
-            list.add(pointer.getNode());
-        }
-        return list;
-    }
+    public abstract JXPathContext getRelativeContext(Pointer pointer);
 
     /**
      * Evaluates the xpath and returns the resulting object. Primitive
@@ -727,58 +760,30 @@ public abstract class JXPathContext {
     public abstract Object getValue(String xpath, Class requiredType);
 
     /**
-     * Modifies the value of the property described by the supplied xpath.
-     * Will throw an exception if one of the following conditions occurs:
-     * <ul>
-     * <li>The xpath does not in fact describe an existing property
-     * <li>The property is not writable (no public, non-static set method)
-     * </ul>
-     * @param xpath indicating position
-     * @param value to set
-     */
-    public abstract void setValue(String xpath, Object value);
-
-    /**
-     * Creates missing elements of the path by invoking an {@link AbstractFactory},
-     * which should first be installed on the context by calling {@link #setFactory}.
-     * <p>
-     * Will throw an exception if the AbstractFactory fails to create
-     * an instance for a path element.
-     * @param xpath indicating destination to create
-     * @return pointer to new location
-     */
-    public abstract Pointer createPath(String xpath);
-
-    /**
-     * The same as setValue, except it creates intermediate elements of
-     * the path by invoking an {@link AbstractFactory}, which should first be
-     * installed on the context by calling {@link #setFactory}.
-     * <p>
-     * Will throw an exception if one of the following conditions occurs:
-     * <ul>
-     * <li>Elements of the xpath aleady exist, but the path does not in
-     *  fact describe an existing property
-     * <li>The AbstractFactory fails to create an instance for an intermediate
-     * element.
-     * <li>The property is not writable (no public, non-static set method)
-     * </ul>
-     * @param xpath indicating position to create
-     * @param value to set
-     * @return pointer to new location
-     */
-    public abstract Pointer createPathAndSetValue(String xpath, Object value);
-
-    /**
-     * Removes the element of the object graph described by the xpath.
-     * @param xpath indicating position to remove
+     * Returns the variable pool associated with the context. If no such
+     * pool was specified with the {@link #setVariables} method,
+     * returns the default implementation of Variables,
+     * {@link BasicVariables BasicVariables}.
+     * @return Variables
      */
-    public abstract void removePath(String xpath);
+    public Variables getVariables() {
+        if (vars == null) {
+            vars = new BasicVariables();
+        }
+        return vars;
+    }
 
     /**
-     * Removes all elements of the object graph described by the xpath.
-     * @param xpath indicating positions to remove
+     * Learn whether this JXPathContext is lenient.
+     * @return boolean
+     * @see #setLenient(boolean)
      */
-    public abstract void removeAll(String xpath);
+    public synchronized boolean isLenient() {
+        if (!lenientSet && parentContext != null) {
+            return parentContext.isLenient();
+        }
+        return lenient;
+    }
 
     /**
      * Traverses the xpath and returns an Iterator of all results found
@@ -791,26 +796,6 @@ public abstract class JXPathContext {
      */
     public abstract <E> Iterator<E> iterate(String xpath);
 
-    /**
-     * Traverses the xpath and returns a Pointer. A Pointer provides easy access
-     * to a property.
-     * <p>
-     * If the xpath <a href='#matches_no_property_in_the_graph'>matches no
-     * properties in the graph</a> the behavior depends on the value that has
-     * been configured with {@link #setLenient(boolean)}:</p>
-     * <ul>
-     * <li> {@code false} (default) the method will throw a
-     * {@link JXPathNotFoundException}.
-     * <li> {@code true} the method returns a pointer whose
-     * {@link Pointer#getValue()} method will always return null.
-     * </ul>
-     *
-     * @param xpath desired
-     * @return Pointer A {@link Pointer}, never {@code null}.
-     * @throws JXPathNotFoundException see method description.
-     */
-    public abstract Pointer getPointer(String xpath);
-
     /**
      * Traverses the xpath and returns an Iterator of Pointers.
      * A Pointer provides easy access to a property.
@@ -822,130 +807,147 @@ public abstract class JXPathContext {
     public abstract Iterator<Pointer> iteratePointers(String xpath);
 
     /**
-     * Install an identity manager that will be used by the context
-     * to look up a node by its ID.
-     * @param idManager IdentityManager to set
+     * Registers a namespace prefix.
+     *
+     * @param prefix A namespace prefix
+     * @param namespaceURI A URI for that prefix
      */
-    public void setIdentityManager(final IdentityManager idManager) {
-        this.idManager = idManager;
+    public void registerNamespace(final String prefix, final String namespaceURI) {
+        throw new UnsupportedOperationException(
+                "Namespace registration is not implemented by " + getClass());
     }
 
     /**
-     * Returns this context's identity manager. If none has been installed,
-     * returns the identity manager of the parent context.
-     * @return IdentityManager
+     * Removes all elements of the object graph described by the xpath.
+     * @param xpath indicating positions to remove
      */
-    public IdentityManager getIdentityManager() {
-        if (idManager == null && parentContext != null) {
-            return parentContext.getIdentityManager();
+    public abstract void removeAll(String xpath);
+
+    /**
+     * Removes the element of the object graph described by the xpath.
+     * @param xpath indicating position to remove
+     */
+    public abstract void removePath(String xpath);
+
+    /**
+     * Finds all nodes that match the specified XPath.
+     *
+     * @param xpath the xpath to be evaluated
+     * @return a list of found objects
+     */
+    public List selectNodes(final String xpath) {
+        final ArrayList list = new ArrayList();
+        final Iterator<Pointer> iterator = iteratePointers(xpath);
+        while (iterator.hasNext()) {
+            final Pointer pointer = iterator.next();
+            list.add(pointer.getNode());
         }
-        return idManager;
+        return list;
     }
 
     /**
-     * Locates a Node by its ID.
+     * Finds the first object that matches the specified XPath. It is equivalent
+     * to {@code getPointer(xpath).getNode()}. Note that this method
+     * produces the same result as {@code getValue()} on object models
+     * like JavaBeans, but a different result for DOM/JDOM etc., because it
+     * returns the Node itself, rather than its textual contents.
      *
-     * @param id is the ID of the sought node.
-     * @return Pointer
+     * @param xpath the xpath to be evaluated
+     * @return the found object
      */
-    public Pointer getPointerByID(final String id) {
-        final IdentityManager manager = getIdentityManager();
-        if (manager != null) {
-            return manager.getPointerByID(this, id);
+    public Object selectSingleNode(final String xpath) {
+        final Pointer pointer = getPointer(xpath);
+        return pointer == null ? null : pointer.getNode();
+    }
+
+    /**
+     * Sets {@link DecimalFormatSymbols} for a given name. The DecimalFormatSymbols
+     * can be referenced as the third, optional argument in the invocation of
+     * {@code format-number (number,format,decimal-format-name)} function.
+     * By default, JXPath uses the symbols for the current locale.
+     *
+     * @param name the format name or null for default format.
+     * @param symbols DecimalFormatSymbols
+     */
+    public synchronized void setDecimalFormatSymbols(final String name,
+            final DecimalFormatSymbols symbols) {
+        if (decimalFormats == null) {
+            decimalFormats = new HashMap<>();
         }
-        throw new JXPathException(
-            "Cannot find an element by ID - "
-                + "no IdentityManager has been specified");
+        decimalFormats.put(name, symbols);
     }
 
     /**
-     * Install a key manager that will be used by the context
-     * to look up a node by a key value.
-     * @param keyManager KeyManager
+     * Sets the ExceptionHandler used by this context, if any.
+     * @param exceptionHandler to set
+     * @since 1.4
      */
-    public void setKeyManager(final KeyManager keyManager) {
-        this.keyManager = keyManager;
+    public void setExceptionHandler(final ExceptionHandler exceptionHandler) {
+        throw new UnsupportedOperationException(
+                "ExceptionHandler registration is not implemented by " + getClass());
     }
 
     /**
-     * Returns this context's key manager. If none has been installed,
-     * returns the key manager of the parent context.
-     * @return KeyManager
+     * Install an abstract factory that should be used by the
+     * {@code createPath()} and {@code createPathAndSetValue()}
+     * methods.
+     * @param factory AbstractFactory
      */
-    public KeyManager getKeyManager() {
-        if (keyManager == null && parentContext != null) {
-            return parentContext.getKeyManager();
-        }
-        return keyManager;
+    public void setFactory(final AbstractFactory factory) {
+        this.factory = factory;
     }
 
     /**
-     * Locates a Node by a key value.
-     * @param key string
-     * @param value string
-     * @return Pointer found
+     * Install a library of extension functions.
+     * @param functions Functions
+     * @see FunctionLibrary
      */
-    public Pointer getPointerByKey(final String key, final String value) {
-        final KeyManager manager = getKeyManager();
-        if (manager != null) {
-            return manager.getPointerByKey(this, key, value);
-        }
-        throw new JXPathException(
-            "Cannot find an element by key - "
-                + "no KeyManager has been specified");
+    public void setFunctions(final Functions functions) {
+        this.functions = functions;
     }
 
     /**
-     * Locates a NodeSet by key/value.
-     * @param key string
-     * @param value object
-     * @return NodeSet found
+     * Install an identity manager that will be used by the context
+     * to look up a node by its ID.
+     * @param idManager IdentityManager to set
      */
-    public NodeSet getNodeSetByKey(final String key, final Object value) {
-        final KeyManager manager = getKeyManager();
-        if (manager != null) {
-            return KeyManagerUtils.getExtendedKeyManager(manager)
-                    .getNodeSetByKey(this, key, value);
-        }
-        throw new JXPathException("Cannot find an element by key - "
-                + "no KeyManager has been specified");
+    public void setIdentityManager(final IdentityManager idManager) {
+        this.idManager = idManager;
     }
 
     /**
-     * Registers a namespace prefix.
-     *
-     * @param prefix A namespace prefix
-     * @param namespaceURI A URI for that prefix
+     * Install a key manager that will be used by the context
+     * to look up a node by a key value.
+     * @param keyManager KeyManager
      */
-    public void registerNamespace(final String prefix, final String namespaceURI) {
-        throw new UnsupportedOperationException(
-                "Namespace registration is not implemented by " + getClass());
+    public void setKeyManager(final KeyManager keyManager) {
+        this.keyManager = keyManager;
     }
 
     /**
-     * Given a prefix, returns a registered namespace URI. If the requested
-     * prefix was not defined explicitly using the registerNamespace method,
-     * JXPathContext will then check the context node to see if the prefix is
-     * defined there. See
-     * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer}.
-     *
-     * @param prefix The namespace prefix to look up
-     * @return namespace URI or null if the prefix is undefined.
+     * If the context is in the lenient mode, then getValue() returns null
+     * for inexistent paths.  Otherwise, a path that does not map to
+     * an existing property will throw an exception.  Note that if the
+     * property exists, but its value is null, the exception is <em>not</em>
+     * thrown.
+     * <p>
+     * By default, lenient = false
+     * @param lenient flag
      */
-    public String getNamespaceURI(final String prefix) {
-        throw new UnsupportedOperationException(
-                "Namespace registration is not implemented by " + getClass());
+    public synchronized void setLenient(final boolean lenient) {
+        this.lenient = lenient;
+        lenientSet = true;
     }
 
     /**
-     * Gets the prefix associated with the specifed namespace URI.
-     * @param namespaceURI the ns URI to check.
-     * @return String prefix
-     * @since JXPath 1.3
+     * Sets the locale for this context.  The value of the "lang"
+     * attribute as well as the lang() function will be
+     * affected by the locale.  By default, JXPath uses
+     * {@code Locale.getDefault()}
+     * @param locale Locale
      */
-    public String getPrefix(final String namespaceURI) {
-        throw new UnsupportedOperationException(
-                "Namespace registration is not implemented by " + getClass());
+    public synchronized void setLocale(final Locale locale) {
+        this.locale = locale;
     }
 
     /**
@@ -963,24 +965,22 @@ public abstract class JXPathContext {
     }
 
     /**
-     * Returns the namespace context pointer set with
-     * {@link #setNamespaceContextPointer(Pointer) setNamespaceContextPointer()}
-     * or, if none has been specified, the context pointer otherwise.
-     *
-     * @return The namespace context pointer.
+     * Modifies the value of the property described by the supplied xpath.
+     * Will throw an exception if one of the following conditions occurs:
+     * <ul>
+     * <li>The xpath does not in fact describe an existing property
+     * <li>The property is not writable (no public, non-static set method)
+     * </ul>
+     * @param xpath indicating position
+     * @param value to set
      */
-    public Pointer getNamespaceContextPointer() {
-        throw new UnsupportedOperationException(
-                "Namespace registration is not implemented by " + getClass());
-    }
+    public abstract void setValue(String xpath, Object value);
 
     /**
-     * Sets the ExceptionHandler used by this context, if any.
-     * @param exceptionHandler to set
-     * @since 1.4
+     * Installs a custom implementation of the Variables interface.
+     * @param vars Variables
      */
-    public void setExceptionHandler(final ExceptionHandler exceptionHandler) {
-        throw new UnsupportedOperationException(
-                "ExceptionHandler registration is not implemented by " + getClass());
+    public void setVariables(final Variables vars) {
+        this.vars = vars;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathContextFactory.java b/src/main/java/org/apache/commons/jxpath/JXPathContextFactory.java
index 395bdb4..db9dd03 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathContextFactory.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathContextFactory.java
@@ -55,82 +55,10 @@ public abstract class JXPathContextFactory {
     */
     private static final String FACTORY_IMPL_NAME = findFactory(FACTORY_NAME_PROPERTY, DEFAULT_FACTORY_CLASS);
 
-    /**
-     * Create a new JXPathContextFactory.
-     */
-    protected JXPathContextFactory () {
-
-    }
-
-    /**
-     * Obtain a new instance of a {@code JXPathContextFactory}.
-     * This static method creates a new factory instance.
-     * This method uses the following ordered lookup procedure to determine
-     * the {@code JXPathContextFactory} implementation class to load:
-     * <ul>
-     * <li>
-     * Use  the {@code org.apache.commons.jxpath.JXPathContextFactory}
-     * system property.
-     * </li>
-     * <li>
-     * Alternatively, use the JAVA_HOME (the parent directory where jdk is
-     * installed)/lib/jxpath.properties for a property file that contains the
-     * name of the implementation class keyed on
-     * {@code org.apache.commons.jxpath.JXPathContextFactory}.
-     * </li>
-     * <li>
-     * Use the Services API (as detailed in the JAR specification), if
-     * available, to determine the class name. The Services API will look
-     * for a class name in the file
-     * {@code META- INF/services/<i>org.apache.commons.jxpath.
-     * JXPathContextFactory</i>} in jars available to the runtime.
-     * </li>
-     * <li>
-     * Platform default {@code JXPathContextFactory} instance.
-     * </li>
-     * </ul>
-     *
-     * Once an application has obtained a reference to a
-     * {@code JXPathContextFactory} it can use the factory to
-     * obtain JXPathContext instances.
-     *
-     * @return JXPathContextFactory
-     * @throws JXPathContextFactoryConfigurationError if the implementation
-     *            is not available or cannot be instantiated.
-     */
-    public static JXPathContextFactory newInstance() {
-        JXPathContextFactory factoryImpl;
-        try {
-            final Class clazz = ClassLoaderUtil.getClass(FACTORY_IMPL_NAME, true);
-            factoryImpl = (JXPathContextFactory) clazz.getConstructor().newInstance();
-        }
-        catch (final ReflectiveOperationException ie) {
-            throw new JXPathContextFactoryConfigurationError(ie);
-        }
-        return factoryImpl;
-    }
-
-    /**
-     * Creates a new instance of a JXPathContext using the
-     * currently configured parameters.
-     * @param parentContext parent context
-     * @param contextBean Object bean
-     * @return JXPathContext
-     * @throws JXPathContextFactoryConfigurationError if a JXPathContext
-     *            cannot be created which satisfies the configuration requested
-     */
-
-    public abstract JXPathContext newContext(
-        JXPathContext parentContext,
-        Object contextBean);
-
-    // This code is duplicated in all factories.
-    // Keep it in sync or move it to a common place
-    // Because it's small probably it's easier to keep it here
-
     /** Temp debug code - this will be removed after we test everything
      */
     private static boolean debug = false;
+
     static {
         try {
             debug = System.getProperty("jxpath.debug") != null;
@@ -253,4 +181,76 @@ public abstract class JXPathContextFactory {
         }
         return defaultFactory;
     }
+
+    // This code is duplicated in all factories.
+    // Keep it in sync or move it to a common place
+    // Because it's small probably it's easier to keep it here
+
+    /**
+     * Obtain a new instance of a {@code JXPathContextFactory}.
+     * This static method creates a new factory instance.
+     * This method uses the following ordered lookup procedure to determine
+     * the {@code JXPathContextFactory} implementation class to load:
+     * <ul>
+     * <li>
+     * Use  the {@code org.apache.commons.jxpath.JXPathContextFactory}
+     * system property.
+     * </li>
+     * <li>
+     * Alternatively, use the JAVA_HOME (the parent directory where jdk is
+     * installed)/lib/jxpath.properties for a property file that contains the
+     * name of the implementation class keyed on
+     * {@code org.apache.commons.jxpath.JXPathContextFactory}.
+     * </li>
+     * <li>
+     * Use the Services API (as detailed in the JAR specification), if
+     * available, to determine the class name. The Services API will look
+     * for a class name in the file
+     * {@code META- INF/services/<i>org.apache.commons.jxpath.
+     * JXPathContextFactory</i>} in jars available to the runtime.
+     * </li>
+     * <li>
+     * Platform default {@code JXPathContextFactory} instance.
+     * </li>
+     * </ul>
+     *
+     * Once an application has obtained a reference to a
+     * {@code JXPathContextFactory} it can use the factory to
+     * obtain JXPathContext instances.
+     *
+     * @return JXPathContextFactory
+     * @throws JXPathContextFactoryConfigurationError if the implementation
+     *            is not available or cannot be instantiated.
+     */
+    public static JXPathContextFactory newInstance() {
+        JXPathContextFactory factoryImpl;
+        try {
+            final Class clazz = ClassLoaderUtil.getClass(FACTORY_IMPL_NAME, true);
+            factoryImpl = (JXPathContextFactory) clazz.getConstructor().newInstance();
+        }
+        catch (final ReflectiveOperationException ie) {
+            throw new JXPathContextFactoryConfigurationError(ie);
+        }
+        return factoryImpl;
+    }
+    /**
+     * Create a new JXPathContextFactory.
+     */
+    protected JXPathContextFactory () {
+
+    }
+
+    /**
+     * Creates a new instance of a JXPathContext using the
+     * currently configured parameters.
+     * @param parentContext parent context
+     * @param contextBean Object bean
+     * @return JXPathContext
+     * @throws JXPathContextFactoryConfigurationError if a JXPathContext
+     *            cannot be created which satisfies the configuration requested
+     */
+
+    public abstract JXPathContext newContext(
+        JXPathContext parentContext,
+        Object contextBean);
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java b/src/main/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java
index deeaf8a..d897d72 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathContextFactoryConfigurationError.java
@@ -36,17 +36,6 @@ public class JXPathContextFactoryConfigurationError extends Error {
          this.exception = null;
      }
 
-    /**
-     * Create a new {@code JXPathContextFactoryConfigurationError} with
-     * the {@code String } specified as an error message.
-     *
-     * @param msg The error message for the exception.
-     */
-    public JXPathContextFactoryConfigurationError(final String msg) {
-        super(msg);
-        this.exception = null;
-    }
-
     /**
      * Create a new {@code JXPathContextFactoryConfigurationError} with a
      * given {@code Exception} base cause of the error.
@@ -72,6 +61,27 @@ public class JXPathContextFactoryConfigurationError extends Error {
         this.exception = e;
     }
 
+    /**
+     * Create a new {@code JXPathContextFactoryConfigurationError} with
+     * the {@code String } specified as an error message.
+     *
+     * @param msg The error message for the exception.
+     */
+    public JXPathContextFactoryConfigurationError(final String msg) {
+        super(msg);
+        this.exception = null;
+    }
+
+    /**
+     * Gets the actual exception (if any) that caused this exception to
+     * be raised.
+     *
+     * @return The encapsulated exception, or null if there is none.
+     */
+    public Exception getException () {
+        return exception;
+    }
+
     /**
      * Gets the message (if any) for this error . If there is no
      * message for the exception and there is an encapsulated
@@ -87,14 +97,4 @@ public class JXPathContextFactoryConfigurationError extends Error {
         }
         return message;
     }
-
-    /**
-     * Gets the actual exception (if any) that caused this exception to
-     * be raised.
-     *
-     * @return The encapsulated exception, or null if there is none.
-     */
-    public Exception getException () {
-        return exception;
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathException.java b/src/main/java/org/apache/commons/jxpath/JXPathException.java
index 68e4c73..091d60f 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathException.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathException.java
@@ -46,6 +46,18 @@ public class JXPathException extends RuntimeException {
         this.exception = null;
     }
 
+    /**
+     * Create a new {@code JXPathException} with the
+     * given {@code Exception} base cause and detail message.
+     *
+     * @param msg The detail message.
+     * @param e The exception to be encapsulated in a JXPathException
+     */
+    public JXPathException(final String msg, final Throwable e) {
+        super(msg);
+        this.exception = e;
+    }
+
     /**
      * Create a new {@code JXPathException} with a
      * given {@code Throwable} base cause of the error.
@@ -59,15 +71,22 @@ public class JXPathException extends RuntimeException {
     }
 
     /**
-     * Create a new {@code JXPathException} with the
-     * given {@code Exception} base cause and detail message.
+     * Same as {@link #getException() getException()}
+     * @return The encapsulated exception, or null if there is none.
+     */
+    @Override
+    public Throwable getCause() {
+        return exception;
+    }
+
+    /**
+     * Gets the actual exception (if any) that caused this exception to
+     * be raised.
      *
-     * @param msg The detail message.
-     * @param e The exception to be encapsulated in a JXPathException
+     * @return The encapsulated exception, or null if there is none.
      */
-    public JXPathException(final String msg, final Throwable e) {
-        super(msg);
-        this.exception = e;
+    public Throwable getException() {
+        return exception;
     }
 
     /**
@@ -92,23 +111,4 @@ public class JXPathException extends RuntimeException {
         return buf.toString();
     }
 
-    /**
-     * Gets the actual exception (if any) that caused this exception to
-     * be raised.
-     *
-     * @return The encapsulated exception, or null if there is none.
-     */
-    public Throwable getException() {
-        return exception;
-    }
-
-    /**
-     * Same as {@link #getException() getException()}
-     * @return The encapsulated exception, or null if there is none.
-     */
-    @Override
-    public Throwable getCause() {
-        return exception;
-    }
-
 }
diff --git a/src/main/java/org/apache/commons/jxpath/JXPathIntrospector.java b/src/main/java/org/apache/commons/jxpath/JXPathIntrospector.java
index d2bc9b1..599af97 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathIntrospector.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathIntrospector.java
@@ -59,73 +59,6 @@ public class JXPathIntrospector {
         registerDynamicClass(Map.class, MapDynamicPropertyHandler.class);
     }
 
-    /**
-     * Automatically creates and registers a JXPathBeanInfo object
-     * for the specified class. That object returns true to isAtomic().
-     * @param beanClass to register
-     */
-    public static void registerAtomicClass(final Class beanClass) {
-        synchronized (byClass) {
-            byClass.put(beanClass, new JXPathBasicBeanInfo(beanClass, true));
-        }
-    }
-
-    /**
-     * Automatically creates and registers a {@link JXPathBeanInfo} object
-     * for the specified class. That object returns true to
-     * {@link JXPathBeanInfo#isDynamic()}.
-     *
-     * @param beanClass to register
-     * @param dynamicPropertyHandlerClass to handle beanClass
-     */
-    public static void registerDynamicClass(final Class beanClass,
-            final Class dynamicPropertyHandlerClass) {
-        final JXPathBasicBeanInfo bi =
-            new JXPathBasicBeanInfo(beanClass, dynamicPropertyHandlerClass);
-        if (beanClass.isInterface()) {
-            synchronized (byInterface) {
-                byInterface.put(beanClass, bi);
-            }
-        }
-        else {
-            synchronized (byClass) {
-                byClass.put(beanClass, bi);
-            }
-        }
-    }
-
-    /**
-     * Creates and registers a JXPathBeanInfo object for the supplied class. If
-     * the class has already been registered, returns the registered
-     * JXPathBeanInfo object.
-     * <p>
-     * The process of creation of JXPathBeanInfo is as follows:
-     * <ul>
-     * <li>If class named {@code <beanClass>XBeanInfo} exists,
-     *     an instance of that class is allocated.
-     * <li>Otherwise, an instance of {@link JXPathBasicBeanInfo
-     *     JXPathBasicBeanInfo}  is allocated.
-     * </ul>
-     * @param beanClass whose info to get
-     * @return JXPathBeanInfo
-     */
-    public static JXPathBeanInfo getBeanInfo(final Class beanClass) {
-        JXPathBeanInfo beanInfo = (JXPathBeanInfo) byClass.get(beanClass);
-        if (beanInfo == null) {
-            beanInfo = findDynamicBeanInfo(beanClass);
-            if (beanInfo == null) {
-                beanInfo = findInformant(beanClass);
-                if (beanInfo == null) {
-                    beanInfo = new JXPathBasicBeanInfo(beanClass);
-                }
-            }
-            synchronized (byClass) {
-                byClass.put(beanClass, beanInfo);
-            }
-        }
-        return beanInfo;
-    }
-
     /**
      * Find a dynamic bean info if available for any superclasses or
      * interfaces.
@@ -193,6 +126,38 @@ public class JXPathIntrospector {
         return null;
     }
 
+    /**
+     * Creates and registers a JXPathBeanInfo object for the supplied class. If
+     * the class has already been registered, returns the registered
+     * JXPathBeanInfo object.
+     * <p>
+     * The process of creation of JXPathBeanInfo is as follows:
+     * <ul>
+     * <li>If class named {@code <beanClass>XBeanInfo} exists,
+     *     an instance of that class is allocated.
+     * <li>Otherwise, an instance of {@link JXPathBasicBeanInfo
+     *     JXPathBasicBeanInfo}  is allocated.
+     * </ul>
+     * @param beanClass whose info to get
+     * @return JXPathBeanInfo
+     */
+    public static JXPathBeanInfo getBeanInfo(final Class beanClass) {
+        JXPathBeanInfo beanInfo = (JXPathBeanInfo) byClass.get(beanClass);
+        if (beanInfo == null) {
+            beanInfo = findDynamicBeanInfo(beanClass);
+            if (beanInfo == null) {
+                beanInfo = findInformant(beanClass);
+                if (beanInfo == null) {
+                    beanInfo = new JXPathBasicBeanInfo(beanClass);
+                }
+            }
+            synchronized (byClass) {
+                byClass.put(beanClass, beanInfo);
+            }
+        }
+        return beanInfo;
+    }
+
     /**
      * Try to create an instance of a named class.
      * First try the classloader of "sibling", then try the system
@@ -221,4 +186,39 @@ public class JXPathIntrospector {
         final Class cls = ClassLoaderUtil.getClass(className);
         return cls.newInstance();
     }
+
+    /**
+     * Automatically creates and registers a JXPathBeanInfo object
+     * for the specified class. That object returns true to isAtomic().
+     * @param beanClass to register
+     */
+    public static void registerAtomicClass(final Class beanClass) {
+        synchronized (byClass) {
+            byClass.put(beanClass, new JXPathBasicBeanInfo(beanClass, true));
+        }
+    }
+
+    /**
+     * Automatically creates and registers a {@link JXPathBeanInfo} object
+     * for the specified class. That object returns true to
+     * {@link JXPathBeanInfo#isDynamic()}.
+     *
+     * @param beanClass to register
+     * @param dynamicPropertyHandlerClass to handle beanClass
+     */
+    public static void registerDynamicClass(final Class beanClass,
+            final Class dynamicPropertyHandlerClass) {
+        final JXPathBasicBeanInfo bi =
+            new JXPathBasicBeanInfo(beanClass, dynamicPropertyHandlerClass);
+        if (beanClass.isInterface()) {
+            synchronized (byInterface) {
+                byInterface.put(beanClass, bi);
+            }
+        }
+        else {
+            synchronized (byClass) {
+                byClass.put(beanClass, bi);
+            }
+        }
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java b/src/main/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java
index fb51952..c13a439 100644
--- a/src/main/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java
+++ b/src/main/java/org/apache/commons/jxpath/MapDynamicPropertyHandler.java
@@ -25,6 +25,11 @@ import java.util.Set;
  */
 public class MapDynamicPropertyHandler implements DynamicPropertyHandler {
 
+    @Override
+    public Object getProperty(final Object object, final String propertyName) {
+        return ((Map) object).get(propertyName);
+    }
+
     @Override
     public String[] getPropertyNames(final Object object) {
         final Map map = (Map) object;
@@ -37,11 +42,6 @@ public class MapDynamicPropertyHandler implements DynamicPropertyHandler {
         return names;
     }
 
-    @Override
-    public Object getProperty(final Object object, final String propertyName) {
-        return ((Map) object).get(propertyName);
-    }
-
     @Override
     public void setProperty(final Object object, final String propertyName, final Object value) {
         ((Map) object).put(propertyName, value);
diff --git a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java
index c2e14b5..298d5d4 100644
--- a/src/main/java/org/apache/commons/jxpath/PackageFunctions.java
+++ b/src/main/java/org/apache/commons/jxpath/PackageFunctions.java
@@ -67,9 +67,9 @@ import org.apache.commons.jxpath.util.TypeUtils;
  * </p>
  */
 public class PackageFunctions implements Functions {
+    private static final Object[] EMPTY_ARRAY = {};
     private final String classPrefix;
     private final String namespace;
-    private static final Object[] EMPTY_ARRAY = {};
 
     /**
      * Create a new PackageFunctions.
@@ -81,15 +81,6 @@ public class PackageFunctions implements Functions {
         this.namespace = namespace;
     }
 
-    /**
-     * Returns the namespace specified in the constructor
-     * @return (singleton) namespace Set
-     */
-    @Override
-    public Set getUsedNamespaces() {
-        return Collections.singleton(namespace);
-    }
-
     /**
      * Returns a {@link Function}, if found, for the specified namespace,
      * name and parameter types.
@@ -213,4 +204,13 @@ public class PackageFunctions implements Functions {
         }
         return null;
     }
+
+    /**
+     * Returns the namespace specified in the constructor
+     * @return (singleton) namespace Set
+     */
+    @Override
+    public Set getUsedNamespaces() {
+        return Collections.singleton(namespace);
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/Pointer.java b/src/main/java/org/apache/commons/jxpath/Pointer.java
index a467c07..654d655 100644
--- a/src/main/java/org/apache/commons/jxpath/Pointer.java
+++ b/src/main/java/org/apache/commons/jxpath/Pointer.java
@@ -35,16 +35,25 @@ import java.io.Serializable;
 public interface Pointer extends Cloneable, Comparable, Serializable {
 
     /**
-     * Returns the value of the object, property or collection element
-     * this pointer represents. May convert the value to one of the
-     * canonical InfoSet types: String, Number, Boolean, Set.
-     *
-     * For example, in the case of an XML element, getValue() will
-     * return the text contained by the element rather than
-     * the element itself.
-     * @return Object value
+     * Returns a string that is a proper "canonical" XPath that corresponds to
+     * this pointer.  Consider this example:
+     * <p>{@code Pointer  ptr = ctx.getPointer("//employees[firstName = 'John']")
+     * }
+     * <p>The  value of {@code ptr.asPath()} will look something like
+     * {@code "/departments[2]/employees[3]"}, so, basically, it represents
+     * the concrete location(s) of the result of a search performed by JXPath.
+     * If an object in the pointer's path is a Dynamic Property object (like a
+     * Map), the asPath method generates an XPath that looks like this: {@code "
+     * /departments[@name = 'HR']/employees[3]"}.
+     * @return String path
      */
-    Object getValue();
+    String asPath();
+
+    /**
+     * Pointers are cloneable.
+     * @return cloned Object
+     */
+    Object clone();
 
     /**
      * Returns the raw value of the object, property or collection element
@@ -57,13 +66,6 @@ public interface Pointer extends Cloneable, Comparable, Serializable {
      */
     Object getNode();
 
-    /**
-     * Modifies the value of the object, property or collection element
-     * this pointer represents.
-     * @param value value to set
-     */
-    void setValue(Object value);
-
     /**
      * Returns the node this pointer is based on.
      * @return Object
@@ -71,23 +73,21 @@ public interface Pointer extends Cloneable, Comparable, Serializable {
     Object getRootNode();
 
     /**
-     * Returns a string that is a proper "canonical" XPath that corresponds to
-     * this pointer.  Consider this example:
-     * <p>{@code Pointer  ptr = ctx.getPointer("//employees[firstName = 'John']")
-     * }
-     * <p>The  value of {@code ptr.asPath()} will look something like
-     * {@code "/departments[2]/employees[3]"}, so, basically, it represents
-     * the concrete location(s) of the result of a search performed by JXPath.
-     * If an object in the pointer's path is a Dynamic Property object (like a
-     * Map), the asPath method generates an XPath that looks like this: {@code "
-     * /departments[@name = 'HR']/employees[3]"}.
-     * @return String path
+     * Returns the value of the object, property or collection element
+     * this pointer represents. May convert the value to one of the
+     * canonical InfoSet types: String, Number, Boolean, Set.
+     *
+     * For example, in the case of an XML element, getValue() will
+     * return the text contained by the element rather than
+     * the element itself.
+     * @return Object value
      */
-    String asPath();
+    Object getValue();
 
     /**
-     * Pointers are cloneable.
-     * @return cloned Object
+     * Modifies the value of the object, property or collection element
+     * this pointer represents.
+     * @param value value to set
      */
-    Object clone();
+    void setValue(Object value);
 }
diff --git a/src/main/java/org/apache/commons/jxpath/Variables.java b/src/main/java/org/apache/commons/jxpath/Variables.java
index 6f0280e..75122fb 100644
--- a/src/main/java/org/apache/commons/jxpath/Variables.java
+++ b/src/main/java/org/apache/commons/jxpath/Variables.java
@@ -27,11 +27,13 @@ import java.io.Serializable;
 public interface Variables extends Serializable {
 
     /**
-     * Returns true if the specified variable is declared.
+     * Defines a new variable with the specified value or modifies
+     * the value of an existing variable.
+     * May throw UnsupportedOperationException.
      * @param varName variable name
-     * @return boolean
+     * @param value to declare
      */
-    boolean isDeclaredVariable(String varName);
+    void declareVariable(String varName, Object value);
 
     /**
      * Returns the value of the specified variable.
@@ -42,13 +44,11 @@ public interface Variables extends Serializable {
     Object getVariable(String varName);
 
     /**
-     * Defines a new variable with the specified value or modifies
-     * the value of an existing variable.
-     * May throw UnsupportedOperationException.
+     * Returns true if the specified variable is declared.
      * @param varName variable name
-     * @param value to declare
+     * @return boolean
      */
-    void declareVariable(String varName, Object value);
+    boolean isDeclaredVariable(String varName);
 
     /**
      * Removes an existing variable. May throw UnsupportedOperationException.
diff --git a/src/main/java/org/apache/commons/jxpath/XMLDocumentContainer.java b/src/main/java/org/apache/commons/jxpath/XMLDocumentContainer.java
index 0079d72..e9b4602 100644
--- a/src/main/java/org/apache/commons/jxpath/XMLDocumentContainer.java
+++ b/src/main/java/org/apache/commons/jxpath/XMLDocumentContainer.java
@@ -49,20 +49,20 @@ public class XMLDocumentContainer implements Container {
 
     /**
      * Create a new XMLDocumentContainer.
-     * @param xmlURL a URL for an XML file. Use getClass().getResource(resourceName)
-     *               to load XML from a resource file.
+     * @param source XML source
      */
-    public XMLDocumentContainer(final URL xmlURL) {
-        this.xmlURL = xmlURL;
-        delegate = new DocumentContainer(xmlURL);
+    public XMLDocumentContainer(final Source source) {
+        this.source = Objects.requireNonNull(source);
     }
 
     /**
      * Create a new XMLDocumentContainer.
-     * @param source XML source
+     * @param xmlURL a URL for an XML file. Use getClass().getResource(resourceName)
+     *               to load XML from a resource file.
      */
-    public XMLDocumentContainer(final Source source) {
-        this.source = Objects.requireNonNull(source);
+    public XMLDocumentContainer(final URL xmlURL) {
+        this.xmlURL = xmlURL;
+        delegate = new DocumentContainer(xmlURL);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/jxpath/functions/MethodFunction.java b/src/main/java/org/apache/commons/jxpath/functions/MethodFunction.java
index 28dd87d..64b0b9f 100644
--- a/src/main/java/org/apache/commons/jxpath/functions/MethodFunction.java
+++ b/src/main/java/org/apache/commons/jxpath/functions/MethodFunction.java
@@ -31,8 +31,8 @@ import org.apache.commons.jxpath.util.ValueUtils;
  */
 public class MethodFunction implements Function {
 
-    private final Method method;
     private static final Object[] EMPTY_ARRAY = {};
+    private final Method method;
 
     /**
      * Create a new MethodFunction.
diff --git a/src/main/java/org/apache/commons/jxpath/ri/Compiler.java b/src/main/java/org/apache/commons/jxpath/ri/Compiler.java
index bfe2868..d34c1f3 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/Compiler.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/Compiler.java
@@ -97,93 +97,66 @@ public interface Compiler {
     int FUNCTION_ENDS_WITH = 31;
 
     /**
-     * Produces an EXPRESSION object that represents a numeric constant.
-     * @param value numeric String
-     * @return Object
-     */
-    Object number(String value);
-
-    /**
-     * Produces an EXPRESSION object that represents a string constant.
-     * @param value String literal
-     * @return Object
-     */
-    Object literal(String value);
-
-    /**
-     * Produces an QNAME that represents a name with an optional prefix.
-     * @param prefix String prefix
-     * @param name String name
-     * @return Object
-     */
-    Object qname(String prefix, String name);
-
-    /**
-     * Produces an EXPRESSION object representing the sum of all argumens
+     * Produces an EXPRESSION object representing logical conjunction of
+     * all arguments
      *
      * @param arguments are EXPRESSION objects
      * @return Object
      */
-    Object sum(Object[] arguments);
-
-    /**
-     * Produces an EXPRESSION object representing <em>left</em> minus <em>right</em>
-     *
-     * @param left is an EXPRESSION object
-     * @param right is an EXPRESSION object
-     * @return Object
-     */
-    Object minus(Object left, Object right);
+    Object and(Object[] arguments);
 
     /**
-     * Produces  an EXPRESSION object representing <em>left</em> multiplied by
+     * Produces  an EXPRESSION object representing <em>left</em> divided by
      * <em>right</em>
      *
      * @param left is an EXPRESSION object
      * @param right is an EXPRESSION object
      * @return Object
      */
-    Object multiply(Object left, Object right);
+    Object divide(Object left, Object right);
 
     /**
-     * Produces  an EXPRESSION object representing <em>left</em> divided by
-     * <em>right</em>
+     * Produces an EXPRESSION object representing the comparison:
+     * <em>left</em> equals to <em>right</em>
      *
      * @param left is an EXPRESSION object
      * @param right is an EXPRESSION object
      * @return Object
      */
-    Object divide(Object left, Object right);
+    Object equal(Object left, Object right);
 
     /**
-     * Produces  an EXPRESSION object representing <em>left</em> modulo
-     * <em>right</em>
+     * Produces an EXPRESSION object representing a filter expression
      *
-     * @param left is an EXPRESSION object
-     * @param right is an EXPRESSION object
+     * @param expression is an EXPRESSION object
+     * @param predicates are EXPRESSION objects
+     * @param steps are STEP objects
      * @return Object
      */
-    Object mod(Object left, Object right);
+    Object expressionPath(
+        Object expression,
+        Object[] predicates,
+        Object[] steps);
 
     /**
-     * Produces an EXPRESSION object representing the comparison:
-     * <em>left</em> less than <em>right</em>
+     * Produces an EXPRESSION object representing the computation of
+     * a core function with the supplied arguments.
      *
-     * @param left is an EXPRESSION object
-     * @param right is an EXPRESSION object
+     * @param code is one of FUNCTION_... constants
+     * @param args are EXPRESSION objects
      * @return Object
      */
-    Object lessThan(Object left, Object right);
+    Object function(int code, Object[] args);
 
     /**
-     * Produces an EXPRESSION object representing the comparison:
-     * <em>left</em> less than or equal to <em>right</em>
+     * Produces an EXPRESSION object representing the computation of
+     * a library function with the supplied arguments.
      *
-     * @param left is an EXPRESSION object
-     * @param right is an EXPRESSION object
+     * @param name is a QNAME object (function name)
+     * @param args are EXPRESSION objects
      * @return Object
      */
-    Object lessThanOrEqual(Object left, Object right);
+    Object function(Object name, Object[] args);
 
     /**
      * Produces an EXPRESSION object representing the comparison:
@@ -207,23 +180,39 @@ public interface Compiler {
 
     /**
      * Produces an EXPRESSION object representing the comparison:
-     * <em>left</em> equals to <em>right</em>
+     * <em>left</em> less than <em>right</em>
      *
      * @param left is an EXPRESSION object
      * @param right is an EXPRESSION object
      * @return Object
      */
-    Object equal(Object left, Object right);
+    Object lessThan(Object left, Object right);
 
     /**
      * Produces an EXPRESSION object representing the comparison:
-     * <em>left</em> is not equal to <em>right</em>
+     * <em>left</em> less than or equal to <em>right</em>
      *
      * @param left is an EXPRESSION object
      * @param right is an EXPRESSION object
      * @return Object
      */
-    Object notEqual(Object left, Object right);
+    Object lessThanOrEqual(Object left, Object right);
+
+    /**
+     * Produces an EXPRESSION object that represents a string constant.
+     * @param value String literal
+     * @return Object
+     */
+    Object literal(String value);
+
+    /**
+     * Produces an EXPRESSION object representing a location path
+     *
+     * @param absolute indicates whether the path is absolute
+     * @param steps are STEP objects
+     * @return Object
+     */
+    Object locationPath(boolean absolute, Object[] steps);
 
     /**
      * Produces an EXPRESSION object representing unary negation of the argument
@@ -234,74 +223,75 @@ public interface Compiler {
     Object minus(Object argument);
 
     /**
-     * Produces an EXPRESSION object representing variable reference
+     * Produces an EXPRESSION object representing <em>left</em> minus <em>right</em>
      *
-     * @param qname is a QNAME object
+     * @param left is an EXPRESSION object
+     * @param right is an EXPRESSION object
      * @return Object
      */
-    Object variableReference(Object qname);
+    Object minus(Object left, Object right);
 
     /**
-     * Produces an EXPRESSION object representing the computation of
-     * a core function with the supplied arguments.
+     * Produces  an EXPRESSION object representing <em>left</em> modulo
+     * <em>right</em>
      *
-     * @param code is one of FUNCTION_... constants
-     * @param args are EXPRESSION objects
+     * @param left is an EXPRESSION object
+     * @param right is an EXPRESSION object
      * @return Object
      */
-    Object function(int code, Object[] args);
+    Object mod(Object left, Object right);
 
     /**
-     * Produces an EXPRESSION object representing the computation of
-     * a library function with the supplied arguments.
+     * Produces  an EXPRESSION object representing <em>left</em> multiplied by
+     * <em>right</em>
      *
-     * @param name is a QNAME object (function name)
-     * @param args are EXPRESSION objects
+     * @param left is an EXPRESSION object
+     * @param right is an EXPRESSION object
      * @return Object
      */
-    Object function(Object name, Object[] args);
+    Object multiply(Object left, Object right);
 
     /**
-     * Produces an EXPRESSION object representing logical conjunction of
-     * all arguments
+     * Produces a NODE_TEST object that represents a node name test.
      *
-     * @param arguments are EXPRESSION objects
+     * @param qname is a QNAME object
      * @return Object
      */
-    Object and(Object[] arguments);
+    Object nodeNameTest(Object qname);
 
     /**
-     * Produces an EXPRESSION object representing logical disjunction of
-     * all arguments
+     * Produces a NODE_TEST object that represents a node type test.
      *
-     * @param arguments are EXPRESSION objects
+     * @param nodeType is a NODE_TEST object
      * @return Object
      */
-    Object or(Object[] arguments);
+    Object nodeTypeTest(int nodeType);
 
     /**
-     * Produces an EXPRESSION object representing union of all node sets
+     * Produces an EXPRESSION object representing the comparison:
+     * <em>left</em> is not equal to <em>right</em>
      *
-     * @param arguments are EXPRESSION objects
+     * @param left is an EXPRESSION object
+     * @param right is an EXPRESSION object
      * @return Object
      */
-    Object union(Object[] arguments);
+    Object notEqual(Object left, Object right);
 
     /**
-     * Produces a NODE_TEST object that represents a node name test.
-     *
-     * @param qname is a QNAME object
+     * Produces an EXPRESSION object that represents a numeric constant.
+     * @param value numeric String
      * @return Object
      */
-    Object nodeNameTest(Object qname);
+    Object number(String value);
 
     /**
-     * Produces a NODE_TEST object that represents a node type test.
+     * Produces an EXPRESSION object representing logical disjunction of
+     * all arguments
      *
-     * @param nodeType is a NODE_TEST object
+     * @param arguments are EXPRESSION objects
      * @return Object
      */
-    Object nodeTypeTest(int nodeType);
+    Object or(Object[] arguments);
 
     /**
      * Produces  a NODE_TEST object that represents a processing instruction
@@ -312,6 +302,14 @@ public interface Compiler {
      */
     Object processingInstructionTest(String instruction);
 
+    /**
+     * Produces an QNAME that represents a name with an optional prefix.
+     * @param prefix String prefix
+     * @param name String name
+     * @return Object
+     */
+    Object qname(String prefix, String name);
+
     /**
      * Produces a STEP object that represents a node test.
      *
@@ -323,24 +321,26 @@ public interface Compiler {
     Object step(int axis, Object nodeTest, Object[] predicates);
 
     /**
-     * Produces an EXPRESSION object representing a location path
+     * Produces an EXPRESSION object representing the sum of all argumens
      *
-     * @param absolute indicates whether the path is absolute
-     * @param steps are STEP objects
+     * @param arguments are EXPRESSION objects
      * @return Object
      */
-    Object locationPath(boolean absolute, Object[] steps);
+    Object sum(Object[] arguments);
 
     /**
-     * Produces an EXPRESSION object representing a filter expression
+     * Produces an EXPRESSION object representing union of all node sets
      *
-     * @param expression is an EXPRESSION object
-     * @param predicates are EXPRESSION objects
-     * @param steps are STEP objects
+     * @param arguments are EXPRESSION objects
      * @return Object
      */
-    Object expressionPath(
-        Object expression,
-        Object[] predicates,
-        Object[] steps);
+    Object union(Object[] arguments);
+
+    /**
+     * Produces an EXPRESSION object representing variable reference
+     *
+     * @param qname is a QNAME object
+     * @return Object
+     */
+    Object variableReference(Object qname);
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/EvalContext.java b/src/main/java/org/apache/commons/jxpath/ri/EvalContext.java
index 49ce884..6dec94e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/EvalContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/EvalContext.java
@@ -63,116 +63,6 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         this.parentContext = parentContext;
     }
 
-    @Override
-    public Pointer getContextNodePointer() {
-        return getCurrentNodePointer();
-    }
-
-    @Override
-    public JXPathContext getJXPathContext() {
-        return getRootContext().getJXPathContext();
-    }
-
-    @Override
-    public int getPosition() {
-        return position;
-    }
-
-    /**
-     * Determines the document order for this context.
-     *
-     * @return 1 ascending order, -1 descending order,
-     *  0 - does not require ordering
-     */
-    public int getDocumentOrder() {
-        return parentContext != null && parentContext.isChildOrderingRequired() ? 1 : 0;
-    }
-
-    /**
-     * Even if this context has the natural ordering and therefore does
-     * not require collecting and sorting all nodes prior to returning them,
-     * such operation may be required for any child context.
-     * @return boolean
-     */
-    public boolean isChildOrderingRequired() {
-        // Default behavior: if this context needs to be ordered,
-        // the children need to be ordered too
-        return getDocumentOrder() != 0;
-    }
-
-    /**
-     * Returns true if there are mode nodes matching the context's constraints.
-     * @return boolean
-     */
-    @Override
-    public boolean hasNext() {
-        if (pointerIterator != null) {
-            return pointerIterator.hasNext();
-        }
-        if (getDocumentOrder() != 0) {
-            return constructIterator();
-        }
-        if (!done && !hasPerformedIteratorStep) {
-            performIteratorStep();
-        }
-        return !done;
-    }
-
-    /**
-     * Returns the next node pointer in the context
-     * @return Object
-     */
-    @Override
-    public Object next() {
-        if (pointerIterator != null) {
-            return pointerIterator.next();
-        }
-
-        if (getDocumentOrder() != 0) {
-            if (!constructIterator()) {
-                throw new NoSuchElementException();
-            }
-            return pointerIterator.next();
-        }
-        if (!done && !hasPerformedIteratorStep) {
-            performIteratorStep();
-        }
-        if (done) {
-            throw new NoSuchElementException();
-        }
-        hasPerformedIteratorStep = false;
-        return getCurrentNodePointer();
-    }
-
-    /**
-     * Moves the iterator forward by one position
-     */
-    private void performIteratorStep() {
-        done = true;
-        if (position != 0 && nextNode()) {
-            done = false;
-        }
-        else {
-            while (nextSet()) {
-                if (nextNode()) {
-                    done = false;
-                    break;
-                }
-            }
-        }
-        hasPerformedIteratorStep = true;
-    }
-
-    /**
-     * Operation is not supported
-     * @throws UnsupportedOperationException Always thrown.
-     */
-    @Override
-    public void remove() {
-        throw new UnsupportedOperationException(
-            "JXPath iterators cannot remove nodes");
-    }
-
     /**
      * Constructs an iterator.
      * @return whether the Iterator was constructed
@@ -199,23 +89,6 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         return true;
     }
 
-    /**
-     * Sort a list of pointers based on document order.
-     * @param l the list to sort.
-     */
-    protected void sortPointers(final List l) {
-        switch (getDocumentOrder()) {
-        case 1:
-            Collections.sort(l);
-            break;
-        case -1:
-            Collections.sort(l, ReverseComparator.INSTANCE);
-            break;
-        default:
-            break;
-        }
-    }
-
     /**
      * Returns the list of all Pointers in this context for the current
      * position of the parent context.
@@ -240,6 +113,41 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         return list;
     }
 
+    @Override
+    public Pointer getContextNodePointer() {
+        return getCurrentNodePointer();
+    }
+
+    /**
+     * Returns the current context node. Undefined before the beginning
+     * of the iteration.
+     * @return NodePoiner
+     */
+    public abstract NodePointer getCurrentNodePointer();
+
+    /**
+     * Gets the current position.
+     * @return int position.
+     */
+    public int getCurrentPosition() {
+        return position;
+    }
+
+    /**
+     * Determines the document order for this context.
+     *
+     * @return 1 ascending order, -1 descending order,
+     *  0 - does not require ordering
+     */
+    public int getDocumentOrder() {
+        return parentContext != null && parentContext.isChildOrderingRequired() ? 1 : 0;
+    }
+
+    @Override
+    public JXPathContext getJXPathContext() {
+        return getRootContext().getJXPathContext();
+    }
+
     /**
      * Returns the list of all Pointers in this context for all positions
      * of the parent contexts.  If there was an ongoing iteration over
@@ -263,21 +171,9 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         return set;
     }
 
-    /**
-     * Typically returns the NodeSet by calling getNodeSet(),
-     * but will be overridden for contexts that more naturally produce
-     * individual values, e.g. VariableContext
-     * @return Object
-     */
-    public Object getValue() {
-        return getNodeSet();
-    }
-
     @Override
-    public String toString() {
-        final Pointer ptr = getContextNodePointer();
-        return ptr == null ? "Empty expression context" : "Expression context [" + getPosition()
-                + "] " + ptr.asPath();
+    public int getPosition() {
+        return position;
     }
 
     /**
@@ -292,21 +188,6 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         return rootContext;
     }
 
-    /**
-     * Sets current position = 0, which is the pre-iteration state.
-     */
-    public void reset() {
-        position = 0;
-    }
-
-    /**
-     * Gets the current position.
-     * @return int position.
-     */
-    public int getCurrentPosition() {
-        return position;
-    }
-
     /**
      * Returns the first encountered Pointer that matches the current
      * context's criteria.
@@ -323,11 +204,77 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
     }
 
     /**
-     * Returns the current context node. Undefined before the beginning
-     * of the iteration.
-     * @return NodePoiner
+     * Typically returns the NodeSet by calling getNodeSet(),
+     * but will be overridden for contexts that more naturally produce
+     * individual values, e.g. VariableContext
+     * @return Object
      */
-    public abstract NodePointer getCurrentNodePointer();
+    public Object getValue() {
+        return getNodeSet();
+    }
+
+    /**
+     * Returns true if there are mode nodes matching the context's constraints.
+     * @return boolean
+     */
+    @Override
+    public boolean hasNext() {
+        if (pointerIterator != null) {
+            return pointerIterator.hasNext();
+        }
+        if (getDocumentOrder() != 0) {
+            return constructIterator();
+        }
+        if (!done && !hasPerformedIteratorStep) {
+            performIteratorStep();
+        }
+        return !done;
+    }
+
+    /**
+     * Even if this context has the natural ordering and therefore does
+     * not require collecting and sorting all nodes prior to returning them,
+     * such operation may be required for any child context.
+     * @return boolean
+     */
+    public boolean isChildOrderingRequired() {
+        // Default behavior: if this context needs to be ordered,
+        // the children need to be ordered too
+        return getDocumentOrder() != 0;
+    }
+
+    /**
+     * Returns the next node pointer in the context
+     * @return Object
+     */
+    @Override
+    public Object next() {
+        if (pointerIterator != null) {
+            return pointerIterator.next();
+        }
+
+        if (getDocumentOrder() != 0) {
+            if (!constructIterator()) {
+                throw new NoSuchElementException();
+            }
+            return pointerIterator.next();
+        }
+        if (!done && !hasPerformedIteratorStep) {
+            performIteratorStep();
+        }
+        if (done) {
+            throw new NoSuchElementException();
+        }
+        hasPerformedIteratorStep = false;
+        return getCurrentNodePointer();
+    }
+
+    /**
+     * Returns true if there is another object in the current set.
+     * Switches the current position and node to the next object.
+     * @return boolean
+     */
+    public abstract boolean nextNode();
 
     /**
      * Returns true if there is another sets of objects to interate over.
@@ -367,11 +314,40 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
     }
 
     /**
-     * Returns true if there is another object in the current set.
-     * Switches the current position and node to the next object.
-     * @return boolean
+     * Moves the iterator forward by one position
      */
-    public abstract boolean nextNode();
+    private void performIteratorStep() {
+        done = true;
+        if (position != 0 && nextNode()) {
+            done = false;
+        }
+        else {
+            while (nextSet()) {
+                if (nextNode()) {
+                    done = false;
+                    break;
+                }
+            }
+        }
+        hasPerformedIteratorStep = true;
+    }
+
+    /**
+     * Operation is not supported
+     * @throws UnsupportedOperationException Always thrown.
+     */
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException(
+            "JXPath iterators cannot remove nodes");
+    }
+
+    /**
+     * Sets current position = 0, which is the pre-iteration state.
+     */
+    public void reset() {
+        position = 0;
+    }
 
     /**
      * Moves the current position to the specified index. Used with integer
@@ -385,4 +361,28 @@ public abstract class EvalContext implements ExpressionContext, Iterator {
         this.position = position;
         return true;
     }
+
+    /**
+     * Sort a list of pointers based on document order.
+     * @param l the list to sort.
+     */
+    protected void sortPointers(final List l) {
+        switch (getDocumentOrder()) {
+        case 1:
+            Collections.sort(l);
+            break;
+        case -1:
+            Collections.sort(l, ReverseComparator.INSTANCE);
+            break;
+        default:
+            break;
+        }
+    }
+
+    @Override
+    public String toString() {
+        final Pointer ptr = getContextNodePointer();
+        return ptr == null ? "Empty expression context" : "Expression context [" + getPosition()
+                + "] " + ptr.asPath();
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/InfoSetUtil.java b/src/main/java/org/apache/commons/jxpath/ri/InfoSetUtil.java
index b50e051..8e9a6a9 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/InfoSetUtil.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/InfoSetUtil.java
@@ -30,65 +30,36 @@ public class InfoSetUtil {
     private static final Double NOT_A_NUMBER = Double.valueOf(Double.NaN);
 
     /**
-     * Converts the supplied object to String.
+     * Converts the supplied object to boolean.
      * @param object to convert
-     * @return String value
+     * @return boolean
      */
-    public static String stringValue(final Object object) {
-        if (object instanceof String) {
-            return (String) object;
-        }
+    public static boolean booleanValue(final Object object) {
         if (object instanceof Number) {
-            final double d = ((Number) object).doubleValue();
-            final long l = ((Number) object).longValue();
-            return d == l ? String.valueOf(l) : String.valueOf(d);
+            final double value = ((Number) object).doubleValue();
+            final int negZero = -0;
+            return value != 0 && value != negZero && !Double.isNaN(value);
         }
         if (object instanceof Boolean) {
-            return ((Boolean) object).booleanValue() ? "true" : "false";
-        }
-        if (object == null) {
-            return "";
-        }
-        if (object instanceof NodePointer) {
-            return stringValue(((NodePointer) object).getValue());
+            return ((Boolean) object).booleanValue();
         }
         if (object instanceof EvalContext) {
             final EvalContext ctx = (EvalContext) object;
             final Pointer ptr = ctx.getSingleNodePointer();
-            return ptr == null ? "" : stringValue(ptr);
-        }
-        return String.valueOf(object);
-    }
-
-    /**
-     * Converts the supplied object to Number.
-     * @param object to convert
-     * @return Number result
-     */
-    public static Number number(final Object object) {
-        if (object instanceof Number) {
-            return (Number) object;
-        }
-        if (object instanceof Boolean) {
-            return ((Boolean) object).booleanValue() ? ONE : ZERO;
+            return ptr != null && booleanValue(ptr);
         }
         if (object instanceof String) {
-            try {
-                return Double.valueOf((String) object);
-            }
-            catch (final NumberFormatException ex) {
-                return NOT_A_NUMBER;
-            }
-        }
-        if (object instanceof EvalContext) {
-            final EvalContext ctx = (EvalContext) object;
-            final Pointer ptr = ctx.getSingleNodePointer();
-            return ptr == null ? NOT_A_NUMBER : number(ptr);
+            return ((String) object).length() != 0;
         }
         if (object instanceof NodePointer) {
-            return number(((NodePointer) object).getValue());
+            NodePointer pointer = (NodePointer) object;
+            if (pointer instanceof VariablePointer) {
+                return booleanValue(pointer.getNode());
+            }
+            pointer = pointer.getValuePointer();
+            return pointer.isActual();
         }
-        return number(stringValue(object));
+        return object != null;
     }
 
     /**
@@ -126,35 +97,64 @@ public class InfoSetUtil {
     }
 
     /**
-     * Converts the supplied object to boolean.
+     * Converts the supplied object to Number.
      * @param object to convert
-     * @return boolean
+     * @return Number result
      */
-    public static boolean booleanValue(final Object object) {
+    public static Number number(final Object object) {
         if (object instanceof Number) {
-            final double value = ((Number) object).doubleValue();
-            final int negZero = -0;
-            return value != 0 && value != negZero && !Double.isNaN(value);
+            return (Number) object;
         }
         if (object instanceof Boolean) {
-            return ((Boolean) object).booleanValue();
+            return ((Boolean) object).booleanValue() ? ONE : ZERO;
+        }
+        if (object instanceof String) {
+            try {
+                return Double.valueOf((String) object);
+            }
+            catch (final NumberFormatException ex) {
+                return NOT_A_NUMBER;
+            }
         }
         if (object instanceof EvalContext) {
             final EvalContext ctx = (EvalContext) object;
             final Pointer ptr = ctx.getSingleNodePointer();
-            return ptr != null && booleanValue(ptr);
+            return ptr == null ? NOT_A_NUMBER : number(ptr);
         }
+        if (object instanceof NodePointer) {
+            return number(((NodePointer) object).getValue());
+        }
+        return number(stringValue(object));
+    }
+
+    /**
+     * Converts the supplied object to String.
+     * @param object to convert
+     * @return String value
+     */
+    public static String stringValue(final Object object) {
         if (object instanceof String) {
-            return ((String) object).length() != 0;
+            return (String) object;
+        }
+        if (object instanceof Number) {
+            final double d = ((Number) object).doubleValue();
+            final long l = ((Number) object).longValue();
+            return d == l ? String.valueOf(l) : String.valueOf(d);
+        }
+        if (object instanceof Boolean) {
+            return ((Boolean) object).booleanValue() ? "true" : "false";
+        }
+        if (object == null) {
+            return "";
         }
         if (object instanceof NodePointer) {
-            NodePointer pointer = (NodePointer) object;
-            if (pointer instanceof VariablePointer) {
-                return booleanValue(pointer.getNode());
-            }
-            pointer = pointer.getValuePointer();
-            return pointer.isActual();
+            return stringValue(((NodePointer) object).getValue());
         }
-        return object != null;
+        if (object instanceof EvalContext) {
+            final EvalContext ctx = (EvalContext) object;
+            final Pointer ptr = ctx.getSingleNodePointer();
+            return ptr == null ? "" : stringValue(ptr);
+        }
+        return String.valueOf(object);
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java b/src/main/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java
index 7f09844..e2dd4a6 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/JXPathCompiledExpression.java
@@ -41,12 +41,16 @@ public class JXPathCompiledExpression implements CompiledExpression {
         this.expression = expression;
     }
 
-    /**
-     * Gets the source expression.
-     * @return String
-     */
-    protected String getXPath() {
-        return xpath;
+    @Override
+    public Pointer createPath(final JXPathContext context) {
+        return ((JXPathContextReferenceImpl) context).
+                    createPath(xpath, expression);
+    }
+
+    @Override
+    public Pointer createPathAndSetValue(final JXPathContext context, final Object value) {
+        return ((JXPathContextReferenceImpl) context).
+                    createPathAndSetValue(xpath, expression, value);
     }
 
     /**
@@ -58,8 +62,9 @@ public class JXPathCompiledExpression implements CompiledExpression {
     }
 
     @Override
-    public String toString() {
-        return xpath;
+    public Pointer getPointer(final JXPathContext context, final String xpath) {
+        return ((JXPathContextReferenceImpl) context).
+                    getPointer(xpath, expression);
     }
 
     @Override
@@ -74,22 +79,12 @@ public class JXPathCompiledExpression implements CompiledExpression {
                     getValue(xpath, expression, requiredType);
     }
 
-    @Override
-    public void setValue(final JXPathContext context, final Object value) {
-        ((JXPathContextReferenceImpl) context).
-                    setValue(xpath, expression, value);
-    }
-
-    @Override
-    public Pointer createPath(final JXPathContext context) {
-        return ((JXPathContextReferenceImpl) context).
-                    createPath(xpath, expression);
-    }
-
-    @Override
-    public Pointer createPathAndSetValue(final JXPathContext context, final Object value) {
-        return ((JXPathContextReferenceImpl) context).
-                    createPathAndSetValue(xpath, expression, value);
+    /**
+     * Gets the source expression.
+     * @return String
+     */
+    protected String getXPath() {
+        return xpath;
     }
 
     @Override
@@ -99,15 +94,14 @@ public class JXPathCompiledExpression implements CompiledExpression {
     }
 
     @Override
-    public Pointer getPointer(final JXPathContext context, final String xpath) {
+    public Iterator iteratePointers(final JXPathContext context) {
         return ((JXPathContextReferenceImpl) context).
-                    getPointer(xpath, expression);
+                    iteratePointers(xpath, expression);
     }
 
     @Override
-    public Iterator iteratePointers(final JXPathContext context) {
-        return ((JXPathContextReferenceImpl) context).
-                    iteratePointers(xpath, expression);
+    public void removeAll(final JXPathContext context) {
+        ((JXPathContextReferenceImpl) context).removeAll(xpath, expression);
     }
 
     @Override
@@ -116,7 +110,13 @@ public class JXPathCompiledExpression implements CompiledExpression {
     }
 
     @Override
-    public void removeAll(final JXPathContext context) {
-        ((JXPathContextReferenceImpl) context).removeAll(xpath, expression);
+    public void setValue(final JXPathContext context, final Object value) {
+        ((JXPathContextReferenceImpl) context).
+                    setValue(xpath, expression, value);
+    }
+
+    @Override
+    public String toString() {
+        return xpath;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java b/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
index 46f2ea6..1bfae39 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
@@ -110,6 +110,43 @@ public class JXPathContextReferenceImpl extends JXPathContext {
         createNodeFactoryArray();
     }
 
+    /**
+     * Call this with a custom NodePointerFactory to add support for
+     * additional types of objects.  Make sure the factory returns
+     * a name that puts it in the right position on the list of factories.
+     * @param factory NodePointerFactory to add
+     */
+    public static void addNodePointerFactory(final NodePointerFactory factory) {
+        synchronized (nodeFactories) {
+            nodeFactories.add(factory);
+            nodeFactoryArray = null;
+        }
+    }
+
+    /**
+     * Checks if existenceCheckClass exists on the class path. If so, allocates
+     * an instance of the specified class, otherwise returns null.
+     * @param className to instantiate
+     * @param existenceCheckClassName guard class
+     * @return className instance
+     */
+    public static Object allocateConditionally(final String className,
+            final String existenceCheckClassName) {
+        try {
+            try {
+                ClassLoaderUtil.getClass(existenceCheckClassName, true);
+            }
+            catch (final ClassNotFoundException ex) {
+                return null;
+            }
+            final Class cls = ClassLoaderUtil.getClass(className, true);
+            return cls.getConstructor().newInstance();
+        }
+        catch (final Exception ex) {
+            throw new JXPathException("Cannot allocate " + className, ex);
+        }
+    }
+
     /**
      * Create the default node factory array.
      */
@@ -127,16 +164,11 @@ public class JXPathContextReferenceImpl extends JXPathContext {
     }
 
     /**
-     * Call this with a custom NodePointerFactory to add support for
-     * additional types of objects.  Make sure the factory returns
-     * a name that puts it in the right position on the list of factories.
-     * @param factory NodePointerFactory to add
+     * Gets the registered NodePointerFactories.
+     * @return NodePointerFactory[]
      */
-    public static void addNodePointerFactory(final NodePointerFactory factory) {
-        synchronized (nodeFactories) {
-            nodeFactories.add(factory);
-            nodeFactoryArray = null;
-        }
+    public static NodePointerFactory[] getNodePointerFactories() {
+        return nodeFactoryArray;
     }
 
     /**
@@ -154,18 +186,10 @@ public class JXPathContextReferenceImpl extends JXPathContext {
         }
     }
 
-    /**
-     * Gets the registered NodePointerFactories.
-     * @return NodePointerFactory[]
-     */
-    public static NodePointerFactory[] getNodePointerFactories() {
-        return nodeFactoryArray;
-    }
-
     /** Namespace resolver */
     protected NamespaceResolver namespaceResolver;
-
     private Pointer rootPointer;
+
     private Pointer contextPointer;
 
     /**
@@ -219,18 +243,18 @@ public class JXPathContextReferenceImpl extends JXPathContext {
     }
 
     /**
-     * Returns a static instance of TreeCompiler.
-     *
-     * Override this to return an alternate compiler.
-     * @return Compiler
+     * Checks if the path follows the JXPath restrictions on the type
+     * of path that can be passed to create... methods.
+     * @param expr Expression to check
      */
-    protected Compiler getCompiler() {
-        return COMPILER;
-    }
-
-    @Override
-    protected CompiledExpression compilePath(final String xpath) {
-        return new JXPathCompiledExpression(xpath, compileExpression(xpath));
+    private void checkSimplePath(final Expression expr) {
+        if (!(expr instanceof LocationPath)
+            || !((LocationPath) expr).isSimplePath()) {
+            throw new JXPathInvalidSyntaxException(
+                "JXPath can only create a path if it uses exclusively "
+                    + "the child:: and attribute:: axes and has "
+                    + "no context-dependent predicates");
+        }
     }
 
     /**
@@ -282,48 +306,9 @@ public class JXPathContextReferenceImpl extends JXPathContext {
         return expr;
     }
 
-    /**
-     * Traverses the xpath and returns the resulting object. Primitive
-     * types are wrapped into objects.
-     * @param xpath expression
-     * @return Object found
-     */
     @Override
-    public Object getValue(final String xpath) {
-        final Expression expression = compileExpression(xpath);
-// TODO: (work in progress) - trying to integrate with Xalan
-//        Object ctxNode = getNativeContextNode(expression);
-//        if (ctxNode != null) {
-//            System.err.println("WILL USE XALAN: " + xpath);
-//            CachedXPathAPI api = new CachedXPathAPI();
-//            try {
-//                if (expression instanceof Path) {
-//                    Node node = api.selectSingleNode((Node)ctxNode, xpath);
-//                    System.err.println("NODE: " + node);
-//                    if (node == null) {
-//                        return null;
-//                    }
-//                    return new DOMNodePointer(node, null).getValue();
-//                }
-//                else {
-//                    XObject object = api.eval((Node)ctxNode, xpath);
-//                    switch (object.getType()) {
-//                    case XObject.CLASS_STRING: return object.str();
-//                    case XObject.CLASS_NUMBER: return new Double(object.num());
-//                    case XObject.CLASS_BOOLEAN: return new Boolean(object.bool());
-//                    default:
-//                        System.err.println("OTHER TYPE: " + object.getTypeString());
-//                    }
-//                }
-//            }
-//            catch (TransformerException e) {
-//                // TODO Auto-generated catch block
-//                e.printStackTrace();
-//            }
-//            return
-//        }
-
-        return getValue(xpath, expression);
+    protected CompiledExpression compilePath(final String xpath) {
+        return new JXPathCompiledExpression(xpath, compileExpression(xpath));
     }
 
 //    private Object getNativeContextNode(Expression expression) {
@@ -356,102 +341,155 @@ public class JXPathContextReferenceImpl extends JXPathContext {
 //        return null;
 //    }
 
+    @Override
+    public Pointer createPath(final String xpath) {
+        return createPath(xpath, compileExpression(xpath));
+    }
+
     /**
-     * Gets the value indicated.
+     * Create the given path.
      * @param xpath String
-     * @param expr Expression
-     * @return Object
+     * @param expr compiled Expression
+     * @return resulting Pointer
      */
-    public Object getValue(final String xpath, final Expression expr) {
-        Object result = expr.computeValue(getEvalContext());
-        if (result == null) {
-            if (expr instanceof Path && !isLenient()) {
-                throw new JXPathNotFoundException("No value for xpath: "
-                        + xpath);
+    public Pointer createPath(final String xpath, final Expression expr) {
+        try {
+            final Object result = expr.computeValue(getEvalContext());
+            Pointer pointer;
+
+            if (result instanceof Pointer) {
+                pointer = (Pointer) result;
             }
-            return null;
-        }
-        if (result instanceof EvalContext) {
-            final EvalContext ctx = (EvalContext) result;
-            result = ctx.getSingleNodePointer();
-            if (!isLenient() && result == null) {
-                throw new JXPathNotFoundException("No value for xpath: "
-                        + xpath);
+            else if (result instanceof EvalContext) {
+                final EvalContext ctx = (EvalContext) result;
+                pointer = ctx.getSingleNodePointer();
             }
-        }
-        if (result instanceof NodePointer) {
-            result = ((NodePointer) result).getValuePointer();
-            if (!isLenient()) {
-                NodePointer.verify((NodePointer) result);
+            else {
+                checkSimplePath(expr);
+                // This should never happen
+                throw new JXPathException("Cannot create path:" + xpath);
             }
-            result = ((NodePointer) result).getValue();
+            return ((NodePointer) pointer).createPath(this);
+        }
+        catch (final Throwable ex) {
+            throw new JXPathException(
+                "Exception trying to create xpath " + xpath,
+                ex);
         }
-        return result;
     }
 
     /**
-     * Calls getValue(xpath), converts the result to the required type
-     * and returns the result of the conversion.
-     * @param xpath expression
-     * @param requiredType Class
-     * @return Object
+     * Create the given path setting its value to value.
+     * @param xpath String
+     * @param expr compiled Expression
+     * @param value Object
+     * @return resulting Pointer
      */
+    public Pointer createPathAndSetValue(final String xpath, final Expression expr,
+            final Object value) {
+        try {
+            return setValue(xpath, expr, value, true);
+        }
+        catch (final Throwable ex) {
+            throw new JXPathException(
+                "Exception trying to create xpath " + xpath,
+                ex);
+        }
+    }
+
     @Override
-    public Object getValue(final String xpath, final Class requiredType) {
-        final Expression expr = compileExpression(xpath);
-        return getValue(xpath, expr, requiredType);
+    public Pointer createPathAndSetValue(final String xpath, final Object value) {
+        return createPathAndSetValue(xpath, compileExpression(xpath), value);
     }
 
     /**
-     * Gets the value indicated.
-     * @param xpath expression
-     * @param expr compiled Expression
-     * @param requiredType Class
-     * @return Object
+     * Gets the absolute root context.
+     * @return EvalContext
      */
-    public Object getValue(final String xpath, final Expression expr, final Class requiredType) {
-        Object value = getValue(xpath, expr);
-        if (value != null && requiredType != null) {
-            if (!TypeUtils.canConvert(value, requiredType)) {
-                throw new JXPathTypeConversionException(
-                    "Invalid expression type. '"
-                        + xpath
-                        + "' returns "
-                        + value.getClass().getName()
-                        + ". It cannot be converted to "
-                        + requiredType.getName());
-            }
-            value = TypeUtils.convert(value, requiredType);
-        }
-        return value;
+    public EvalContext getAbsoluteRootContext() {
+        return new InitialContext(new RootContext(this,
+                getAbsoluteRootPointer()));
     }
 
     /**
-     * Traverses the xpath and returns a Iterator of all results found
-     * for the path. If the xpath matches no properties
-     * in the graph, the Iterator will not be null.
-     * @param xpath expression
-     * @return Iterator
+     * Gets absolute root pointer.
+     * @return NodePointer
      */
-    @Override
-    public Iterator iterate(final String xpath) {
-        return iterate(xpath, compileExpression(xpath));
+    private NodePointer getAbsoluteRootPointer() {
+        return (NodePointer) rootPointer;
     }
 
     /**
-     * Traverses the xpath and returns a Iterator of all results found
-     * for the path. If the xpath matches no properties
-     * in the graph, the Iterator will not be null.
-     * @param xpath expression
-     * @param expr compiled Expression
-     * @return Iterator
+     * Returns a static instance of TreeCompiler.
+     *
+     * Override this to return an alternate compiler.
+     * @return Compiler
      */
-    public Iterator iterate(final String xpath, final Expression expr) {
-        return expr.iterate(getEvalContext());
+    protected Compiler getCompiler() {
+        return COMPILER;
     }
 
     @Override
-    public Pointer getPointer(final String xpath) {
+    public Pointer getContextPointer() {
+        return contextPointer;
+    }
+
+    /**
+     * Gets the evaluation context.
+     * @return EvalContext
+     */
+    private EvalContext getEvalContext() {
+        return new InitialContext(new RootContext(this,
+                (NodePointer) getContextPointer()));
+    }
+
+    /**
+     * Gets the named Function.
+     * @param functionName name
+     * @param parameters function args
+     * @return Function
+     */
+    public Function getFunction(final QName functionName, final Object[] parameters) {
+        final String namespace = functionName.getPrefix();
+        final String name = functionName.getName();
+        JXPathContext funcCtx = this;
+        Function func;
+        Functions funcs;
+        while (funcCtx != null) {
+            funcs = funcCtx.getFunctions();
+            if (funcs != null) {
+                func = funcs.getFunction(namespace, name, parameters);
+                if (func != null) {
+                    return func;
+                }
+            }
+            funcCtx = funcCtx.getParentContext();
+        }
+        throw new JXPathFunctionNotFoundException(
+            "Undefined function: " + functionName.toString());
+    }
+
+    @Override
+    public Pointer getNamespaceContextPointer() {
+        return namespaceResolver.getNamespaceContextPointer();
+    }
+
+    /**
+     * Gets the namespace resolver.
+     * @return NamespaceResolver
+     */
+    public NamespaceResolver getNamespaceResolver() {
+        namespaceResolver.seal();
+        return namespaceResolver;
+    }
+
+    @Override
+    public String getNamespaceURI(final String prefix) {
+        return namespaceResolver.getNamespaceURI(prefix);
+    }
+
+    @Override
+    public Pointer getPointer(final String xpath) {
         return getPointer(xpath, compileExpression(xpath));
     }
 
@@ -476,138 +514,172 @@ public class JXPathContextReferenceImpl extends JXPathContext {
         return NodePointer.newNodePointer(null, result, getLocale());
     }
 
+    /**
+     * {@inheritDoc}
+     * @see org.apache.commons.jxpath.JXPathContext#getPrefix(java.lang.String)
+     */
     @Override
-    public void setValue(final String xpath, final Object value) {
-        setValue(xpath, compileExpression(xpath), value);
+    public String getPrefix(final String namespaceURI) {
+        return namespaceResolver.getPrefix(namespaceURI);
     }
 
-    /**
-     * Sets the value of xpath to value.
-     * @param xpath path
-     * @param expr compiled Expression
-     * @param value Object
-     */
-    public void setValue(final String xpath, final Expression expr, final Object value) {
-        try {
-            setValue(xpath, expr, value, false);
-        }
-        catch (final Throwable ex) {
+    @Override
+    public JXPathContext getRelativeContext(final Pointer pointer) {
+        final Object contextBean = pointer.getNode();
+        if (contextBean == null) {
             throw new JXPathException(
-                "Exception trying to set value with xpath " + xpath, ex);
+                "Cannot create a relative context for a non-existent node: "
+                    + pointer);
         }
+        return new JXPathContextReferenceImpl(this, contextBean, pointer);
     }
 
+    /**
+     * Traverses the xpath and returns the resulting object. Primitive
+     * types are wrapped into objects.
+     * @param xpath expression
+     * @return Object found
+     */
     @Override
-    public Pointer createPath(final String xpath) {
-        return createPath(xpath, compileExpression(xpath));
+    public Object getValue(final String xpath) {
+        final Expression expression = compileExpression(xpath);
+// TODO: (work in progress) - trying to integrate with Xalan
+//        Object ctxNode = getNativeContextNode(expression);
+//        if (ctxNode != null) {
+//            System.err.println("WILL USE XALAN: " + xpath);
+//            CachedXPathAPI api = new CachedXPathAPI();
+//            try {
+//                if (expression instanceof Path) {
+//                    Node node = api.selectSingleNode((Node)ctxNode, xpath);
+//                    System.err.println("NODE: " + node);
+//                    if (node == null) {
+//                        return null;
+//                    }
+//                    return new DOMNodePointer(node, null).getValue();
+//                }
+//                else {
+//                    XObject object = api.eval((Node)ctxNode, xpath);
+//                    switch (object.getType()) {
+//                    case XObject.CLASS_STRING: return object.str();
+//                    case XObject.CLASS_NUMBER: return new Double(object.num());
+//                    case XObject.CLASS_BOOLEAN: return new Boolean(object.bool());
+//                    default:
+//                        System.err.println("OTHER TYPE: " + object.getTypeString());
+//                    }
+//                }
+//            }
+//            catch (TransformerException e) {
+//                // TODO Auto-generated catch block
+//                e.printStackTrace();
+//            }
+//            return
+//        }
+
+        return getValue(xpath, expression);
     }
 
     /**
-     * Create the given path.
-     * @param xpath String
-     * @param expr compiled Expression
-     * @return resulting Pointer
+     * Calls getValue(xpath), converts the result to the required type
+     * and returns the result of the conversion.
+     * @param xpath expression
+     * @param requiredType Class
+     * @return Object
      */
-    public Pointer createPath(final String xpath, final Expression expr) {
-        try {
-            final Object result = expr.computeValue(getEvalContext());
-            Pointer pointer;
+    @Override
+    public Object getValue(final String xpath, final Class requiredType) {
+        final Expression expr = compileExpression(xpath);
+        return getValue(xpath, expr, requiredType);
+    }
 
-            if (result instanceof Pointer) {
-                pointer = (Pointer) result;
-            }
-            else if (result instanceof EvalContext) {
-                final EvalContext ctx = (EvalContext) result;
-                pointer = ctx.getSingleNodePointer();
+    /**
+     * Gets the value indicated.
+     * @param xpath String
+     * @param expr Expression
+     * @return Object
+     */
+    public Object getValue(final String xpath, final Expression expr) {
+        Object result = expr.computeValue(getEvalContext());
+        if (result == null) {
+            if (expr instanceof Path && !isLenient()) {
+                throw new JXPathNotFoundException("No value for xpath: "
+                        + xpath);
             }
-            else {
-                checkSimplePath(expr);
-                // This should never happen
-                throw new JXPathException("Cannot create path:" + xpath);
+            return null;
+        }
+        if (result instanceof EvalContext) {
+            final EvalContext ctx = (EvalContext) result;
+            result = ctx.getSingleNodePointer();
+            if (!isLenient() && result == null) {
+                throw new JXPathNotFoundException("No value for xpath: "
+                        + xpath);
             }
-            return ((NodePointer) pointer).createPath(this);
         }
-        catch (final Throwable ex) {
-            throw new JXPathException(
-                "Exception trying to create xpath " + xpath,
-                ex);
+        if (result instanceof NodePointer) {
+            result = ((NodePointer) result).getValuePointer();
+            if (!isLenient()) {
+                NodePointer.verify((NodePointer) result);
+            }
+            result = ((NodePointer) result).getValue();
         }
-    }
-
-    @Override
-    public Pointer createPathAndSetValue(final String xpath, final Object value) {
-        return createPathAndSetValue(xpath, compileExpression(xpath), value);
+        return result;
     }
 
     /**
-     * Create the given path setting its value to value.
-     * @param xpath String
+     * Gets the value indicated.
+     * @param xpath expression
      * @param expr compiled Expression
-     * @param value Object
-     * @return resulting Pointer
+     * @param requiredType Class
+     * @return Object
      */
-    public Pointer createPathAndSetValue(final String xpath, final Expression expr,
-            final Object value) {
-        try {
-            return setValue(xpath, expr, value, true);
-        }
-        catch (final Throwable ex) {
-            throw new JXPathException(
-                "Exception trying to create xpath " + xpath,
-                ex);
+    public Object getValue(final String xpath, final Expression expr, final Class requiredType) {
+        Object value = getValue(xpath, expr);
+        if (value != null && requiredType != null) {
+            if (!TypeUtils.canConvert(value, requiredType)) {
+                throw new JXPathTypeConversionException(
+                    "Invalid expression type. '"
+                        + xpath
+                        + "' returns "
+                        + value.getClass().getName()
+                        + ". It cannot be converted to "
+                        + requiredType.getName());
+            }
+            value = TypeUtils.convert(value, requiredType);
         }
+        return value;
     }
 
     /**
-     * Sets the specified value.
-     * @param xpath path
-     * @param expr compiled Expression
-     * @param value destination value
-     * @param create whether to create missing node(s)
-     * @return Pointer created
+     * Gets a VariablePointer for the given variable name.
+     * @param name variable name
+     * @return NodePointer
      */
-    private Pointer setValue(final String xpath, final Expression expr, final Object value,
-            final boolean create) {
-        final Object result = expr.computeValue(getEvalContext());
-        Pointer pointer;
-
-        if (result instanceof Pointer) {
-            pointer = (Pointer) result;
-        }
-        else if (result instanceof EvalContext) {
-            final EvalContext ctx = (EvalContext) result;
-            pointer = ctx.getSingleNodePointer();
-        }
-        else {
-            if (create) {
-                checkSimplePath(expr);
-            }
+    public NodePointer getVariablePointer(final QName name) {
+        return NodePointer.newNodePointer(name, VariablePointerFactory
+                .contextWrapper(this), getLocale());
+    }
 
-            // This should never happen
-            throw new JXPathException("Cannot set value for xpath: " + xpath);
-        }
-        if (create) {
-            pointer = ((NodePointer) pointer).createPath(this, value);
-        }
-        else {
-            pointer.setValue(value);
-        }
-        return pointer;
+    /**
+     * Traverses the xpath and returns a Iterator of all results found
+     * for the path. If the xpath matches no properties
+     * in the graph, the Iterator will not be null.
+     * @param xpath expression
+     * @return Iterator
+     */
+    @Override
+    public Iterator iterate(final String xpath) {
+        return iterate(xpath, compileExpression(xpath));
     }
 
     /**
-     * Checks if the path follows the JXPath restrictions on the type
-     * of path that can be passed to create... methods.
-     * @param expr Expression to check
+     * Traverses the xpath and returns a Iterator of all results found
+     * for the path. If the xpath matches no properties
+     * in the graph, the Iterator will not be null.
+     * @param xpath expression
+     * @param expr compiled Expression
+     * @return Iterator
      */
-    private void checkSimplePath(final Expression expr) {
-        if (!(expr instanceof LocationPath)
-            || !((LocationPath) expr).isSimplePath()) {
-            throw new JXPathInvalidSyntaxException(
-                "JXPath can only create a path if it uses exclusively "
-                    + "the child:: and attribute:: axes and has "
-                    + "no context-dependent predicates");
-        }
+    public Iterator iterate(final String xpath, final Expression expr) {
+        return expr.iterate(getEvalContext());
     }
 
     /**
@@ -637,27 +709,11 @@ public class JXPathContextReferenceImpl extends JXPathContext {
     }
 
     @Override
-    public void removePath(final String xpath) {
-        removePath(xpath, compileExpression(xpath));
-    }
-
-    /**
-     * Remove the specified path.
-     * @param xpath expression
-     * @param expr compiled Expression
-     */
-    public void removePath(final String xpath, final Expression expr) {
-        try {
-            final NodePointer pointer = (NodePointer) getPointer(xpath, expr);
-            if (pointer != null) {
-                pointer.remove();
-            }
-        }
-        catch (final Throwable ex) {
-            throw new JXPathException(
-                "Exception trying to remove xpath " + xpath,
-                ex);
+    public void registerNamespace(final String prefix, final String namespaceURI) {
+        if (namespaceResolver.isSealed()) {
+            namespaceResolver = (NamespaceResolver) namespaceResolver.clone();
         }
+        namespaceResolver.registerNamespace(prefix, namespaceURI);
     }
 
     @Override
@@ -695,103 +751,37 @@ public class JXPathContextReferenceImpl extends JXPathContext {
     }
 
     @Override
-    public JXPathContext getRelativeContext(final Pointer pointer) {
-        final Object contextBean = pointer.getNode();
-        if (contextBean == null) {
-            throw new JXPathException(
-                "Cannot create a relative context for a non-existent node: "
-                    + pointer);
-        }
-        return new JXPathContextReferenceImpl(this, contextBean, pointer);
-    }
-
-    @Override
-    public Pointer getContextPointer() {
-        return contextPointer;
-    }
-
-    /**
-     * Gets absolute root pointer.
-     * @return NodePointer
-     */
-    private NodePointer getAbsoluteRootPointer() {
-        return (NodePointer) rootPointer;
-    }
-
-    /**
-     * Gets the evaluation context.
-     * @return EvalContext
-     */
-    private EvalContext getEvalContext() {
-        return new InitialContext(new RootContext(this,
-                (NodePointer) getContextPointer()));
-    }
-
-    /**
-     * Gets the absolute root context.
-     * @return EvalContext
-     */
-    public EvalContext getAbsoluteRootContext() {
-        return new InitialContext(new RootContext(this,
-                getAbsoluteRootPointer()));
-    }
-
-    /**
-     * Gets a VariablePointer for the given variable name.
-     * @param name variable name
-     * @return NodePointer
-     */
-    public NodePointer getVariablePointer(final QName name) {
-        return NodePointer.newNodePointer(name, VariablePointerFactory
-                .contextWrapper(this), getLocale());
+    public void removePath(final String xpath) {
+        removePath(xpath, compileExpression(xpath));
     }
 
     /**
-     * Gets the named Function.
-     * @param functionName name
-     * @param parameters function args
-     * @return Function
+     * Remove the specified path.
+     * @param xpath expression
+     * @param expr compiled Expression
      */
-    public Function getFunction(final QName functionName, final Object[] parameters) {
-        final String namespace = functionName.getPrefix();
-        final String name = functionName.getName();
-        JXPathContext funcCtx = this;
-        Function func;
-        Functions funcs;
-        while (funcCtx != null) {
-            funcs = funcCtx.getFunctions();
-            if (funcs != null) {
-                func = funcs.getFunction(namespace, name, parameters);
-                if (func != null) {
-                    return func;
-                }
+    public void removePath(final String xpath, final Expression expr) {
+        try {
+            final NodePointer pointer = (NodePointer) getPointer(xpath, expr);
+            if (pointer != null) {
+                pointer.remove();
             }
-            funcCtx = funcCtx.getParentContext();
         }
-        throw new JXPathFunctionNotFoundException(
-            "Undefined function: " + functionName.toString());
-    }
-
-    @Override
-    public void registerNamespace(final String prefix, final String namespaceURI) {
-        if (namespaceResolver.isSealed()) {
-            namespaceResolver = (NamespaceResolver) namespaceResolver.clone();
+        catch (final Throwable ex) {
+            throw new JXPathException(
+                "Exception trying to remove xpath " + xpath,
+                ex);
         }
-        namespaceResolver.registerNamespace(prefix, namespaceURI);
-    }
-
-    @Override
-    public String getNamespaceURI(final String prefix) {
-        return namespaceResolver.getNamespaceURI(prefix);
     }
 
     /**
      * {@inheritDoc}
-     * @see org.apache.commons.jxpath.JXPathContext#getPrefix(java.lang.String)
      */
     @Override
-    public String getPrefix(final String namespaceURI) {
-        return namespaceResolver.getPrefix(namespaceURI);
+    public void setExceptionHandler(final ExceptionHandler exceptionHandler) {
+        if (rootPointer instanceof NodePointer) {
+            ((NodePointer) rootPointer).setExceptionHandler(exceptionHandler);
+        }
     }
 
     @Override
@@ -802,51 +792,61 @@ public class JXPathContextReferenceImpl extends JXPathContext {
         namespaceResolver.setNamespaceContextPointer((NodePointer) pointer);
     }
 
-    @Override
-    public Pointer getNamespaceContextPointer() {
-        return namespaceResolver.getNamespaceContextPointer();
-    }
-
     /**
-     * Gets the namespace resolver.
-     * @return NamespaceResolver
-     */
-    public NamespaceResolver getNamespaceResolver() {
-        namespaceResolver.seal();
-        return namespaceResolver;
-    }
-
-    /**
-     * {@inheritDoc}
+     * Sets the value of xpath to value.
+     * @param xpath path
+     * @param expr compiled Expression
+     * @param value Object
      */
-    @Override
-    public void setExceptionHandler(final ExceptionHandler exceptionHandler) {
-        if (rootPointer instanceof NodePointer) {
-            ((NodePointer) rootPointer).setExceptionHandler(exceptionHandler);
+    public void setValue(final String xpath, final Expression expr, final Object value) {
+        try {
+            setValue(xpath, expr, value, false);
+        }
+        catch (final Throwable ex) {
+            throw new JXPathException(
+                "Exception trying to set value with xpath " + xpath, ex);
         }
     }
 
     /**
-     * Checks if existenceCheckClass exists on the class path. If so, allocates
-     * an instance of the specified class, otherwise returns null.
-     * @param className to instantiate
-     * @param existenceCheckClassName guard class
-     * @return className instance
+     * Sets the specified value.
+     * @param xpath path
+     * @param expr compiled Expression
+     * @param value destination value
+     * @param create whether to create missing node(s)
+     * @return Pointer created
      */
-    public static Object allocateConditionally(final String className,
-            final String existenceCheckClassName) {
-        try {
-            try {
-                ClassLoaderUtil.getClass(existenceCheckClassName, true);
-            }
-            catch (final ClassNotFoundException ex) {
-                return null;
+    private Pointer setValue(final String xpath, final Expression expr, final Object value,
+            final boolean create) {
+        final Object result = expr.computeValue(getEvalContext());
+        Pointer pointer;
+
+        if (result instanceof Pointer) {
+            pointer = (Pointer) result;
+        }
+        else if (result instanceof EvalContext) {
+            final EvalContext ctx = (EvalContext) result;
+            pointer = ctx.getSingleNodePointer();
+        }
+        else {
+            if (create) {
+                checkSimplePath(expr);
             }
-            final Class cls = ClassLoaderUtil.getClass(className, true);
-            return cls.getConstructor().newInstance();
+
+            // This should never happen
+            throw new JXPathException("Cannot set value for xpath: " + xpath);
         }
-        catch (final Exception ex) {
-            throw new JXPathException("Cannot allocate " + className, ex);
+        if (create) {
+            pointer = ((NodePointer) pointer).createPath(this, value);
         }
+        else {
+            pointer.setValue(value);
+        }
+        return pointer;
+    }
+
+    @Override
+    public void setValue(final String xpath, final Object value) {
+        setValue(xpath, compileExpression(xpath), value);
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/NamespaceResolver.java b/src/main/java/org/apache/commons/jxpath/ri/NamespaceResolver.java
index 371745b..714a0e0 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/NamespaceResolver.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/NamespaceResolver.java
@@ -29,16 +29,6 @@ import org.apache.commons.jxpath.ri.model.NodePointer;
 public class NamespaceResolver implements Cloneable, Serializable {
     private static final long serialVersionUID = 1085590057838651311L;
 
-    /** Parent NamespaceResolver */
-    protected final NamespaceResolver parent;
-    /** Namespace map */
-    protected HashMap namespaceMap = new HashMap();
-    /** Reverse lookup map */
-    protected HashMap reverseMap = new HashMap();
-    /** Pointer */
-    protected NodePointer pointer;
-    private boolean sealed;
-
     /**
      * Find the namespace prefix for the specified namespace URI and NodePointer.
      * @param pointer location
@@ -64,6 +54,16 @@ public class NamespaceResolver implements Cloneable, Serializable {
         }
         return null;
     }
+    /** Parent NamespaceResolver */
+    protected final NamespaceResolver parent;
+    /** Namespace map */
+    protected HashMap namespaceMap = new HashMap();
+    /** Reverse lookup map */
+    protected HashMap reverseMap = new HashMap();
+    /** Pointer */
+    protected NodePointer pointer;
+
+    private boolean sealed;
 
     /**
      * Create a new NamespaceResolver.
@@ -80,27 +80,44 @@ public class NamespaceResolver implements Cloneable, Serializable {
         this.parent = parent;
     }
 
+    @Override
+    public Object clone() {
+        try {
+            final NamespaceResolver result = (NamespaceResolver) super.clone();
+            result.sealed = false;
+            return result;
+        }
+        catch (final CloneNotSupportedException e) {
+            // Of course, it's supported.
+            e.printStackTrace();
+            return null;
+        }
+    }
+
     /**
-     * Registers a namespace prefix.
+     * Given a prefix, returns an externally registered namespace URI.
      *
-     * @param prefix A namespace prefix
-     * @param namespaceURI A URI for that prefix
+     * @param prefix The namespace prefix to look up
+     * @return namespace URI or null if the prefix is undefined.
+     * @since JXPath 1.3
      */
-    public synchronized void registerNamespace(final String prefix, final String namespaceURI) {
-        if (isSealed()) {
-            throw new IllegalStateException(
-                    "Cannot register namespaces on a sealed NamespaceResolver");
-        }
-        namespaceMap.put(prefix, namespaceURI);
-        reverseMap.put(namespaceURI, prefix);
+     protected synchronized String getExternallyRegisteredNamespaceURI(
+            final String prefix) {
+        final String uri = (String) namespaceMap.get(prefix);
+        return uri == null && parent != null ? parent
+                .getExternallyRegisteredNamespaceURI(prefix) : uri;
     }
 
     /**
-     * Register a namespace for the expression context.
-     * @param pointer the Pointer to set.
+     * Gets the nearest prefix found that matches an externally-registered namespace.
+     * @param namespaceURI the ns URI to check.
+     * @return String prefix if found.
+     * @since JXPath 1.3
      */
-    public void setNamespaceContextPointer(final NodePointer pointer) {
-        this.pointer = pointer;
+    protected synchronized String getExternallyRegisteredPrefix(final String namespaceURI) {
+        final String prefix = (String) reverseMap.get(namespaceURI);
+        return prefix == null && parent != null ? parent
+                .getExternallyRegisteredPrefix(namespaceURI) : prefix;
     }
 
     /**
@@ -130,20 +147,6 @@ public class NamespaceResolver implements Cloneable, Serializable {
                 : uri;
     }
 
-    /**
-     * Given a prefix, returns an externally registered namespace URI.
-     *
-     * @param prefix The namespace prefix to look up
-     * @return namespace URI or null if the prefix is undefined.
-     * @since JXPath 1.3
-     */
-     protected synchronized String getExternallyRegisteredNamespaceURI(
-            final String prefix) {
-        final String uri = (String) namespaceMap.get(prefix);
-        return uri == null && parent != null ? parent
-                .getExternallyRegisteredNamespaceURI(prefix) : uri;
-    }
-
     /**
      * Gets the prefix associated with the specifed namespace URI.
      * @param namespaceURI the ns URI to check.
@@ -155,18 +158,6 @@ public class NamespaceResolver implements Cloneable, Serializable {
                 namespaceURI) : prefix;
     }
 
-    /**
-     * Gets the nearest prefix found that matches an externally-registered namespace.
-     * @param namespaceURI the ns URI to check.
-     * @return String prefix if found.
-     * @since JXPath 1.3
-     */
-    protected synchronized String getExternallyRegisteredPrefix(final String namespaceURI) {
-        final String prefix = (String) reverseMap.get(namespaceURI);
-        return prefix == null && parent != null ? parent
-                .getExternallyRegisteredPrefix(namespaceURI) : prefix;
-    }
-
     /**
      * Learn whether this NamespaceResolver has been sealed.
      * @return boolean
@@ -175,6 +166,21 @@ public class NamespaceResolver implements Cloneable, Serializable {
         return sealed;
     }
 
+    /**
+     * Registers a namespace prefix.
+     *
+     * @param prefix A namespace prefix
+     * @param namespaceURI A URI for that prefix
+     */
+    public synchronized void registerNamespace(final String prefix, final String namespaceURI) {
+        if (isSealed()) {
+            throw new IllegalStateException(
+                    "Cannot register namespaces on a sealed NamespaceResolver");
+        }
+        namespaceMap.put(prefix, namespaceURI);
+        reverseMap.put(namespaceURI, prefix);
+    }
+
     /**
      * Seal this {@link NamespaceResolver}.
      */
@@ -185,17 +191,11 @@ public class NamespaceResolver implements Cloneable, Serializable {
         }
     }
 
-    @Override
-    public Object clone() {
-        try {
-            final NamespaceResolver result = (NamespaceResolver) super.clone();
-            result.sealed = false;
-            return result;
-        }
-        catch (final CloneNotSupportedException e) {
-            // Of course, it's supported.
-            e.printStackTrace();
-            return null;
-        }
+    /**
+     * Register a namespace for the expression context.
+     * @param pointer the Pointer to set.
+     */
+    public void setNamespaceContextPointer(final NodePointer pointer) {
+        this.pointer = pointer;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/Parser.java b/src/main/java/org/apache/commons/jxpath/ri/Parser.java
index 58fe7ca..9ad984a 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/Parser.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/Parser.java
@@ -30,6 +30,33 @@ public class Parser {
 
     private static final XPathParser PARSER = new XPathParser(new StringReader(""));
 
+    /**
+     * Add escapes to the specified String.
+     * @param string incoming String
+     * @return String
+     */
+    private static String addEscapes(final String string) {
+        // Piggy-back on the code generated by JavaCC
+        return TokenMgrError.addEscapes(string);
+    }
+
+    /**
+     * Describe a parse position.
+     * @param expression to parse
+     * @param position parse position
+     * @return String
+     */
+    private static String describePosition(final String expression, final int position) {
+        if (position <= 0) {
+            return "at the beginning of the expression";
+        }
+        if (position >= expression.length()) {
+            return "- expression incomplete";
+        }
+        return "after: '"
+            + addEscapes(expression.substring(0, position)) + "'";
+    }
+
     /**
      * Parses the XPath expression. Throws a JXPathException in case
      * of a syntax error.
@@ -68,31 +95,4 @@ public class Parser {
             return expr;
         }
     }
-
-    /**
-     * Describe a parse position.
-     * @param expression to parse
-     * @param position parse position
-     * @return String
-     */
-    private static String describePosition(final String expression, final int position) {
-        if (position <= 0) {
-            return "at the beginning of the expression";
-        }
-        if (position >= expression.length()) {
-            return "- expression incomplete";
-        }
-        return "after: '"
-            + addEscapes(expression.substring(0, position)) + "'";
-    }
-
-    /**
-     * Add escapes to the specified String.
-     * @param string incoming String
-     * @return String
-     */
-    private static String addEscapes(final String string) {
-        // Piggy-back on the code generated by JavaCC
-        return TokenMgrError.addEscapes(string);
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/QName.java b/src/main/java/org/apache/commons/jxpath/ri/QName.java
index ccad014..9e79f03 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/QName.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/QName.java
@@ -51,12 +51,15 @@ public class QName implements Serializable {
         this.qualifiedName = prefix == null ? localName : prefix + ':' + localName;
     }
 
-    /**
-     * Gets the prefix of this QName.
-     * @return String
-     */
-    public String getPrefix() {
-        return prefix;
+    @Override
+    public boolean equals(final Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (!(object instanceof QName)) {
+            return false;
+        }
+        return qualifiedName.equals(((QName) object).qualifiedName);
     }
 
     /**
@@ -67,9 +70,12 @@ public class QName implements Serializable {
         return name;
     }
 
-    @Override
-    public String toString() {
-        return qualifiedName;
+    /**
+     * Gets the prefix of this QName.
+     * @return String
+     */
+    public String getPrefix() {
+        return prefix;
     }
 
     @Override
@@ -78,13 +84,7 @@ public class QName implements Serializable {
     }
 
     @Override
-    public boolean equals(final Object object) {
-        if (this == object) {
-            return true;
-        }
-        if (!(object instanceof QName)) {
-            return false;
-        }
-        return qualifiedName.equals(((QName) object).qualifiedName);
+    public String toString() {
+        return qualifiedName;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/AncestorContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/AncestorContext.java
index 1230779..6aaa50a 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/AncestorContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/AncestorContext.java
@@ -55,26 +55,6 @@ public class AncestorContext extends EvalContext {
         return -1;
     }
 
-    @Override
-    public void reset() {
-        super.reset();
-        setStarted = false;
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        if (position < getCurrentPosition()) {
-            reset();
-        }
-
-        while (getCurrentPosition() < position) {
-            if (!nextNode()) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean nextNode() {
         if (!setStarted) {
@@ -99,4 +79,24 @@ public class AncestorContext extends EvalContext {
             }
         }
     }
+
+    @Override
+    public void reset() {
+        super.reset();
+        setStarted = false;
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        if (position < getCurrentPosition()) {
+            reset();
+        }
+
+        while (getCurrentPosition() < position) {
+            if (!nextNode()) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java
index be08c0e..86453be 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/AttributeContext.java
@@ -51,27 +51,6 @@ public class AttributeContext extends EvalContext {
         return currentNodePointer;
     }
 
-    @Override
-    public void reset() {
-        setStarted = false;
-        iterator = null;
-        super.reset();
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        if (position < getCurrentPosition()) {
-            reset();
-        }
-
-        while (getCurrentPosition() < position) {
-            if (!nextNode()) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean nextNode() {
         super.setPosition(getCurrentPosition() + 1);
@@ -99,4 +78,25 @@ public class AttributeContext extends EvalContext {
         currentNodePointer = iterator.getNodePointer();
         return true;
     }
+
+    @Override
+    public void reset() {
+        setStarted = false;
+        iterator = null;
+        super.reset();
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        if (position < getCurrentPosition()) {
+            reset();
+        }
+
+        while (getCurrentPosition() < position) {
+            if (!nextNode()) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
index bfcc021..db3c571 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/ChildContext.java
@@ -87,6 +87,19 @@ public class ChildContext extends EvalContext {
         return setPosition(getCurrentPosition() + 1);
     }
 
+    /**
+     * Allocates a PropertyIterator.
+     */
+    private void prepare() {
+        final NodePointer parent = parentContext.getCurrentNodePointer();
+        if (parent == null) {
+            return;
+        }
+        final NodePointer useParent = startFromParentLocation ? parent.getParent() : parent;
+        iterator = useParent == null ? null : useParent.childIterator(nodeTest, reverse,
+                startFromParentLocation ? parent : null);
+    }
+
     @Override
     public void reset() {
         super.reset();
@@ -102,17 +115,4 @@ public class ChildContext extends EvalContext {
         }
         return iterator != null && iterator.setPosition(position);
     }
-
-    /**
-     * Allocates a PropertyIterator.
-     */
-    private void prepare() {
-        final NodePointer parent = parentContext.getCurrentNodePointer();
-        if (parent == null) {
-            return;
-        }
-        final NodePointer useParent = startFromParentLocation ? parent.getParent() : parent;
-        iterator = useParent == null ? null : useParent.childIterator(nodeTest, reverse,
-                startFromParentLocation ? parent : null);
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java
index 1610dd3..836731e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/DescendantContext.java
@@ -31,13 +31,13 @@ import org.apache.commons.jxpath.ri.model.NodePointer;
  * axes.
  */
 public class DescendantContext extends EvalContext {
+    private static final NodeTest ELEMENT_NODE_TEST =
+            new NodeTypeTest(Compiler.NODE_TYPE_NODE);
     private final NodeTest nodeTest;
     private boolean setStarted = false;
     private Stack stack = null;
     private NodePointer currentNodePointer = null;
     private final boolean includeSelf;
-    private static final NodeTest ELEMENT_NODE_TEST =
-            new NodeTypeTest(Compiler.NODE_TYPE_NODE);
 
     /**
      * Create a new DescendantContext.
@@ -52,11 +52,6 @@ public class DescendantContext extends EvalContext {
         this.nodeTest = nodeTest;
     }
 
-    @Override
-    public boolean isChildOrderingRequired() {
-        return true;
-    }
-
     @Override
     public NodePointer getCurrentNodePointer() {
         if (position == 0 && !setPosition(1)) {
@@ -66,23 +61,25 @@ public class DescendantContext extends EvalContext {
     }
 
     @Override
-    public void reset() {
-        super.reset();
-        setStarted = false;
+    public boolean isChildOrderingRequired() {
+        return true;
     }
 
-    @Override
-    public boolean setPosition(final int position) {
-        if (position < this.position) {
-            reset();
-        }
-
-        while (this.position < position) {
-            if (!nextNode()) {
-                return false;
+    /**
+     * Checks if we are reentering a bean we have already seen and if so
+     * returns true to prevent infinite recursion.
+     * @return boolean
+     */
+    private boolean isRecursive() {
+        final Object node = currentNodePointer.getNode();
+        for (int i = stack.size() - 1; --i >= 0;) {
+            final NodeIterator it = (NodeIterator) stack.get(i);
+            final Pointer pointer = it.getNodePointer();
+            if (pointer != null && pointer.getNode() == node) {
+                return true;
             }
         }
-        return true;
+        return false;
     }
 
     @Override
@@ -138,20 +135,23 @@ public class DescendantContext extends EvalContext {
         return false;
     }
 
-    /**
-     * Checks if we are reentering a bean we have already seen and if so
-     * returns true to prevent infinite recursion.
-     * @return boolean
-     */
-    private boolean isRecursive() {
-        final Object node = currentNodePointer.getNode();
-        for (int i = stack.size() - 1; --i >= 0;) {
-            final NodeIterator it = (NodeIterator) stack.get(i);
-            final Pointer pointer = it.getNodePointer();
-            if (pointer != null && pointer.getNode() == node) {
-                return true;
+    @Override
+    public void reset() {
+        super.reset();
+        setStarted = false;
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        if (position < this.position) {
+            reset();
+        }
+
+        while (this.position < position) {
+            if (!nextNode()) {
+                return false;
             }
         }
-        return false;
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/InitialContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/InitialContext.java
index f2c0335..891357e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/InitialContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/InitialContext.java
@@ -45,12 +45,12 @@ public class InitialContext extends EvalContext {
     }
 
     @Override
-    public Pointer getSingleNodePointer() {
+    public NodePointer getCurrentNodePointer() {
         return nodePointer;
     }
 
     @Override
-    public NodePointer getCurrentNodePointer() {
+    public Pointer getSingleNodePointer() {
         return nodePointer;
     }
 
@@ -64,6 +64,15 @@ public class InitialContext extends EvalContext {
         return setPosition(position + 1);
     }
 
+    @Override
+    public boolean nextSet() {
+        if (started) {
+            return false;
+        }
+        started = true;
+        return true;
+    }
+
     @Override
     public boolean setPosition(final int position) {
         this.position = position;
@@ -76,13 +85,4 @@ public class InitialContext extends EvalContext {
         }
         return position == 1;
     }
-
-    @Override
-    public boolean nextSet() {
-        if (started) {
-            return false;
-        }
-        started = true;
-        return true;
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
index ffcf7b1..cde04bc 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
@@ -46,27 +46,6 @@ public class NamespaceContext extends EvalContext {
         return currentNodePointer;
     }
 
-    @Override
-    public void reset() {
-        setStarted = false;
-        iterator = null;
-        super.reset();
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        if (position < getCurrentPosition()) {
-            reset();
-        }
-
-        while (getCurrentPosition() < position) {
-            if (!nextNode()) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean nextNode() {
         super.setPosition(getCurrentPosition() + 1);
@@ -102,4 +81,25 @@ public class NamespaceContext extends EvalContext {
         currentNodePointer = iterator.getNodePointer();
         return true;
     }
+
+    @Override
+    public void reset() {
+        setStarted = false;
+        iterator = null;
+        super.reset();
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        if (position < getCurrentPosition()) {
+            reset();
+        }
+
+        while (getCurrentPosition() < position) {
+            if (!nextNode()) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/NodeSetContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/NodeSetContext.java
index 9099fd7..4ae0afc 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/NodeSetContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/NodeSetContext.java
@@ -37,11 +37,6 @@ public class NodeSetContext extends EvalContext {
         this.nodeSet = nodeSet;
     }
 
-    @Override
-    public NodeSet getNodeSet() {
-        return nodeSet;
-    }
-
     @Override
     public NodePointer getCurrentNodePointer() {
         if (position == 0 && !setPosition(1)) {
@@ -51,9 +46,13 @@ public class NodeSetContext extends EvalContext {
     }
 
     @Override
-    public boolean setPosition(final int position) {
-        super.setPosition(position);
-        return position >= 1 && position <= nodeSet.getPointers().size();
+    public NodeSet getNodeSet() {
+        return nodeSet;
+    }
+
+    @Override
+    public boolean nextNode() {
+        return setPosition(position + 1);
     }
 
     @Override
@@ -66,7 +65,8 @@ public class NodeSetContext extends EvalContext {
     }
 
     @Override
-    public boolean nextNode() {
-        return setPosition(position + 1);
+    public boolean setPosition(final int position) {
+        super.setPosition(position);
+        return position >= 1 && position <= nodeSet.getPointers().size();
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/ParentContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/ParentContext.java
index d11b134..a51468a 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/ParentContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/ParentContext.java
@@ -53,18 +53,6 @@ public class ParentContext extends EvalContext {
         return -1;
     }
 
-    @Override
-    public void reset() {
-        super.reset();
-        setStarted = false;
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        super.setPosition(position);
-        return position == 1;
-    }
-
     @Override
     public boolean nextNode() {
         // Each set contains exactly one node: the parent
@@ -85,4 +73,16 @@ public class ParentContext extends EvalContext {
         }
         return false;
     }
+
+    @Override
+    public void reset() {
+        super.reset();
+        setStarted = false;
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        super.setPosition(position);
+        return position == 1;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java
index b3b84aa..f946f72 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/PrecedingOrFollowingContext.java
@@ -59,26 +59,6 @@ public class PrecedingOrFollowingContext extends EvalContext {
         return reverse ? -1 : 1;
     }
 
-    @Override
-    public void reset() {
-        super.reset();
-        setStarted = false;
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        if (position < this.position) {
-            reset();
-        }
-
-        while (this.position < position) {
-            if (!nextNode()) {
-                return false;
-            }
-        }
-        return true;
-    }
-
     @Override
     public boolean nextNode() {
         if (!setStarted) {
@@ -172,4 +152,24 @@ public class PrecedingOrFollowingContext extends EvalContext {
         }
         return false;
     }
+
+    @Override
+    public void reset() {
+        super.reset();
+        setStarted = false;
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        if (position < this.position) {
+            reset();
+        }
+
+        while (this.position < position) {
+            if (!nextNode()) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java
index 645fdf5..e8ef976 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/PredicateContext.java
@@ -49,6 +49,17 @@ public class PredicateContext extends EvalContext {
         }
     }
 
+    @Override
+    public NodePointer getCurrentNodePointer() {
+        if (position == 0 && !setPosition(1)) {
+            return null;
+        }
+        if (dynamicPropertyPointer != null) {
+            return dynamicPropertyPointer.getValuePointer();
+        }
+        return parentContext.getCurrentNodePointer();
+    }
+
     @Override
     public boolean nextNode() {
         if (done) {
@@ -109,29 +120,17 @@ public class PredicateContext extends EvalContext {
         return false;
     }
 
-    /**
-     * 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;
-        }
+    @Override
+    public boolean nextSet() {
+        reset();
+        return parentContext.nextSet();
+    }
 
-        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;
+    @Override
+    public void reset() {
+        super.reset();
+        parentContext.reset();
+        done = false;
     }
 
     @Override
@@ -150,30 +149,6 @@ public class PredicateContext extends EvalContext {
         return true;
     }
 
-    @Override
-    public NodePointer getCurrentNodePointer() {
-        if (position == 0 && !setPosition(1)) {
-            return null;
-        }
-        if (dynamicPropertyPointer != null) {
-            return dynamicPropertyPointer.getValuePointer();
-        }
-        return parentContext.getCurrentNodePointer();
-    }
-
-    @Override
-    public void reset() {
-        super.reset();
-        parentContext.reset();
-        done = false;
-    }
-
-    @Override
-    public boolean nextSet() {
-        reset();
-        return parentContext.nextSet();
-    }
-
     /**
      * Basic setPosition
      * @param position to set
@@ -191,4 +166,29 @@ public class PredicateContext extends EvalContext {
         }
         return true;
     }
+
+    /**
+     * 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;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/RootContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/RootContext.java
index 0827dd9..b2cf926 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/RootContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/RootContext.java
@@ -28,12 +28,12 @@ import org.apache.commons.jxpath.ri.model.NodePointer;
  * EvalContext that is used to hold the root node for the path traversal.
  */
 public class RootContext extends EvalContext {
+    public static final Object UNKNOWN_VALUE = new Object();
+    private static final int MAX_REGISTER = 4;
     private final JXPathContextReferenceImpl jxpathContext;
     private final NodePointer pointer;
     private Object[] registers;
     private int availableRegister = 0;
-    public static final Object UNKNOWN_VALUE = new Object();
-    private static final int MAX_REGISTER = 4;
 
     /**
      * Create a new RootContext.
@@ -50,16 +50,6 @@ public class RootContext extends EvalContext {
         }
     }
 
-    @Override
-    public JXPathContext getJXPathContext() {
-        return jxpathContext;
-    }
-
-    @Override
-    public RootContext getRootContext() {
-        return this;
-    }
-
     /**
      * Gets absolute root context
      * @return EvalContext
@@ -68,36 +58,6 @@ public class RootContext extends EvalContext {
         return jxpathContext.getAbsoluteRootContext();
     }
 
-    @Override
-    public NodePointer getCurrentNodePointer() {
-        return pointer;
-    }
-
-    @Override
-    public Object getValue() {
-        return pointer;
-    }
-
-    @Override
-    public int getCurrentPosition() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean nextNode() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean nextSet() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean setPosition(final int position) {
-        throw new UnsupportedOperationException();
-    }
-
     /**
      * Gets a context that points to the specified object.
      * @param constant object
@@ -123,16 +83,14 @@ public class RootContext extends EvalContext {
         return new InitialContext(new RootContext(jxpathContext, pointer));
     }
 
-    /**
-     * Gets variable context.
-     * @param variableName variable name
-     * @return EvalContext
-     */
-    public EvalContext getVariableContext(final QName variableName) {
-        return new InitialContext(
-            new RootContext(
-                jxpathContext,
-                jxpathContext.getVariablePointer(variableName)));
+    @Override
+    public NodePointer getCurrentNodePointer() {
+        return pointer;
+    }
+
+    @Override
+    public int getCurrentPosition() {
+        throw new UnsupportedOperationException();
     }
 
     /**
@@ -145,6 +103,11 @@ public class RootContext extends EvalContext {
         return jxpathContext.getFunction(functionName, parameters);
     }
 
+    @Override
+    public JXPathContext getJXPathContext() {
+        return jxpathContext;
+    }
+
     /**
      * Gets a registered value.
      * @param id int
@@ -157,6 +120,43 @@ public class RootContext extends EvalContext {
         return registers[id];
     }
 
+    @Override
+    public RootContext getRootContext() {
+        return this;
+    }
+
+    @Override
+    public Object getValue() {
+        return pointer;
+    }
+
+    /**
+     * Gets variable context.
+     * @param variableName variable name
+     * @return EvalContext
+     */
+    public EvalContext getVariableContext(final QName variableName) {
+        return new InitialContext(
+            new RootContext(
+                jxpathContext,
+                jxpathContext.getVariablePointer(variableName)));
+    }
+
+    @Override
+    public boolean nextNode() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean nextSet() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean setPosition(final int position) {
+        throw new UnsupportedOperationException();
+    }
+
     /**
      * Sets the next registered value.
      * @param value Object
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/SelfContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/SelfContext.java
index 2a45a52..081b8b9 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/SelfContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/SelfContext.java
@@ -40,11 +40,6 @@ public class SelfContext extends EvalContext {
         this.nodeTest = nodeTest;
     }
 
-    @Override
-    public Pointer getSingleNodePointer() {
-        return parentContext.getSingleNodePointer();
-    }
-
     @Override
     public NodePointer getCurrentNodePointer() {
         if (position == 0 && !setPosition(1)) {
@@ -53,6 +48,11 @@ public class SelfContext extends EvalContext {
         return nodePointer;
     }
 
+    @Override
+    public Pointer getSingleNodePointer() {
+        return parentContext.getSingleNodePointer();
+    }
+
     @Override
     public boolean nextNode() {
         return setPosition(getCurrentPosition() + 1);
diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java b/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
index 8ef88ed..285a481 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
@@ -62,47 +62,378 @@ public class SimplePathInterpreter {
 //    private static String PATH;       // Debugging
 
     /**
-     * Interpret a simple path that starts with the given root and
-     * follows the given steps. All steps must have the axis "child::"
-     * and a name test.  They can also optionally have predicates
-     * of type [@name=expression] or simply [expression] interpreted
-     * as an index.
+     * For a pointer that matches an actual node, returns 0.
+     * For a pointer that does not match an actual node, but whose
+     * parent pointer does returns -1, etc.
+     * @param pointer input pointer
+     * @return int match quality code
+     */
+    private static int computeQuality(NodePointer pointer) {
+        int quality = PERFECT_MATCH;
+        while (pointer != null && !pointer.isActual()) {
+            quality--;
+            pointer = pointer.getImmediateParentPointer();
+        }
+        return quality;
+    }
+
+    /**
+     * Create the child pointer for a given step.
+     * @param parentPointer parent pointer
+     * @param step associated step
+     * @return NodePointer
+     */
+    private static NodePointer createChildPointerForStep(
+                final PropertyOwnerPointer parentPointer, final Step step) {
+        final int axis = step.getAxis();
+        if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) {
+            final QName name = ((NodeNameTest) step.getNodeTest()).getNodeName();
+            if (axis == Compiler.AXIS_ATTRIBUTE && isLangAttribute(name)) {
+                return new LangAttributePointer(parentPointer);
+            }
+            if (parentPointer.isValidProperty(name)) {
+                final 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;
+    }
+
+    /**
+     * Creates a "null pointer" that
+     * a) represents the requested path and
+     * b) can be used for creation of missing nodes in the path.
      * @param context evaluation context
-     * @param root root pointer
+     * @param parent parent pointer
      * @param steps path steps
+     * @param currentStep step number
      * @return NodePointer
      */
-    public static NodePointer interpretSimpleLocationPath(
-            final EvalContext context, final NodePointer root, final Step[] steps) {
-//        PATH = createNullPointer(context, root, steps, 0).toString();  // Dbg
-        final NodePointer pointer = doStep(context, root, steps, 0);
-//        return valuePointer(pointer);
-        return pointer;
+    public static NodePointer createNullPointer(
+            final EvalContext context, NodePointer parent, final Step[] steps,
+            final int currentStep) {
+        if (currentStep == steps.length) {
+            return parent;
+        }
+
+        parent = valuePointer(parent);
+
+        final Step step = steps[currentStep];
+
+        final int axis = step.getAxis();
+        if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) {
+            final NullPropertyPointer pointer = new NullPropertyPointer(parent);
+            final QName name = ((NodeNameTest) step.getNodeTest()).getNodeName();
+            pointer.setPropertyName(name.toString());
+            pointer.setAttribute(axis == Compiler.AXIS_ATTRIBUTE);
+            parent = pointer;
+        }
+        // else { it is self::node() }
+
+        final Expression[] predicates = step.getPredicates();
+        return createNullPointerForPredicates(
+            context,
+            parent,
+            steps,
+            currentStep,
+            predicates,
+            0);
     }
 
     /**
-     * Interpret the steps of a simple expression path that
-     * starts with the given root, which is the result of evaluation
-     * of the root expression of the expression path, applies the
-     * given predicates to it and then follows the given steps.
-     * All steps must have the axis "child::" or "attribute::"
-     * and a name test.  They can also optionally have predicates
-     * of type [@name=...] or simply [...] interpreted as an index.
+     * Creates a "null pointer" that starts with predicates.
      * @param context evaluation context
-     * @param root root pointer
-     * @param predicates predicates corresponding to {@code steps}
+     * @param parent parent pointer
      * @param steps path steps
+     * @param currentStep step number
+     * @param predicates predicates
+     * @param currentPredicate int predicate number
      * @return NodePointer
      */
-    public static NodePointer interpretSimpleExpressionPath(
-                final EvalContext context, final NodePointer root,
-                final Expression[] predicates, final Step[] steps) {
-//        PATH = createNullPointerForPredicates(context, root,
-//                    steps, -1, predicates, 0).toString();  // Debugging
-        final NodePointer pointer =
-            doPredicate(context, root, steps, -1, predicates, 0);
-//        return valuePointer(pointer);
-        return pointer;
+    private static NodePointer createNullPointerForPredicates(
+            final EvalContext context, NodePointer parent,
+            final Step[] steps, final int currentStep,
+            final Expression[] predicates, final int currentPredicate) {
+        for (int i = currentPredicate; i < predicates.length; i++) {
+            final Expression predicate = predicates[i];
+            if (predicate instanceof NameAttributeTest) {
+                final String key = keyFromPredicate(context, predicate);
+                parent = valuePointer(parent);
+                final NullPropertyPointer pointer = new NullPropertyPointer(parent);
+                pointer.setNameAttributeValue(key);
+                parent = pointer;
+            }
+            else {
+                final int index = indexFromPredicate(context, predicate);
+                if (parent instanceof NullPropertyPointer) {
+                    parent.setIndex(index);
+                }
+                else {
+                    parent = new NullElementPointer(parent, index);
+                }
+            }
+        }
+        // Proceed with the remaining steps
+        return createNullPointer(
+                    context, parent, steps, currentStep + 1);
+    }
+
+    /**
+     * Evaluates predicates and proceeds with the subsequent steps
+     * of the path.
+     * @param context evaluation context
+     * @param parent parent pointer
+     * @param steps path steps
+     * @param currentStep step number
+     * @param predicates predicate expressions
+     * @param currentPredicate int predicate number
+     * @return NodePointer
+     */
+    private static NodePointer doPredicate(
+                final EvalContext context, final NodePointer parent,
+                final Step[] steps, final int currentStep,
+                final Expression[] predicates, final int currentPredicate) {
+        if (currentPredicate == predicates.length) {
+            return doStep(context, parent, steps, currentStep + 1);
+        }
+
+        final Expression predicate = predicates[currentPredicate];
+        if (predicate instanceof NameAttributeTest) { // [@name = key1]
+            return doPredicateName(
+                context,
+                parent,
+                steps,
+                currentStep,
+                predicates,
+                currentPredicate);
+        }
+        // else [index]
+        return doPredicateIndex(
+            context,
+            parent,
+            steps,
+            currentStep,
+            predicates,
+            currentPredicate);
+    }
+
+    /**
+     * Evaluate a subscript predicate: see if the node is a collection and
+     * if the index is inside the collection.
+     * @param context evaluation context
+     * @param parent parent pointer
+     * @param steps path steps
+     * @param currentStep step number
+     * @param predicates predicates
+     * @param currentPredicate int predicate number
+     * @return NodePointer
+     */
+    private static NodePointer doPredicateIndex(
+            final EvalContext context, final NodePointer parent,
+            final Step[] steps, final int currentStep,
+            final Expression[] predicates, final int currentPredicate) {
+        final Expression predicate = predicates[currentPredicate];
+        final int index = indexFromPredicate(context, predicate);
+        NodePointer pointer = parent;
+        if (isCollectionElement(pointer, index)) {
+            pointer = (NodePointer) pointer.clone();
+            pointer.setIndex(index);
+            return doPredicate(
+                context,
+                pointer,
+                steps,
+                currentStep,
+                predicates,
+                currentPredicate + 1);
+        }
+        return createNullPointerForPredicates(
+            context,
+            parent,
+            steps,
+            currentStep,
+            predicates,
+            currentPredicate);
+    }
+
+    /**
+     * Execute a NameAttributeTest predicate
+     * @param context evaluation context
+     * @param parent parent pointer
+     * @param steps path steps
+     * @param currentStep int step number
+     * @param predicates predicates
+     * @param currentPredicate int predicate number
+     * @return NodePointer
+     */
+    private static NodePointer doPredicateName(
+            final EvalContext context, final NodePointer parent,
+            final Step[] steps, final int currentStep,
+            final Expression[] predicates, final int currentPredicate) {
+        final Expression predicate = predicates[currentPredicate];
+        final String key = keyFromPredicate(context, predicate);
+        NodePointer child = valuePointer(parent);
+        if (child instanceof PropertyOwnerPointer) {
+            final PropertyPointer pointer =
+                ((PropertyOwnerPointer) child).getPropertyPointer();
+            pointer.setPropertyName(key);
+            if (pointer.isActual()) {
+                return doPredicate(
+                    context,
+                    pointer,
+                    steps,
+                    currentStep,
+                    predicates,
+                    currentPredicate + 1);
+            }
+        }
+        else if (child.isCollection()) {
+            // For each node in the collection, perform the following:
+            // if the node is a property owner, apply this predicate to it;
+            // if the node is a collection, apply this predicate to each elem.;
+            // if the node is not a prop owner or a collection,
+            //  see if it has the attribute "name" with the right value,
+            //  if so - proceed to the next predicate
+            NodePointer bestMatch = null;
+            int bestQuality = 0;
+            child = (NodePointer) child.clone();
+            final int count = child.getLength();
+            for (int i = 0; i < count; i++) {
+                child.setIndex(i);
+                final NodePointer valuePointer = valuePointer(child);
+                NodePointer pointer;
+                if (valuePointer instanceof PropertyOwnerPointer
+                    || valuePointer.isCollection()) {
+                    pointer =
+                        doPredicateName(
+                            context,
+                            valuePointer,
+                            steps,
+                            currentStep,
+                            predicates,
+                            currentPredicate);
+                }
+                else if (isNameAttributeEqual(valuePointer, key)) {
+                    pointer =
+                        doPredicate(
+                            context,
+                            valuePointer,
+                            steps,
+                            currentStep,
+                            predicates,
+                            currentPredicate + 1);
+                }
+                else {
+                    pointer = null;
+                }
+                if (pointer != null) {
+                    final int quality = computeQuality(pointer);
+                    if (quality == PERFECT_MATCH) {
+                        return pointer;
+                    }
+                    if (quality > bestQuality) {
+                        bestMatch = (NodePointer) pointer.clone();
+                        bestQuality = quality;
+                    }
+                }
+            }
+            if (bestMatch != null) {
+                return bestMatch;
+            }
+        }
+        else {
+            // If the node is a standard InfoSet node (e.g. DOM Node),
+            // employ doPredicates_standard, which will iterate through
+            // the node's children and apply all predicates
+            final NodePointer found =
+                doPredicatesStandard(
+                    context,
+                    Collections.singletonList(child),
+                    steps,
+                    currentStep,
+                    predicates,
+                    currentPredicate);
+            if (found != null) {
+                return found;
+            }
+        }
+        // If nothing worked - return a null pointer
+        return createNullPointerForPredicates(
+            context,
+            child,
+            steps,
+            currentStep,
+            predicates,
+            currentPredicate);
+    }
+
+    /**
+     * Called exclusively for standard InfoSet nodes, e.g. DOM nodes
+     * to evaluate predicate sequences like [@name=...][@name=...][index].
+     * @param context evaluation context
+     * @param parents List of parent pointers
+     * @param steps path steps
+     * @param currentStep step number
+     * @param predicates predicates
+     * @param currentPredicate int predicate number
+     * @return NodePointer
+     */
+    private static NodePointer doPredicatesStandard(
+                final EvalContext context, final List parents,
+                final Step[] steps, final int currentStep,
+                final Expression[] predicates, final int currentPredicate) {
+        if (parents.isEmpty()) {
+            return null;
+        }
+
+        // If all predicates have been processed, take the first
+        // element from the list of results and proceed to the
+        // remaining steps with that element.
+        if (currentPredicate == predicates.length) {
+            final NodePointer pointer = (NodePointer) parents.get(0);
+            return doStep(context, pointer, steps, currentStep + 1);
+        }
+
+        final Expression predicate = predicates[currentPredicate];
+        if (predicate instanceof NameAttributeTest) {
+            final String key = keyFromPredicate(context, predicate);
+            final List newList = new ArrayList();
+            for (int i = 0; i < parents.size(); i++) {
+                final NodePointer pointer = (NodePointer) parents.get(i);
+                if (isNameAttributeEqual(pointer, key)) {
+                    newList.add(pointer);
+                }
+            }
+            if (newList.isEmpty()) {
+                return null;
+            }
+            return doPredicatesStandard(
+                context,
+                newList,
+                steps,
+                currentStep,
+                predicates,
+                currentPredicate + 1);
+        }
+        // For a subscript, simply take the corresponding
+        // element from the list of results and
+        // proceed to the remaining predicates with that element
+        final int index = indexFromPredicate(context, predicate);
+        if (index < 0 || index >= parents.size()) {
+            return null;
+        }
+        final NodePointer ptr = (NodePointer) parents.get(index);
+        return doPredicate(
+            context,
+            ptr,
+            steps,
+            currentStep,
+            predicates,
+            currentPredicate + 1);
     }
 
     /**
@@ -310,47 +641,20 @@ public class SimplePathInterpreter {
         if (!childPointer.isActual()) {
             // Property does not exist - return a null pointer
             return createNullPointer(
-                context,
-                parentPointer,
-                steps,
-                currentStep);
-        }
-
-        // Evaluate predicates
-        return doPredicate(
-            context,
-            childPointer,
-            steps,
-            currentStep,
-            predicates,
-            0);
-    }
-
-    /**
-     * Create the child pointer for a given step.
-     * @param parentPointer parent pointer
-     * @param step associated step
-     * @return NodePointer
-     */
-    private static NodePointer createChildPointerForStep(
-                final PropertyOwnerPointer parentPointer, final Step step) {
-        final int axis = step.getAxis();
-        if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) {
-            final QName name = ((NodeNameTest) step.getNodeTest()).getNodeName();
-            if (axis == Compiler.AXIS_ATTRIBUTE && isLangAttribute(name)) {
-                return new LangAttributePointer(parentPointer);
-            }
-            if (parentPointer.isValidProperty(name)) {
-                final 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;
+                context,
+                parentPointer,
+                steps,
+                currentStep);
         }
-        return parentPointer;
+
+        // Evaluate predicates
+        return doPredicate(
+            context,
+            childPointer,
+            steps,
+            currentStep,
+            predicates,
+            0);
     }
 
     /**
@@ -436,256 +740,35 @@ public class SimplePathInterpreter {
     }
 
     /**
-     * Evaluates predicates and proceeds with the subsequent steps
-     * of the path.
-     * @param context evaluation context
-     * @param parent parent pointer
-     * @param steps path steps
-     * @param currentStep step number
-     * @param predicates predicate expressions
-     * @param currentPredicate int predicate number
-     * @return NodePointer
-     */
-    private static NodePointer doPredicate(
-                final EvalContext context, final NodePointer parent,
-                final Step[] steps, final int currentStep,
-                final Expression[] predicates, final int currentPredicate) {
-        if (currentPredicate == predicates.length) {
-            return doStep(context, parent, steps, currentStep + 1);
-        }
-
-        final Expression predicate = predicates[currentPredicate];
-        if (predicate instanceof NameAttributeTest) { // [@name = key1]
-            return doPredicateName(
-                context,
-                parent,
-                steps,
-                currentStep,
-                predicates,
-                currentPredicate);
-        }
-        // else [index]
-        return doPredicateIndex(
-            context,
-            parent,
-            steps,
-            currentStep,
-            predicates,
-            currentPredicate);
-    }
-
-    /**
-     * Execute a NameAttributeTest predicate
-     * @param context evaluation context
-     * @param parent parent pointer
-     * @param steps path steps
-     * @param currentStep int step number
-     * @param predicates predicates
-     * @param currentPredicate int predicate number
-     * @return NodePointer
-     */
-    private static NodePointer doPredicateName(
-            final EvalContext context, final NodePointer parent,
-            final Step[] steps, final int currentStep,
-            final Expression[] predicates, final int currentPredicate) {
-        final Expression predicate = predicates[currentPredicate];
-        final String key = keyFromPredicate(context, predicate);
-        NodePointer child = valuePointer(parent);
-        if (child instanceof PropertyOwnerPointer) {
-            final PropertyPointer pointer =
-                ((PropertyOwnerPointer) child).getPropertyPointer();
-            pointer.setPropertyName(key);
-            if (pointer.isActual()) {
-                return doPredicate(
-                    context,
-                    pointer,
-                    steps,
-                    currentStep,
-                    predicates,
-                    currentPredicate + 1);
-            }
-        }
-        else if (child.isCollection()) {
-            // For each node in the collection, perform the following:
-            // if the node is a property owner, apply this predicate to it;
-            // if the node is a collection, apply this predicate to each elem.;
-            // if the node is not a prop owner or a collection,
-            //  see if it has the attribute "name" with the right value,
-            //  if so - proceed to the next predicate
-            NodePointer bestMatch = null;
-            int bestQuality = 0;
-            child = (NodePointer) child.clone();
-            final int count = child.getLength();
-            for (int i = 0; i < count; i++) {
-                child.setIndex(i);
-                final NodePointer valuePointer = valuePointer(child);
-                NodePointer pointer;
-                if (valuePointer instanceof PropertyOwnerPointer
-                    || valuePointer.isCollection()) {
-                    pointer =
-                        doPredicateName(
-                            context,
-                            valuePointer,
-                            steps,
-                            currentStep,
-                            predicates,
-                            currentPredicate);
-                }
-                else if (isNameAttributeEqual(valuePointer, key)) {
-                    pointer =
-                        doPredicate(
-                            context,
-                            valuePointer,
-                            steps,
-                            currentStep,
-                            predicates,
-                            currentPredicate + 1);
-                }
-                else {
-                    pointer = null;
-                }
-                if (pointer != null) {
-                    final int quality = computeQuality(pointer);
-                    if (quality == PERFECT_MATCH) {
-                        return pointer;
-                    }
-                    if (quality > bestQuality) {
-                        bestMatch = (NodePointer) pointer.clone();
-                        bestQuality = quality;
-                    }
-                }
-            }
-            if (bestMatch != null) {
-                return bestMatch;
-            }
-        }
-        else {
-            // If the node is a standard InfoSet node (e.g. DOM Node),
-            // employ doPredicates_standard, which will iterate through
-            // the node's children and apply all predicates
-            final NodePointer found =
-                doPredicatesStandard(
-                    context,
-                    Collections.singletonList(child),
-                    steps,
-                    currentStep,
-                    predicates,
-                    currentPredicate);
-            if (found != null) {
-                return found;
-            }
-        }
-        // If nothing worked - return a null pointer
-        return createNullPointerForPredicates(
-            context,
-            child,
-            steps,
-            currentStep,
-            predicates,
-            currentPredicate);
-    }
-
-    /**
-     * Called exclusively for standard InfoSet nodes, e.g. DOM nodes
-     * to evaluate predicate sequences like [@name=...][@name=...][index].
-     * @param context evaluation context
-     * @param parents List of parent pointers
-     * @param steps path steps
-     * @param currentStep step number
-     * @param predicates predicates
-     * @param currentPredicate int predicate number
-     * @return NodePointer
-     */
-    private static NodePointer doPredicatesStandard(
-                final EvalContext context, final List parents,
-                final Step[] steps, final int currentStep,
-                final Expression[] predicates, final int currentPredicate) {
-        if (parents.isEmpty()) {
-            return null;
-        }
-
-        // If all predicates have been processed, take the first
-        // element from the list of results and proceed to the
-        // remaining steps with that element.
-        if (currentPredicate == predicates.length) {
-            final NodePointer pointer = (NodePointer) parents.get(0);
-            return doStep(context, pointer, steps, currentStep + 1);
-        }
-
-        final Expression predicate = predicates[currentPredicate];
-        if (predicate instanceof NameAttributeTest) {
-            final String key = keyFromPredicate(context, predicate);
-            final List newList = new ArrayList();
-            for (int i = 0; i < parents.size(); i++) {
-                final NodePointer pointer = (NodePointer) parents.get(i);
-                if (isNameAttributeEqual(pointer, key)) {
-                    newList.add(pointer);
-                }
-            }
-            if (newList.isEmpty()) {
-                return null;
-            }
-            return doPredicatesStandard(
-                context,
-                newList,
-                steps,
-                currentStep,
-                predicates,
-                currentPredicate + 1);
-        }
-        // For a subscript, simply take the corresponding
-        // element from the list of results and
-        // proceed to the remaining predicates with that element
-        final int index = indexFromPredicate(context, predicate);
-        if (index < 0 || index >= parents.size()) {
-            return null;
-        }
-        final NodePointer ptr = (NodePointer) parents.get(index);
-        return doPredicate(
-            context,
-            ptr,
-            steps,
-            currentStep,
-            predicates,
-            currentPredicate + 1);
-    }
-
-    /**
-     * Evaluate a subscript predicate: see if the node is a collection and
-     * if the index is inside the collection.
-     * @param context evaluation context
-     * @param parent parent pointer
-     * @param steps path steps
-     * @param currentStep step number
-     * @param predicates predicates
-     * @param currentPredicate int predicate number
-     * @return NodePointer
-     */
-    private static NodePointer doPredicateIndex(
-            final EvalContext context, final NodePointer parent,
-            final Step[] steps, final int currentStep,
-            final Expression[] predicates, final int currentPredicate) {
-        final Expression predicate = predicates[currentPredicate];
-        final int index = indexFromPredicate(context, predicate);
-        NodePointer pointer = parent;
-        if (isCollectionElement(pointer, index)) {
-            pointer = (NodePointer) pointer.clone();
-            pointer.setIndex(index);
-            return doPredicate(
-                context,
-                pointer,
-                steps,
-                currentStep,
-                predicates,
-                currentPredicate + 1);
+     * Gets a NodeIterator.
+     * @param context evaluation context
+     * @param pointer owning pointer
+     * @param step triggering step
+     * @return NodeIterator
+     */
+    private static NodeIterator getNodeIterator(
+        final EvalContext context,
+        final NodePointer pointer,
+        final Step step) {
+        if (step.getAxis() == Compiler.AXIS_CHILD) {
+            NodeTest nodeTest = step.getNodeTest();
+            final QName qname = ((NodeNameTest) nodeTest).getNodeName();
+            final String prefix = qname.getPrefix();
+            if (prefix != null) {
+                final String namespaceURI = context.getJXPathContext()
+                        .getNamespaceURI(prefix);
+                nodeTest = new NodeNameTest(qname, namespaceURI);
+            }
+            return pointer.childIterator(nodeTest, false, null);
         }
-        return createNullPointerForPredicates(
-            context,
-            parent,
-            steps,
-            currentStep,
-            predicates,
-            currentPredicate);
+        // 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());
     }
 
     /**
@@ -717,49 +800,47 @@ public class SimplePathInterpreter {
     }
 
     /**
-     * Extracts the string value of the expression from a predicate like
-     * [@name=expression].
+     * Interpret the steps of a simple expression path that
+     * starts with the given root, which is the result of evaluation
+     * of the root expression of the expression path, applies the
+     * given predicates to it and then follows the given steps.
+     * All steps must have the axis "child::" or "attribute::"
+     * and a name test.  They can also optionally have predicates
+     * of type [@name=...] or simply [...] interpreted as an index.
      * @param context evaluation context
-     * @param predicate predicate to evaluate
-     * @return String key extracted
-     */
-    private static String keyFromPredicate(final EvalContext context,
-                final Expression predicate) {
-        final Expression expr =
-            ((NameAttributeTest) predicate).getNameTestExpression();
-        return InfoSetUtil.stringValue(expr.computeValue(context));
-    }
-
-    /**
-     * For a pointer that matches an actual node, returns 0.
-     * For a pointer that does not match an actual node, but whose
-     * parent pointer does returns -1, etc.
-     * @param pointer input pointer
-     * @return int match quality code
+     * @param root root pointer
+     * @param predicates predicates corresponding to {@code steps}
+     * @param steps path steps
+     * @return NodePointer
      */
-    private static int computeQuality(NodePointer pointer) {
-        int quality = PERFECT_MATCH;
-        while (pointer != null && !pointer.isActual()) {
-            quality--;
-            pointer = pointer.getImmediateParentPointer();
-        }
-        return quality;
+    public static NodePointer interpretSimpleExpressionPath(
+                final EvalContext context, final NodePointer root,
+                final Expression[] predicates, final Step[] steps) {
+//        PATH = createNullPointerForPredicates(context, root,
+//                    steps, -1, predicates, 0).toString();  // Debugging
+        final NodePointer pointer =
+            doPredicate(context, root, steps, -1, predicates, 0);
+//        return valuePointer(pointer);
+        return pointer;
     }
 
     /**
-     * Returns true if the pointer has an attribute called "name" and
-     * its value is equal to the supplied string.
-     * @param pointer input pointer
-     * @param name name to check
-     * @return boolean
+     * Interpret a simple path that starts with the given root and
+     * follows the given steps. All steps must have the axis "child::"
+     * and a name test.  They can also optionally have predicates
+     * of type [@name=expression] or simply [expression] interpreted
+     * as an index.
+     * @param context evaluation context
+     * @param root root pointer
+     * @param steps path steps
+     * @return NodePointer
      */
-    private static boolean isNameAttributeEqual(
-        final NodePointer pointer,
-        final String name) {
-        final NodeIterator it = pointer.attributeIterator(QNAME_NAME);
-        return it != null
-            && it.setPosition(1)
-            && name.equals(it.getNodePointer().getValue());
+    public static NodePointer interpretSimpleLocationPath(
+            final EvalContext context, final NodePointer root, final Step[] steps) {
+//        PATH = createNullPointer(context, root, steps, 0).toString();  // Dbg
+        final NodePointer pointer = doStep(context, root, steps, 0);
+//        return valuePointer(pointer);
+        return pointer;
     }
 
     /**
@@ -780,134 +861,53 @@ public class SimplePathInterpreter {
     }
 
     /**
-     * For an intermediate pointer (e.g. PropertyPointer, ContainerPointer)
-     * returns a pointer for the contained value.
-     * @param pointer input pointer
-     * @return NodePointer
-     */
-    private static NodePointer valuePointer(final NodePointer pointer) {
-        return pointer == null ? null : pointer.getValuePointer();
-    }
-
-    /**
-     * Creates a "null pointer" that
-     * a) represents the requested path and
-     * b) can be used for creation of missing nodes in the path.
-     * @param context evaluation context
-     * @param parent parent pointer
-     * @param steps path steps
-     * @param currentStep step number
-     * @return NodePointer
+     * Learn whether {@code name} is a lang attribute.
+     * @param name to compare
+     * @return boolean
      */
-    public static NodePointer createNullPointer(
-            final EvalContext context, NodePointer parent, final Step[] steps,
-            final int currentStep) {
-        if (currentStep == steps.length) {
-            return parent;
-        }
-
-        parent = valuePointer(parent);
-
-        final Step step = steps[currentStep];
-
-        final int axis = step.getAxis();
-        if (axis == Compiler.AXIS_CHILD || axis == Compiler.AXIS_ATTRIBUTE) {
-            final NullPropertyPointer pointer = new NullPropertyPointer(parent);
-            final QName name = ((NodeNameTest) step.getNodeTest()).getNodeName();
-            pointer.setPropertyName(name.toString());
-            pointer.setAttribute(axis == Compiler.AXIS_ATTRIBUTE);
-            parent = pointer;
-        }
-        // else { it is self::node() }
-
-        final Expression[] predicates = step.getPredicates();
-        return createNullPointerForPredicates(
-            context,
-            parent,
-            steps,
-            currentStep,
-            predicates,
-            0);
+    private static boolean isLangAttribute(final QName name) {
+        return name.getPrefix() != null
+            && name.getPrefix().equals("xml")
+            && name.getName().equals("lang");
     }
 
     /**
-     * Creates a "null pointer" that starts with predicates.
-     * @param context evaluation context
-     * @param parent parent pointer
-     * @param steps path steps
-     * @param currentStep step number
-     * @param predicates predicates
-     * @param currentPredicate int predicate number
-     * @return NodePointer
+     * Returns true if the pointer has an attribute called "name" and
+     * its value is equal to the supplied string.
+     * @param pointer input pointer
+     * @param name name to check
+     * @return boolean
      */
-    private static NodePointer createNullPointerForPredicates(
-            final EvalContext context, NodePointer parent,
-            final Step[] steps, final int currentStep,
-            final Expression[] predicates, final int currentPredicate) {
-        for (int i = currentPredicate; i < predicates.length; i++) {
-            final Expression predicate = predicates[i];
-            if (predicate instanceof NameAttributeTest) {
-                final String key = keyFromPredicate(context, predicate);
-                parent = valuePointer(parent);
-                final NullPropertyPointer pointer = new NullPropertyPointer(parent);
-                pointer.setNameAttributeValue(key);
-                parent = pointer;
-            }
-            else {
-                final int index = indexFromPredicate(context, predicate);
-                if (parent instanceof NullPropertyPointer) {
-                    parent.setIndex(index);
-                }
-                else {
-                    parent = new NullElementPointer(parent, index);
-                }
-            }
-        }
-        // Proceed with the remaining steps
-        return createNullPointer(
-                    context, parent, steps, currentStep + 1);
+    private static boolean isNameAttributeEqual(
+        final NodePointer pointer,
+        final String name) {
+        final NodeIterator it = pointer.attributeIterator(QNAME_NAME);
+        return it != null
+            && it.setPosition(1)
+            && name.equals(it.getNodePointer().getValue());
     }
 
     /**
-     * Gets a NodeIterator.
+     * Extracts the string value of the expression from a predicate like
+     * [@name=expression].
      * @param context evaluation context
-     * @param pointer owning pointer
-     * @param step triggering step
-     * @return NodeIterator
+     * @param predicate predicate to evaluate
+     * @return String key extracted
      */
-    private static NodeIterator getNodeIterator(
-        final EvalContext context,
-        final NodePointer pointer,
-        final Step step) {
-        if (step.getAxis() == Compiler.AXIS_CHILD) {
-            NodeTest nodeTest = step.getNodeTest();
-            final QName qname = ((NodeNameTest) nodeTest).getNodeName();
-            final String prefix = qname.getPrefix();
-            if (prefix != null) {
-                final 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());
+    private static String keyFromPredicate(final EvalContext context,
+                final Expression predicate) {
+        final Expression expr =
+            ((NameAttributeTest) predicate).getNameTestExpression();
+        return InfoSetUtil.stringValue(expr.computeValue(context));
     }
 
     /**
-     * Learn whether {@code name} is a lang attribute.
-     * @param name to compare
-     * @return boolean
+     * For an intermediate pointer (e.g. PropertyPointer, ContainerPointer)
+     * returns a pointer for the contained value.
+     * @param pointer input pointer
+     * @return NodePointer
      */
-    private static boolean isLangAttribute(final QName name) {
-        return name.getPrefix() != null
-            && name.getPrefix().equals("xml")
-            && name.getName().equals("lang");
+    private static NodePointer valuePointer(final NodePointer pointer) {
+        return pointer == null ? null : pointer.getValuePointer();
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/Constant.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/Constant.java
index 6fe6d36..812deb7 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/Constant.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/Constant.java
@@ -47,26 +47,26 @@ public class Constant extends Expression {
         return value;
     }
 
-    @Override
-    public Object computeValue(final EvalContext context) {
-        return value;
-    }
-
     /**
      * Returns false
      * @return false
      */
     @Override
-    public boolean isContextDependent() {
+    public boolean computeContextDependent() {
         return false;
     }
 
+    @Override
+    public Object computeValue(final EvalContext context) {
+        return value;
+    }
+
     /**
      * Returns false
      * @return false
      */
     @Override
-    public boolean computeContextDependent() {
+    public boolean isContextDependent() {
         return false;
     }
 
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
index 3eda571..c36a991 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
@@ -53,117 +53,29 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * Gets the function code.
-     * @return int function code
+     * Assert {@code count} args.
+     * @param count int
      */
-    public int getFunctionCode() {
-        return functionCode;
+    private void assertArgCount(final int count) {
+        assertArgRange(count, count);
     }
 
     /**
-     * Gets the name of this function.
-     * @return String function name
+     * Assert at least {@code min}/at most {@code max} args.
+     * @param min int
+     * @param max int
      */
-    protected String getFunctionName() {
-        switch (functionCode) {
-            case Compiler.FUNCTION_LAST :
-                return "last";
-            case Compiler.FUNCTION_POSITION :
-                return "position";
-            case Compiler.FUNCTION_COUNT :
-                return "count";
-            case Compiler.FUNCTION_ID :
-                return "id";
-            case Compiler.FUNCTION_LOCAL_NAME :
-                return "local-name";
-            case Compiler.FUNCTION_NAMESPACE_URI :
-                return "namespace-uri";
-            case Compiler.FUNCTION_NAME :
-                return "name";
-            case Compiler.FUNCTION_STRING :
-                return "string";
-            case Compiler.FUNCTION_CONCAT :
-                return "concat";
-            case Compiler.FUNCTION_STARTS_WITH :
-                return "starts-with";
-            case Compiler.FUNCTION_ENDS_WITH :
-                return "ends-with";
-            case Compiler.FUNCTION_CONTAINS :
-                return "contains";
-            case Compiler.FUNCTION_SUBSTRING_BEFORE :
-                return "substring-before";
-            case Compiler.FUNCTION_SUBSTRING_AFTER :
-                return "substring-after";
-            case Compiler.FUNCTION_SUBSTRING :
-                return "substring";
-            case Compiler.FUNCTION_STRING_LENGTH :
-                return "string-length";
-            case Compiler.FUNCTION_NORMALIZE_SPACE :
-                return "normalize-space";
-            case Compiler.FUNCTION_TRANSLATE :
-                return "translate";
-            case Compiler.FUNCTION_BOOLEAN :
-                return "boolean";
-            case Compiler.FUNCTION_NOT :
-                return "not";
-            case Compiler.FUNCTION_TRUE :
-                return "true";
-            case Compiler.FUNCTION_FALSE :
-                return "false";
-            case Compiler.FUNCTION_LANG :
-                return "lang";
-            case Compiler.FUNCTION_NUMBER :
-                return "number";
-            case Compiler.FUNCTION_SUM :
-                return "sum";
-            case Compiler.FUNCTION_FLOOR :
-                return "floor";
-            case Compiler.FUNCTION_CEILING :
-                return "ceiling";
-            case Compiler.FUNCTION_ROUND :
-                return "round";
-            case Compiler.FUNCTION_KEY :
-                return "key";
-            case Compiler.FUNCTION_FORMAT_NUMBER:
-                return "format-number";
-            default:
-                return "unknownFunction" + functionCode + "()";
+    private void assertArgRange(final int min, final int max) {
+        final int ct = getArgumentCount();
+        if (ct < min || ct > max) {
+            throw new JXPathInvalidSyntaxException(
+                    "Incorrect number of arguments: " + this);
         }
     }
 
-    /**
-     * Convenience method to return the first argument.
-     * @return Expression
-     */
-    public Expression getArg1() {
-        return args[0];
-    }
-
-    /**
-     * Convenience method to return the second argument.
-     * @return Expression
-     */
-    public Expression getArg2() {
-        return args[1];
-    }
-
-    /**
-     * Convenience method to return the third argument.
-     * @return Expression
-     */
-    public Expression getArg3() {
-        return args[2];
-    }
-
-    /**
-     * Gets the number of argument Expressions.
-     * @return int count
-     */
-    public int getArgumentCount() {
-        if (args == null) {
-            return 0;
-        }
-        return args.length;
+    @Override
+    public Object compute(final EvalContext context) {
+        return computeValue(context);
     }
 
     /**
@@ -219,29 +131,6 @@ public class CoreFunction extends Operation {
         }
     }
 
-    @Override
-    public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        buffer.append(getFunctionName());
-        buffer.append('(');
-        final Expression[] args = getArguments();
-        if (args != null) {
-            for (int i = 0; i < args.length; i++) {
-                if (i > 0) {
-                    buffer.append(", ");
-                }
-                buffer.append(args[i]);
-            }
-        }
-        buffer.append(')');
-        return buffer.toString();
-    }
-
-    @Override
-    public Object compute(final EvalContext context) {
-        return computeValue(context);
-    }
-
     @Override
     public Object computeValue(final EvalContext context) {
         switch (functionCode) {
@@ -313,36 +202,58 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * last() implementation.
+     * boolean() implementation.
+     * @param context evaluation context
+     * @return Boolean
+     */
+    protected Object functionBoolean(final EvalContext context) {
+        assertArgCount(1);
+        return InfoSetUtil.booleanValue(getArg1().computeValue(context))
+            ? Boolean.TRUE
+            : Boolean.FALSE;
+    }
+
+    /**
+     * ceiling() implementation.
      * @param context evaluation context
      * @return Number
      */
-    protected Object functionLast(final EvalContext context) {
-        assertArgCount(0);
-        // Move the position to the beginning and iterate through
-        // the context to count nodes.
-        final int old = context.getCurrentPosition();
-        context.reset();
-        int count = 0;
-        while (context.nextNode()) {
-            count++;
+    protected Object functionCeiling(final EvalContext context) {
+        assertArgCount(1);
+        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+            return Double.valueOf(v);
         }
+        return Double.valueOf(Math.ceil(v));
+    }
 
-        // Restore the current position.
-        if (old != 0) {
-            context.setPosition(old);
+    /**
+     * concat() implementation.
+     * @param context evaluation context
+     * @return String
+     */
+    protected Object functionConcat(final EvalContext context) {
+        if (getArgumentCount() < 2) {
+            assertArgCount(2);
         }
-        return Double.valueOf(count);
+        final StringBuilder buffer = new StringBuilder();
+        final Expression[] args = getArguments();
+        for (final Expression arg : args) {
+            buffer.append(InfoSetUtil.stringValue(arg.compute(context)));
+        }
+        return buffer.toString();
     }
 
     /**
-     * position() implementation.
+     * contains() implementation.
      * @param context evaluation context
-     * @return Number
+     * @return Boolean
      */
-    protected Object functionPosition(final EvalContext context) {
-        assertArgCount(0);
-        return Integer.valueOf(context.getCurrentPosition());
+    protected Object functionContains(final EvalContext context) {
+        assertArgCount(2);
+        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        return Boolean.valueOf(s1.contains(s2));
     }
 
     /**
@@ -378,56 +289,118 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * lang() implementation.
+     * ends-with() implementation.
      * @param context evaluation context
      * @return Boolean
+     * @since 1.4
      */
-    protected Object functionLang(final EvalContext context) {
-        assertArgCount(1);
-        final String lang = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final NodePointer pointer = (NodePointer) context.getSingleNodePointer();
-        if (pointer == null) {
-            return Boolean.FALSE;
-        }
-        return pointer.isLanguage(lang) ? Boolean.TRUE : Boolean.FALSE;
+    protected Object functionEndsWith(final EvalContext context) {
+        assertArgCount(2);
+        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        return s1.endsWith(s2) ? Boolean.TRUE : Boolean.FALSE;
     }
 
     /**
-     * id() implementation.
+     * false() implementation.
      * @param context evaluation context
-     * @return Pointer
+     * @return Boolean.FALSE
      */
-    protected Object functionID(final EvalContext context) {
-        assertArgCount(1);
-        final String id = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final JXPathContext jxpathContext = context.getJXPathContext();
-        final NodePointer pointer = (NodePointer) jxpathContext.getContextPointer();
-        return pointer.getPointerByID(jxpathContext, id);
+    protected Object functionFalse(final EvalContext context) {
+        assertArgCount(0);
+        return Boolean.FALSE;
     }
 
     /**
-     * key() implementation.
+     * floor() implementation.
      * @param context evaluation context
-     * @return various Object
+     * @return Number
      */
-    protected Object functionKey(final EvalContext context) {
-        assertArgCount(2);
-        final String key = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        Object value = getArg2().compute(context);
-        EvalContext ec = null;
-        if (value instanceof EvalContext) {
-            ec = (EvalContext) value;
-            if (ec.hasNext()) {
-                value = ((NodePointer) ec.next()).getValue();
-            }
-            else { // empty context -> empty results
-                return new NodeSetContext(context, new BasicNodeSet());
-            }
+    protected Object functionFloor(final EvalContext context) {
+        assertArgCount(1);
+        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+            return Double.valueOf(v);
         }
-        final JXPathContext jxpathContext = context.getJXPathContext();
-        NodeSet nodeSet = jxpathContext.getNodeSetByKey(key, value);
-        if (ec != null && ec.hasNext()) {
-            final BasicNodeSet accum = new BasicNodeSet();
+        return Double.valueOf(Math.floor(v));
+    }
+
+    /**
+     * format-number() implementation.
+     * @param context evaluation context
+     * @return String
+     */
+    private Object functionFormatNumber(final EvalContext context) {
+        final int minArgs = 2;
+        final int maxArgs = 3;
+        assertArgRange(minArgs, maxArgs);
+
+        final double number =
+            InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        final String pattern =
+            InfoSetUtil.stringValue(getArg2().computeValue(context));
+
+        DecimalFormatSymbols symbols;
+        if (getArgumentCount() == maxArgs) {
+            final String symbolsName =
+                InfoSetUtil.stringValue(getArg3().computeValue(context));
+            symbols =
+                context.getJXPathContext().getDecimalFormatSymbols(symbolsName);
+        }
+        else {
+            final NodePointer pointer = context.getCurrentNodePointer();
+            Locale locale;
+            if (pointer != null) {
+                locale = pointer.getLocale();
+            }
+            else {
+                locale = context.getJXPathContext().getLocale();
+            }
+            symbols = new DecimalFormatSymbols(locale);
+        }
+
+        final DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
+        format.setDecimalFormatSymbols(symbols);
+        format.applyLocalizedPattern(pattern);
+        return format.format(number);
+    }
+
+    /**
+     * id() implementation.
+     * @param context evaluation context
+     * @return Pointer
+     */
+    protected Object functionID(final EvalContext context) {
+        assertArgCount(1);
+        final String id = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final JXPathContext jxpathContext = context.getJXPathContext();
+        final NodePointer pointer = (NodePointer) jxpathContext.getContextPointer();
+        return pointer.getPointerByID(jxpathContext, id);
+    }
+
+    /**
+     * key() implementation.
+     * @param context evaluation context
+     * @return various Object
+     */
+    protected Object functionKey(final EvalContext context) {
+        assertArgCount(2);
+        final String key = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        Object value = getArg2().compute(context);
+        EvalContext ec = null;
+        if (value instanceof EvalContext) {
+            ec = (EvalContext) value;
+            if (ec.hasNext()) {
+                value = ((NodePointer) ec.next()).getValue();
+            }
+            else { // empty context -> empty results
+                return new NodeSetContext(context, new BasicNodeSet());
+            }
+        }
+        final JXPathContext jxpathContext = context.getJXPathContext();
+        NodeSet nodeSet = jxpathContext.getNodeSetByKey(key, value);
+        if (ec != null && ec.hasNext()) {
+            final BasicNodeSet accum = new BasicNodeSet();
             accum.add(nodeSet);
             while (ec.hasNext()) {
                 value = ((NodePointer) ec.next()).getValue();
@@ -439,27 +412,41 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * namespace-uri() implementation.
+     * lang() implementation.
      * @param context evaluation context
-     * @return String
+     * @return Boolean
      */
-    protected Object functionNamespaceURI(final EvalContext context) {
-        if (getArgumentCount() == 0) {
-            final NodePointer ptr = context.getCurrentNodePointer();
-            final String str = ptr.getNamespaceURI();
-            return str == null ? "" : str;
-        }
+    protected Object functionLang(final EvalContext context) {
         assertArgCount(1);
-        final Object set = getArg1().compute(context);
-        if (set instanceof EvalContext) {
-            final EvalContext ctx = (EvalContext) set;
-            if (ctx.hasNext()) {
-                final NodePointer ptr = (NodePointer) ctx.next();
-                final String str = ptr.getNamespaceURI();
-                return str == null ? "" : str;
-            }
+        final String lang = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final NodePointer pointer = (NodePointer) context.getSingleNodePointer();
+        if (pointer == null) {
+            return Boolean.FALSE;
         }
-        return "";
+        return pointer.isLanguage(lang) ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    /**
+     * last() implementation.
+     * @param context evaluation context
+     * @return Number
+     */
+    protected Object functionLast(final EvalContext context) {
+        assertArgCount(0);
+        // Move the position to the beginning and iterate through
+        // the context to count nodes.
+        final int old = context.getCurrentPosition();
+        context.reset();
+        int count = 0;
+        while (context.nextNode()) {
+            count++;
+        }
+
+        // Restore the current position.
+        if (old != 0) {
+            context.setPosition(old);
+        }
+        return Double.valueOf(count);
     }
 
     /**
@@ -507,106 +494,165 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * string() implementation.
+     * namespace-uri() implementation.
      * @param context evaluation context
      * @return String
      */
-    protected Object functionString(final EvalContext context) {
+    protected Object functionNamespaceURI(final EvalContext context) {
         if (getArgumentCount() == 0) {
-            return InfoSetUtil.stringValue(context.getCurrentNodePointer());
+            final NodePointer ptr = context.getCurrentNodePointer();
+            final String str = ptr.getNamespaceURI();
+            return str == null ? "" : str;
         }
         assertArgCount(1);
-        return InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final Object set = getArg1().compute(context);
+        if (set instanceof EvalContext) {
+            final EvalContext ctx = (EvalContext) set;
+            if (ctx.hasNext()) {
+                final NodePointer ptr = (NodePointer) ctx.next();
+                final String str = ptr.getNamespaceURI();
+                return str == null ? "" : str;
+            }
+        }
+        return "";
     }
 
     /**
-     * concat() implementation.
+     * normalize-space() implementation.
      * @param context evaluation context
      * @return String
      */
-    protected Object functionConcat(final EvalContext context) {
-        if (getArgumentCount() < 2) {
-            assertArgCount(2);
+    protected Object functionNormalizeSpace(final EvalContext context) {
+        assertArgCount(1);
+        final String s = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final char[] chars = s.toCharArray();
+        int out = 0;
+        int phase = 0;
+        for (int in = 0; in < chars.length; in++) {
+            switch (chars[in]) {
+                case ' ':
+                case '\t':
+                case '\r':
+                case '\n':
+                    if (phase == 1) { // non-space
+                        phase = 2;
+                        chars[out++] = ' ';
+                    }
+                    break;
+                default:
+                    chars[out++] = chars[in];
+                    phase = 1;
+            }
         }
-        final StringBuilder buffer = new StringBuilder();
-        final Expression[] args = getArguments();
-        for (final Expression arg : args) {
-            buffer.append(InfoSetUtil.stringValue(arg.compute(context)));
+        if (phase == 2) { // trailing-space
+            out--;
         }
-        return buffer.toString();
+        return new String(chars, 0, out);
     }
 
     /**
-     * starts-with() implementation.
+     * not() implementation.
      * @param context evaluation context
      * @return Boolean
      */
-    protected Object functionStartsWith(final EvalContext context) {
-        assertArgCount(2);
-        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
-        return s1.startsWith(s2) ? Boolean.TRUE : Boolean.FALSE;
+    protected Object functionNot(final EvalContext context) {
+        assertArgCount(1);
+        return InfoSetUtil.booleanValue(getArg1().computeValue(context))
+            ? Boolean.FALSE
+            : Boolean.TRUE;
     }
 
     /**
-     * ends-with() implementation.
+     * null() implementation.
      * @param context evaluation context
-     * @return Boolean
-     * @since 1.4
+     * @return null
      */
-    protected Object functionEndsWith(final EvalContext context) {
-        assertArgCount(2);
-        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
-        return s1.endsWith(s2) ? Boolean.TRUE : Boolean.FALSE;
+    protected Object functionNull(final EvalContext context) {
+        assertArgCount(0);
+        return null;
     }
 
     /**
-     * contains() implementation.
+     * number() implementation.
      * @param context evaluation context
-     * @return Boolean
+     * @return Number
      */
-    protected Object functionContains(final EvalContext context) {
-        assertArgCount(2);
-        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
-        return Boolean.valueOf(s1.contains(s2));
+    protected Object functionNumber(final EvalContext context) {
+        if (getArgumentCount() == 0) {
+            return InfoSetUtil.number(context.getCurrentNodePointer());
+        }
+        assertArgCount(1);
+        return InfoSetUtil.number(getArg1().computeValue(context));
     }
 
     /**
-     * substring-before() implementation.
+     * position() implementation.
      * @param context evaluation context
-     * @return String
+     * @return Number
      */
-    protected Object functionSubstringBefore(final EvalContext context) {
-        assertArgCount(2);
-        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
-        final int index = s1.indexOf(s2);
-        if (index == -1) {
-            return "";
-        }
-        return s1.substring(0, index);
+    protected Object functionPosition(final EvalContext context) {
+        assertArgCount(0);
+        return Integer.valueOf(context.getCurrentPosition());
     }
 
     /**
-     * substring-after() implementation.
+     * round() implementation.
      * @param context evaluation context
-     * @return String
+     * @return Number
      */
-    protected Object functionSubstringAfter(final EvalContext context) {
-        assertArgCount(2);
-        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
-        final int index = s1.indexOf(s2);
-        if (index == -1) {
-            return "";
+    protected Object functionRound(final EvalContext context) {
+        assertArgCount(1);
+        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+            return Double.valueOf(v);
         }
-        return s1.substring(index + s2.length());
+        return Double.valueOf(Math.round(v));
     }
 
     /**
-     * substring() implementation.
+     * starts-with() implementation.
+     * @param context evaluation context
+     * @return Boolean
+     */
+    protected Object functionStartsWith(final EvalContext context) {
+        assertArgCount(2);
+        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        return s1.startsWith(s2) ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    /**
+     * string() implementation.
+     * @param context evaluation context
+     * @return String
+     */
+    protected Object functionString(final EvalContext context) {
+        if (getArgumentCount() == 0) {
+            return InfoSetUtil.stringValue(context.getCurrentNodePointer());
+        }
+        assertArgCount(1);
+        return InfoSetUtil.stringValue(getArg1().computeValue(context));
+    }
+
+    /**
+     * string-length() implementation.
+     * @param context evaluation context
+     * @return Number
+     */
+    protected Object functionStringLength(final EvalContext context) {
+        String s;
+        if (getArgumentCount() == 0) {
+            s = InfoSetUtil.stringValue(context.getCurrentNodePointer());
+        }
+        else {
+            assertArgCount(1);
+            s = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        }
+        return Double.valueOf(s.length());
+    }
+
+    /**
+     * substring() implementation.
      * @param context evaluation context
      * @return String
      */
@@ -658,53 +704,59 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * string-length() implementation.
+     * substring-after() implementation.
      * @param context evaluation context
-     * @return Number
+     * @return String
      */
-    protected Object functionStringLength(final EvalContext context) {
-        String s;
-        if (getArgumentCount() == 0) {
-            s = InfoSetUtil.stringValue(context.getCurrentNodePointer());
-        }
-        else {
-            assertArgCount(1);
-            s = InfoSetUtil.stringValue(getArg1().computeValue(context));
+    protected Object functionSubstringAfter(final EvalContext context) {
+        assertArgCount(2);
+        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        final int index = s1.indexOf(s2);
+        if (index == -1) {
+            return "";
         }
-        return Double.valueOf(s.length());
+        return s1.substring(index + s2.length());
     }
 
     /**
-     * normalize-space() implementation.
+     * substring-before() implementation.
      * @param context evaluation context
      * @return String
      */
-    protected Object functionNormalizeSpace(final EvalContext context) {
+    protected Object functionSubstringBefore(final EvalContext context) {
+        assertArgCount(2);
+        final String s1 = InfoSetUtil.stringValue(getArg1().computeValue(context));
+        final String s2 = InfoSetUtil.stringValue(getArg2().computeValue(context));
+        final int index = s1.indexOf(s2);
+        if (index == -1) {
+            return "";
+        }
+        return s1.substring(0, index);
+    }
+
+    /**
+     * sum() implementation.
+     * @param context evaluation context
+     * @return Number
+     */
+    protected Object functionSum(final EvalContext context) {
         assertArgCount(1);
-        final String s = InfoSetUtil.stringValue(getArg1().computeValue(context));
-        final char[] chars = s.toCharArray();
-        int out = 0;
-        int phase = 0;
-        for (int in = 0; in < chars.length; in++) {
-            switch (chars[in]) {
-                case ' ':
-                case '\t':
-                case '\r':
-                case '\n':
-                    if (phase == 1) { // non-space
-                        phase = 2;
-                        chars[out++] = ' ';
-                    }
-                    break;
-                default:
-                    chars[out++] = chars[in];
-                    phase = 1;
-            }
+        final Object v = getArg1().compute(context);
+        if (v == null) {
+            return ZERO;
         }
-        if (phase == 2) { // trailing-space
-            out--;
+        if (v instanceof EvalContext) {
+            double sum = 0.0;
+            final EvalContext ctx = (EvalContext) v;
+            while (ctx.hasNext()) {
+                final NodePointer ptr = (NodePointer) ctx.next();
+                sum += InfoSetUtil.doubleValue(ptr);
+            }
+            return Double.valueOf(sum);
         }
-        return new String(chars, 0, out);
+        throw new JXPathException(
+            "Invalid argument type for 'sum': " + v.getClass().getName());
     }
 
     /**
@@ -735,30 +787,6 @@ public class CoreFunction extends Operation {
         return new String(chars, 0, out);
     }
 
-    /**
-     * boolean() implementation.
-     * @param context evaluation context
-     * @return Boolean
-     */
-    protected Object functionBoolean(final EvalContext context) {
-        assertArgCount(1);
-        return InfoSetUtil.booleanValue(getArg1().computeValue(context))
-            ? Boolean.TRUE
-            : Boolean.FALSE;
-    }
-
-    /**
-     * not() implementation.
-     * @param context evaluation context
-     * @return Boolean
-     */
-    protected Object functionNot(final EvalContext context) {
-        assertArgCount(1);
-        return InfoSetUtil.booleanValue(getArg1().computeValue(context))
-            ? Boolean.FALSE
-            : Boolean.TRUE;
-    }
-
     /**
      * true() implementation.
      * @param context evaluation context
@@ -770,162 +798,134 @@ public class CoreFunction extends Operation {
     }
 
     /**
-     * false() implementation.
-     * @param context evaluation context
-     * @return Boolean.FALSE
-     */
-    protected Object functionFalse(final EvalContext context) {
-        assertArgCount(0);
-        return Boolean.FALSE;
-    }
-
-    /**
-     * null() implementation.
-     * @param context evaluation context
-     * @return null
+     * Convenience method to return the first argument.
+     * @return Expression
      */
-    protected Object functionNull(final EvalContext context) {
-        assertArgCount(0);
-        return null;
+    public Expression getArg1() {
+        return args[0];
     }
 
     /**
-     * number() implementation.
-     * @param context evaluation context
-     * @return Number
+     * Convenience method to return the second argument.
+     * @return Expression
      */
-    protected Object functionNumber(final EvalContext context) {
-        if (getArgumentCount() == 0) {
-            return InfoSetUtil.number(context.getCurrentNodePointer());
-        }
-        assertArgCount(1);
-        return InfoSetUtil.number(getArg1().computeValue(context));
+    public Expression getArg2() {
+        return args[1];
     }
 
     /**
-     * sum() implementation.
-     * @param context evaluation context
-     * @return Number
+     * Convenience method to return the third argument.
+     * @return Expression
      */
-    protected Object functionSum(final EvalContext context) {
-        assertArgCount(1);
-        final Object v = getArg1().compute(context);
-        if (v == null) {
-            return ZERO;
-        }
-        if (v instanceof EvalContext) {
-            double sum = 0.0;
-            final EvalContext ctx = (EvalContext) v;
-            while (ctx.hasNext()) {
-                final NodePointer ptr = (NodePointer) ctx.next();
-                sum += InfoSetUtil.doubleValue(ptr);
-            }
-            return Double.valueOf(sum);
-        }
-        throw new JXPathException(
-            "Invalid argument type for 'sum': " + v.getClass().getName());
+    public Expression getArg3() {
+        return args[2];
     }
 
     /**
-     * floor() implementation.
-     * @param context evaluation context
-     * @return Number
+     * Gets the number of argument Expressions.
+     * @return int count
      */
-    protected Object functionFloor(final EvalContext context) {
-        assertArgCount(1);
-        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
-        if (Double.isNaN(v) || Double.isInfinite(v)) {
-            return Double.valueOf(v);
+    public int getArgumentCount() {
+        if (args == null) {
+            return 0;
         }
-        return Double.valueOf(Math.floor(v));
+        return args.length;
     }
 
     /**
-     * ceiling() implementation.
-     * @param context evaluation context
-     * @return Number
+     * Gets the function code.
+     * @return int function code
      */
-    protected Object functionCeiling(final EvalContext context) {
-        assertArgCount(1);
-        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
-        if (Double.isNaN(v) || Double.isInfinite(v)) {
-            return Double.valueOf(v);
-        }
-        return Double.valueOf(Math.ceil(v));
+    public int getFunctionCode() {
+        return functionCode;
     }
 
     /**
-     * round() implementation.
-     * @param context evaluation context
-     * @return Number
+     * Gets the name of this function.
+     * @return String function name
      */
-    protected Object functionRound(final EvalContext context) {
-        assertArgCount(1);
-        final double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
-        if (Double.isNaN(v) || Double.isInfinite(v)) {
-            return Double.valueOf(v);
+    protected String getFunctionName() {
+        switch (functionCode) {
+            case Compiler.FUNCTION_LAST :
+                return "last";
+            case Compiler.FUNCTION_POSITION :
+                return "position";
+            case Compiler.FUNCTION_COUNT :
+                return "count";
+            case Compiler.FUNCTION_ID :
+                return "id";
+            case Compiler.FUNCTION_LOCAL_NAME :
+                return "local-name";
+            case Compiler.FUNCTION_NAMESPACE_URI :
+                return "namespace-uri";
+            case Compiler.FUNCTION_NAME :
+                return "name";
+            case Compiler.FUNCTION_STRING :
+                return "string";
+            case Compiler.FUNCTION_CONCAT :
+                return "concat";
+            case Compiler.FUNCTION_STARTS_WITH :
+                return "starts-with";
+            case Compiler.FUNCTION_ENDS_WITH :
+                return "ends-with";
+            case Compiler.FUNCTION_CONTAINS :
+                return "contains";
+            case Compiler.FUNCTION_SUBSTRING_BEFORE :
+                return "substring-before";
+            case Compiler.FUNCTION_SUBSTRING_AFTER :
+                return "substring-after";
+            case Compiler.FUNCTION_SUBSTRING :
+                return "substring";
+            case Compiler.FUNCTION_STRING_LENGTH :
+                return "string-length";
+            case Compiler.FUNCTION_NORMALIZE_SPACE :
+                return "normalize-space";
+            case Compiler.FUNCTION_TRANSLATE :
+                return "translate";
+            case Compiler.FUNCTION_BOOLEAN :
+                return "boolean";
+            case Compiler.FUNCTION_NOT :
+                return "not";
+            case Compiler.FUNCTION_TRUE :
+                return "true";
+            case Compiler.FUNCTION_FALSE :
+                return "false";
+            case Compiler.FUNCTION_LANG :
+                return "lang";
+            case Compiler.FUNCTION_NUMBER :
+                return "number";
+            case Compiler.FUNCTION_SUM :
+                return "sum";
+            case Compiler.FUNCTION_FLOOR :
+                return "floor";
+            case Compiler.FUNCTION_CEILING :
+                return "ceiling";
+            case Compiler.FUNCTION_ROUND :
+                return "round";
+            case Compiler.FUNCTION_KEY :
+                return "key";
+            case Compiler.FUNCTION_FORMAT_NUMBER:
+                return "format-number";
+            default:
+                return "unknownFunction" + functionCode + "()";
         }
-        return Double.valueOf(Math.round(v));
     }
 
-    /**
-     * format-number() implementation.
-     * @param context evaluation context
-     * @return String
-     */
-    private Object functionFormatNumber(final EvalContext context) {
-        final int minArgs = 2;
-        final int maxArgs = 3;
-        assertArgRange(minArgs, maxArgs);
-
-        final double number =
-            InfoSetUtil.doubleValue(getArg1().computeValue(context));
-        final String pattern =
-            InfoSetUtil.stringValue(getArg2().computeValue(context));
-
-        DecimalFormatSymbols symbols;
-        if (getArgumentCount() == maxArgs) {
-            final String symbolsName =
-                InfoSetUtil.stringValue(getArg3().computeValue(context));
-            symbols =
-                context.getJXPathContext().getDecimalFormatSymbols(symbolsName);
-        }
-        else {
-            final NodePointer pointer = context.getCurrentNodePointer();
-            Locale locale;
-            if (pointer != null) {
-                locale = pointer.getLocale();
-            }
-            else {
-                locale = context.getJXPathContext().getLocale();
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        buffer.append(getFunctionName());
+        buffer.append('(');
+        final Expression[] args = getArguments();
+        if (args != null) {
+            for (int i = 0; i < args.length; i++) {
+                if (i > 0) {
+                    buffer.append(", ");
+                }
+                buffer.append(args[i]);
             }
-            symbols = new DecimalFormatSymbols(locale);
-        }
-
-        final DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
-        format.setDecimalFormatSymbols(symbols);
-        format.applyLocalizedPattern(pattern);
-        return format.format(number);
-    }
-
-    /**
-     * Assert {@code count} args.
-     * @param count int
-     */
-    private void assertArgCount(final int count) {
-        assertArgRange(count, count);
-    }
-
-    /**
-     * Assert at least {@code min}/at most {@code max} args.
-     * @param min int
-     * @param max int
-     */
-    private void assertArgRange(final int min, final int max) {
-        final int ct = getArgumentCount();
-        if (ct < min || ct > max) {
-            throw new JXPathInvalidSyntaxException(
-                    "Incorrect number of arguments: " + this);
         }
+        buffer.append(')');
+        return buffer.toString();
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java
index 7ae49db..db70171 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java
@@ -57,6 +57,12 @@ public abstract class CoreOperation extends Operation {
     @Override
     public abstract Object computeValue(EvalContext context);
 
+    /**
+     * Computes the precedence of the operation.
+     * @return int precedence
+     */
+    protected abstract int getPrecedence();
+
     /**
      * Returns the XPath symbol for this operation, e.g. "+", "div", etc.
      * @return String symbol
@@ -70,29 +76,6 @@ public abstract class CoreOperation extends Operation {
      */
     protected abstract boolean isSymmetric();
 
-    /**
-     * Computes the precedence of the operation.
-     * @return int precedence
-     */
-    protected abstract int getPrecedence();
-
-    @Override
-    public String toString() {
-        if (args.length == 1) {
-            return getSymbol() + parenthesize(args[0], false);
-        }
-        final StringBuilder buffer = new StringBuilder();
-        for (int i = 0; i < args.length; i++) {
-            if (i > 0) {
-                buffer.append(' ');
-                buffer.append(getSymbol());
-                buffer.append(' ');
-            }
-            buffer.append(parenthesize(args[i], i == 0));
-        }
-        return buffer.toString();
-    }
-
     /**
      * Wrap an expression in parens if necessary.
      * @param expression other Expression
@@ -114,4 +97,21 @@ public abstract class CoreOperation extends Operation {
         }
         return '(' + s + ')';
     }
+
+    @Override
+    public String toString() {
+        if (args.length == 1) {
+            return getSymbol() + parenthesize(args[0], false);
+        }
+        final StringBuilder buffer = new StringBuilder();
+        for (int i = 0; i < args.length; i++) {
+            if (i > 0) {
+                buffer.append(' ');
+                buffer.append(getSymbol());
+                buffer.append(' ');
+            }
+            buffer.append(parenthesize(args[i], i == 0));
+        }
+        return buffer.toString();
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java
index 4245030..6199fb5 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java
@@ -47,12 +47,12 @@ public class CoreOperationAdd extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return true;
+    public String getSymbol() {
+        return "+";
     }
 
     @Override
-    public String getSymbol() {
-        return "+";
+    protected boolean isSymmetric() {
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java
index 113c15e..4b76431 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java
@@ -48,12 +48,12 @@ public class CoreOperationAnd extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return true;
+    public String getSymbol() {
+        return "and";
     }
 
     @Override
-    public String getSymbol() {
-        return "and";
+    protected boolean isSymmetric() {
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java
index 5e54b91..9c331db 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java
@@ -58,14 +58,20 @@ public abstract class CoreOperationCompare extends CoreOperation {
         return equal(context, args[0], args[1]) ? Boolean.TRUE : Boolean.FALSE;
     }
 
-    @Override
-    protected int getPrecedence() {
-        return COMPARE_PRECEDENCE;
-    }
-
-    @Override
-    protected boolean isSymmetric() {
-        return true;
+    /**
+     * Learn whether it contains value.
+     * @param it Iterator to check
+     * @param value for which to look
+     * @return whether value was found
+     */
+    protected boolean contains(final Iterator it, final Object value) {
+        while (it.hasNext()) {
+            final Object element = it.next();
+            if (equal(element, value)) {
+                return true;
+            }
+        }
+        return false;
     }
 
     /**
@@ -116,41 +122,6 @@ public abstract class CoreOperationCompare extends CoreOperation {
         return equal(l, r);
     }
 
-    /**
-     * Learn whether it contains value.
-     * @param it Iterator to check
-     * @param value for which to look
-     * @return whether value was found
-     */
-    protected boolean contains(final Iterator it, final Object value) {
-        while (it.hasNext()) {
-            final Object element = it.next();
-            if (equal(element, value)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Learn whether lit intersects rit.
-     * @param lit left Iterator
-     * @param rit right Iterator
-     * @return boolean
-     */
-    protected boolean findMatch(final Iterator lit, final Iterator rit) {
-        final HashSet left = new HashSet();
-        while (lit.hasNext()) {
-            left.add(lit.next());
-        }
-        while (rit.hasNext()) {
-            if (contains(left.iterator(), rit.next())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     /**
      * Learn whether l equals r in XPath terms.
      * @param l left operand
@@ -192,4 +163,33 @@ public abstract class CoreOperationCompare extends CoreOperation {
         return result ^ invert;
     }
 
+    /**
+     * Learn whether lit intersects rit.
+     * @param lit left Iterator
+     * @param rit right Iterator
+     * @return boolean
+     */
+    protected boolean findMatch(final Iterator lit, final Iterator rit) {
+        final HashSet left = new HashSet();
+        while (lit.hasNext()) {
+            left.add(lit.next());
+        }
+        while (rit.hasNext()) {
+            if (contains(left.iterator(), rit.next())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    protected int getPrecedence() {
+        return COMPARE_PRECEDENCE;
+    }
+
+    @Override
+    protected boolean isSymmetric() {
+        return true;
+    }
+
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java
index ff5933c..7f60792 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java
@@ -46,12 +46,12 @@ public class CoreOperationDivide extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return false;
+    public String getSymbol() {
+        return "div";
     }
 
     @Override
-    public String getSymbol() {
-        return "div";
+    protected boolean isSymmetric() {
+        return false;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java
index f04a8fd..3891d2e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java
@@ -46,12 +46,12 @@ public class CoreOperationMod extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return false;
+    public String getSymbol() {
+        return "mod";
     }
 
     @Override
-    public String getSymbol() {
-        return "mod";
+    protected boolean isSymmetric() {
+        return false;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java
index df35849..e019d88 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java
@@ -46,12 +46,12 @@ public class CoreOperationMultiply extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return true;
+    public String getSymbol() {
+        return "*";
     }
 
     @Override
-    public String getSymbol() {
-        return "*";
+    protected boolean isSymmetric() {
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java
index afeeed9..23fb285 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java
@@ -44,12 +44,12 @@ public class CoreOperationNegate extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return false;
+    public String getSymbol() {
+        return "-";
     }
 
     @Override
-    public String getSymbol() {
-        return "-";
+    protected boolean isSymmetric() {
+        return false;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java
index 4b6cbf2..2866354 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java
@@ -48,12 +48,12 @@ public class CoreOperationOr extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return true;
+    public String getSymbol() {
+        return "or";
     }
 
     @Override
-    public String getSymbol() {
-        return "or";
+    protected boolean isSymmetric() {
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
index 0ea95b9..6910df6 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
@@ -39,29 +39,6 @@ public abstract class CoreOperationRelationalExpression extends CoreOperation {
         super(args);
     }
 
-    @Override
-    public final Object computeValue(final EvalContext context) {
-        return compute(args[0].compute(context), args[1].compute(context))
-                ? Boolean.TRUE : Boolean.FALSE;
-    }
-
-    @Override
-    protected final int getPrecedence() {
-        return RELATIONAL_EXPR_PRECEDENCE;
-    }
-
-    @Override
-    protected final boolean isSymmetric() {
-        return false;
-    }
-
-    /**
-     * Template method for subclasses to evaluate the result of a comparison.
-     * @param compare result of comparison to evaluate
-     * @return ultimate operation success/failure
-     */
-    protected abstract boolean evaluateCompare(int compare);
-
     /**
      * Compare left to right.
      * @param left left operand
@@ -98,19 +75,10 @@ public abstract class CoreOperationRelationalExpression extends CoreOperation {
         return evaluateCompare(ld == rd ? 0 : ld < rd ? -1 : 1);
     }
 
-    /**
-     * Reduce an operand for comparison.
-     * @param o Object to reduce
-     * @return reduced operand
-     */
-    private Object reduce(Object o) {
-        if (o instanceof SelfContext) {
-            o = ((EvalContext) o).getSingleNodePointer();
-        }
-        if (o instanceof Collection) {
-            o = ((Collection) o).iterator();
-        }
-        return o;
+    @Override
+    public final Object computeValue(final EvalContext context) {
+        return compute(args[0].compute(context), args[1].compute(context))
+                ? Boolean.TRUE : Boolean.FALSE;
     }
 
     /**
@@ -145,6 +113,13 @@ public abstract class CoreOperationRelationalExpression extends CoreOperation {
         return false;
     }
 
+    /**
+     * Template method for subclasses to evaluate the result of a comparison.
+     * @param compare result of comparison to evaluate
+     * @return ultimate operation success/failure
+     */
+    protected abstract boolean evaluateCompare(int compare);
+
     /**
      * Learn whether there is an intersection between two Iterators.
      * @param lit left Iterator
@@ -164,4 +139,29 @@ public abstract class CoreOperationRelationalExpression extends CoreOperation {
         return false;
     }
 
+    @Override
+    protected final int getPrecedence() {
+        return RELATIONAL_EXPR_PRECEDENCE;
+    }
+
+    @Override
+    protected final boolean isSymmetric() {
+        return false;
+    }
+
+    /**
+     * Reduce an operand for comparison.
+     * @param o Object to reduce
+     * @return reduced operand
+     */
+    private Object reduce(Object o) {
+        if (o instanceof SelfContext) {
+            o = ((EvalContext) o).getSingleNodePointer();
+        }
+        if (o instanceof Collection) {
+            o = ((Collection) o).iterator();
+        }
+        return o;
+    }
+
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java
index 27347b3..d72635b 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java
@@ -46,12 +46,12 @@ public class CoreOperationSubtract extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return false;
+    public String getSymbol() {
+        return "-";
     }
 
     @Override
-    public String getSymbol() {
-        return "-";
+    protected boolean isSymmetric() {
+        return false;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java
index 9718bfb..9c63686 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java
@@ -53,12 +53,12 @@ public class CoreOperationUnion extends CoreOperation {
     }
 
     @Override
-    protected boolean isSymmetric() {
-        return true;
+    public String getSymbol() {
+        return "|";
     }
 
     @Override
-    public String getSymbol() {
-        return "|";
+    protected boolean isSymmetric() {
+        return true;
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/Expression.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/Expression.java
index 30f2c4d..38ac339 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/Expression.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/Expression.java
@@ -36,92 +36,6 @@ import org.apache.commons.jxpath.util.ValueUtils;
  */
 public abstract class Expression {
 
-    /** Zero */
-    protected static final Double ZERO = Double.valueOf(0);
-
-    /** One */
-    protected static final Double ONE = Double.valueOf(1);
-
-    /** NaN */
-    protected static final Double NOT_A_NUMBER = Double.valueOf(Double.NaN);
-
-    private boolean contextDependencyKnown = false;
-    private boolean contextDependent;
-
-    /**
-     * Returns true if this expression should be re-evaluated
-     * each time the current position in the context changes.
-     * @return boolean
-     */
-    public synchronized boolean isContextDependent() {
-        if (!contextDependencyKnown) {
-            contextDependent = computeContextDependent();
-            contextDependencyKnown = true;
-        }
-        return contextDependent;
-    }
-
-    /**
-     * Implemented by subclasses and result is cached by isContextDependent()
-     * @return calculated context-dependentness as boolean
-     */
-    public abstract boolean computeContextDependent();
-
-    /**
-     * Evaluates the expression. If the result is a node set, returns
-     * the first element of the node set.
-     * @param context evaluation context
-     * @return Object
-     */
-    public abstract Object computeValue(EvalContext context);
-
-    /**
-     * Evaluates the expression. If the result is a node set, returns
-     * the first element of the node set.
-     * @param context evaluation context
-     * @return Object
-     */
-    public abstract Object compute(EvalContext context);
-
-    /**
-     * Iterate over the values from the specified context.
-     * @param context evaluation context
-     * @return value Iterator
-     */
-    public Iterator iterate(final EvalContext context) {
-        final Object result = compute(context);
-        if (result instanceof EvalContext) {
-            return new ValueIterator((EvalContext) result);
-        }
-        if (result instanceof NodeSet) {
-            return new ValueIterator(((NodeSet) result).getPointers().iterator());
-        }
-        return ValueUtils.iterate(result);
-    }
-
-    /**
-     * Iterate over the pointers from the specified context.
-     * @param context evaluation context
-     * @return pointer Iterator
-     */
-    public Iterator iteratePointers(final EvalContext context) {
-        final Object result = compute(context);
-        if (result == null) {
-            return Collections.EMPTY_LIST.iterator();
-        }
-        if (result instanceof EvalContext) {
-            return (EvalContext) result;
-        }
-        if (result instanceof NodeSet) {
-            return new PointerIterator(((NodeSet) result).getPointers().iterator(),
-                    new QName(null, "value"),
-                    context.getRootContext().getCurrentNodePointer().getLocale());
-        }
-        return new PointerIterator(ValueUtils.iterate(result),
-                new QName(null, "value"),
-                context.getRootContext().getCurrentNodePointer().getLocale());
-    }
-
     /**
      * Pointer iterator
      */
@@ -198,4 +112,90 @@ public abstract class Expression {
             throw new UnsupportedOperationException();
         }
     }
+
+    /** Zero */
+    protected static final Double ZERO = Double.valueOf(0);
+
+    /** One */
+    protected static final Double ONE = Double.valueOf(1);
+    /** NaN */
+    protected static final Double NOT_A_NUMBER = Double.valueOf(Double.NaN);
+
+    private boolean contextDependencyKnown = false;
+
+    private boolean contextDependent;
+
+    /**
+     * Evaluates the expression. If the result is a node set, returns
+     * the first element of the node set.
+     * @param context evaluation context
+     * @return Object
+     */
+    public abstract Object compute(EvalContext context);
+
+    /**
+     * Implemented by subclasses and result is cached by isContextDependent()
+     * @return calculated context-dependentness as boolean
+     */
+    public abstract boolean computeContextDependent();
+
+    /**
+     * Evaluates the expression. If the result is a node set, returns
+     * the first element of the node set.
+     * @param context evaluation context
+     * @return Object
+     */
+    public abstract Object computeValue(EvalContext context);
+
+    /**
+     * Returns true if this expression should be re-evaluated
+     * each time the current position in the context changes.
+     * @return boolean
+     */
+    public synchronized boolean isContextDependent() {
+        if (!contextDependencyKnown) {
+            contextDependent = computeContextDependent();
+            contextDependencyKnown = true;
+        }
+        return contextDependent;
+    }
+
+    /**
+     * Iterate over the values from the specified context.
+     * @param context evaluation context
+     * @return value Iterator
+     */
+    public Iterator iterate(final EvalContext context) {
+        final Object result = compute(context);
+        if (result instanceof EvalContext) {
+            return new ValueIterator((EvalContext) result);
+        }
+        if (result instanceof NodeSet) {
+            return new ValueIterator(((NodeSet) result).getPointers().iterator());
+        }
+        return ValueUtils.iterate(result);
+    }
+
+    /**
+     * Iterate over the pointers from the specified context.
+     * @param context evaluation context
+     * @return pointer Iterator
+     */
+    public Iterator iteratePointers(final EvalContext context) {
+        final Object result = compute(context);
+        if (result == null) {
+            return Collections.EMPTY_LIST.iterator();
+        }
+        if (result instanceof EvalContext) {
+            return (EvalContext) result;
+        }
+        if (result instanceof NodeSet) {
+            return new PointerIterator(((NodeSet) result).getPointers().iterator(),
+                    new QName(null, "value"),
+                    context.getRootContext().getCurrentNodePointer().getLocale());
+        }
+        return new PointerIterator(ValueUtils.iterate(result),
+                new QName(null, "value"),
+                context.getRootContext().getCurrentNodePointer().getLocale());
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java
index 3dbf891..16d55e0 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java
@@ -50,21 +50,9 @@ public class ExpressionPath extends Path {
         this.predicates = predicates;
     }
 
-    /**
-     * Gets the expression.
-     * @return Expression
-     */
-    public Expression getExpression() {
-        return expression;
-    }
-
-    /**
-     * Predicates are the expressions in brackets that may follow
-     * the root expression of the path.
-     * @return Expression[]
-     */
-    public Expression[] getPredicates() {
-        return predicates;
+    @Override
+    public Object compute(final EvalContext context) {
+        return expressionPath(context, false);
     }
 
     /**
@@ -87,55 +75,6 @@ public class ExpressionPath extends Path {
         return super.computeContextDependent();
     }
 
-    /**
-     * Recognized paths formatted as {@code $x[3]/foo[2]}.  The
-     * evaluation of such "simple" paths is optimized and streamlined.
-     * @return boolean
-     */
-    public synchronized boolean isSimpleExpressionPath() {
-        if (!basicKnown) {
-            basicKnown = true;
-            basic = isSimplePath() && areBasicPredicates(getPredicates());
-        }
-        return basic;
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        if (expression instanceof CoreOperation
-            || expression instanceof ExpressionPath
-            || expression instanceof LocationPath) {
-            buffer.append('(');
-            buffer.append(expression);
-            buffer.append(')');
-        }
-        else {
-            buffer.append(expression);
-        }
-        if (predicates != null) {
-            for (final Expression predicate : predicates) {
-                buffer.append('[');
-                buffer.append(predicate);
-                buffer.append(']');
-            }
-        }
-
-        final Step[] steps = getSteps();
-        if (steps != null) {
-            for (final Step step : steps) {
-                buffer.append("/");
-                buffer.append(step);
-            }
-        }
-        return buffer.toString();
-    }
-
-    @Override
-    public Object compute(final EvalContext context) {
-        return expressionPath(context, false);
-    }
-
     @Override
     public Object computeValue(final EvalContext context) {
         return expressionPath(context, true);
@@ -194,4 +133,65 @@ public class ExpressionPath extends Path {
         return firstMatch ? (Object) getSingleNodePointerForSteps(context)
                 : evalSteps(context);
     }
+
+    /**
+     * Gets the expression.
+     * @return Expression
+     */
+    public Expression getExpression() {
+        return expression;
+    }
+
+    /**
+     * Predicates are the expressions in brackets that may follow
+     * the root expression of the path.
+     * @return Expression[]
+     */
+    public Expression[] getPredicates() {
+        return predicates;
+    }
+
+    /**
+     * Recognized paths formatted as {@code $x[3]/foo[2]}.  The
+     * evaluation of such "simple" paths is optimized and streamlined.
+     * @return boolean
+     */
+    public synchronized boolean isSimpleExpressionPath() {
+        if (!basicKnown) {
+            basicKnown = true;
+            basic = isSimplePath() && areBasicPredicates(getPredicates());
+        }
+        return basic;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        if (expression instanceof CoreOperation
+            || expression instanceof ExpressionPath
+            || expression instanceof LocationPath) {
+            buffer.append('(');
+            buffer.append(expression);
+            buffer.append(')');
+        }
+        else {
+            buffer.append(expression);
+        }
+        if (predicates != null) {
+            for (final Expression predicate : predicates) {
+                buffer.append('[');
+                buffer.append(predicate);
+                buffer.append(']');
+            }
+        }
+
+        final Step[] steps = getSteps();
+        if (steps != null) {
+            for (final Step step : steps) {
+                buffer.append("/");
+                buffer.append(step);
+            }
+        }
+        return buffer.toString();
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java
index c45614e..bfff7c6 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java
@@ -43,12 +43,9 @@ public class ExtensionFunction extends Operation {
         this.functionName = functionName;
     }
 
-    /**
-     * Gets the function name
-     * @return QName
-     */
-    public QName getFunctionName() {
-        return functionName;
+    @Override
+    public Object compute(final EvalContext context) {
+        return computeValue(context);
     }
 
     /**
@@ -61,29 +58,6 @@ public class ExtensionFunction extends Operation {
         return true;
     }
 
-    @Override
-    public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        buffer.append(functionName);
-        buffer.append('(');
-        final Expression[] args = getArguments();
-        if (args != null) {
-            for (int i = 0; i < args.length; i++) {
-                if (i > 0) {
-                    buffer.append(", ");
-                }
-                buffer.append(args[i]);
-            }
-        }
-        buffer.append(')');
-        return buffer.toString();
-    }
-
-    @Override
-    public Object compute(final EvalContext context) {
-        return computeValue(context);
-    }
-
     @Override
     public Object computeValue(final EvalContext context) {
         Object[] parameters = null;
@@ -113,4 +87,30 @@ public class ExtensionFunction extends Operation {
     private Object convert(final Object object) {
         return object instanceof EvalContext ? ((EvalContext) object).getValue() : object;
     }
+
+    /**
+     * Gets the function name
+     * @return QName
+     */
+    public QName getFunctionName() {
+        return functionName;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        buffer.append(functionName);
+        buffer.append('(');
+        final Expression[] args = getArguments();
+        if (args != null) {
+            for (int i = 0; i < args.length; i++) {
+                if (i > 0) {
+                    buffer.append(", ");
+                }
+                buffer.append(args[i]);
+            }
+        }
+        buffer.append(')');
+        return buffer.toString();
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java
index 98afe8a..d32db0b 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java
@@ -35,34 +35,6 @@ public class LocationPath extends Path {
         this.absolute = absolute;
     }
 
-    /**
-     * Learn whether this LocationPath is absolute.
-     * @return boolean
-     */
-    public boolean isAbsolute() {
-        return absolute;
-    }
-
-    @Override
-    public boolean computeContextDependent() {
-        return !absolute || super.computeContextDependent();
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder buffer = new StringBuilder();
-        final Step[] steps = getSteps();
-        if (steps != null) {
-            for (int i = 0; i < steps.length; i++) {
-                if (i > 0 || absolute) {
-                    buffer.append('/');
-                }
-                buffer.append(steps[i]);
-            }
-        }
-        return buffer.toString();
-    }
-
     @Override
     public Object compute(final EvalContext context) {
         // Create a chain of contexts
@@ -76,6 +48,11 @@ public class LocationPath extends Path {
         return evalSteps(rootContext);
     }
 
+    @Override
+    public boolean computeContextDependent() {
+        return !absolute || super.computeContextDependent();
+    }
+
     @Override
     public Object computeValue(final EvalContext context) {
         // Create a chain of contexts
@@ -88,4 +65,27 @@ public class LocationPath extends Path {
         }
         return getSingleNodePointerForSteps(rootContext);
     }
+
+    /**
+     * Learn whether this LocationPath is absolute.
+     * @return boolean
+     */
+    public boolean isAbsolute() {
+        return absolute;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder();
+        final Step[] steps = getSteps();
+        if (steps != null) {
+            for (int i = 0; i < steps.length; i++) {
+                if (i > 0 || absolute) {
+                    buffer.append('/');
+                }
+                buffer.append(steps[i]);
+            }
+        }
+        return buffer.toString();
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java
index 629b4df..8a140b6 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java
@@ -32,6 +32,11 @@ public class NameAttributeTest extends CoreOperationEqual {
         super(namePath, nameValue);
     }
 
+    @Override
+    public boolean computeContextDependent() {
+        return true;
+    }
+
     /**
      * Gets the name test expression.
      * @return Expression
@@ -39,9 +44,4 @@ public class NameAttributeTest extends CoreOperationEqual {
     public Expression getNameTestExpression() {
         return args[1];
     }
-
-    @Override
-    public boolean computeContextDependent() {
-        return true;
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java
index 118f700..79e5357 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java
@@ -42,14 +42,6 @@ public class NodeNameTest extends NodeTest {
         this.namespaceURI = namespaceURI;
     }
 
-    /**
-     * Gets the node name.
-     * @return QName
-     */
-    public QName getNodeName() {
-        return qname;
-    }
-
     /**
      * Gets the ns URI.
      * @return String
@@ -58,6 +50,14 @@ public class NodeNameTest extends NodeTest {
         return namespaceURI;
     }
 
+    /**
+     * Gets the node name.
+     * @return QName
+     */
+    public QName getNodeName() {
+        return qname;
+    }
+
     /**
      * Learn whether this is a wildcard test.
      * @return {@code true} if the node name is "*".
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java
index 545c373..6a754ae 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java
@@ -21,6 +21,26 @@ import org.apache.commons.jxpath.ri.Compiler;
 /**
  */
 public class NodeTypeTest extends NodeTest {
+    /**
+     * Render the given node type as a String.
+     * @param code int
+     * @return String
+     */
+    public static String nodeTypeToString(final int code) {
+        switch (code) {
+            case Compiler.NODE_TYPE_NODE :
+                return "node";
+            case Compiler.NODE_TYPE_TEXT :
+                return "text";
+            case Compiler.NODE_TYPE_COMMENT :
+                return "comment";
+            case Compiler.NODE_TYPE_PI :
+                return "processing-instruction";
+            default:
+                return "UNKNOWN";
+        }
+    }
+
     private final int nodeType;
 
     /**
@@ -43,24 +63,4 @@ public class NodeTypeTest extends NodeTest {
     public String toString() {
         return nodeTypeToString(nodeType) + "()";
     }
-
-    /**
-     * Render the given node type as a String.
-     * @param code int
-     * @return String
-     */
-    public static String nodeTypeToString(final int code) {
-        switch (code) {
-            case Compiler.NODE_TYPE_NODE :
-                return "node";
-            case Compiler.NODE_TYPE_TEXT :
-                return "text";
-            case Compiler.NODE_TYPE_COMMENT :
-                return "comment";
-            case Compiler.NODE_TYPE_PI :
-                return "processing-instruction";
-            default:
-                return "UNKNOWN";
-        }
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/Operation.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/Operation.java
index b8c36b5..da59952 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/Operation.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/Operation.java
@@ -31,14 +31,6 @@ public abstract class Operation extends Expression {
         this.args = args;
     }
 
-    /**
-     * Gets the arguments.
-     * @return Expression[]
-     */
-    public Expression[] getArguments() {
-        return args;
-    }
-
     @Override
     public boolean computeContextDependent() {
         if (args != null) {
@@ -50,4 +42,12 @@ public abstract class Operation extends Expression {
         }
         return false;
     }
+
+    /**
+     * Gets the arguments.
+     * @return Expression[]
+     */
+    public Expression[] getArguments() {
+        return args;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/Path.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/Path.java
index 2e712ea..c9daad8 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/Path.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/Path.java
@@ -51,11 +51,69 @@ public abstract class Path extends Expression {
     }
 
     /**
-     * Gets the steps.
-     * @return Step[]
+     * Learn whether the elements of the specified array are "basic" predicates.
+     * @param predicates the Expression[] to check
+     * @return boolean
      */
-    public Step[] getSteps() {
-        return steps;
+    protected boolean areBasicPredicates(final Expression[] predicates) {
+        if (predicates != null && predicates.length != 0) {
+            boolean firstIndex = true;
+            for (final Expression predicate : predicates) {
+                if (predicate instanceof NameAttributeTest) {
+                    if (((NameAttributeTest) predicate)
+                        .getNameTestExpression()
+                        .isContextDependent()) {
+                        return false;
+                    }
+                }
+                else if (predicate.isContextDependent()) {
+                    return false;
+                }
+                else {
+                    if (!firstIndex) {
+                        return false;
+                    }
+                    firstIndex = false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Build a context from a chain of contexts.
+     * @param context evaluation context
+     * @param stepCount number of steps to descend
+     * @param createInitialContext whether to create the initial context
+     * @return created context
+     */
+    protected EvalContext buildContextChain(
+            EvalContext context,
+            final int stepCount,
+            final boolean createInitialContext) {
+        if (createInitialContext) {
+            context = new InitialContext(context);
+        }
+        if (steps.length == 0) {
+            return context;
+        }
+        for (int i = 0; i < stepCount; i++) {
+            context =
+                createContextForStep(
+                    context,
+                    steps[i].getAxis(),
+                    steps[i].getNodeTest());
+            final Expression[] predicates = steps[i].getPredicates();
+            if (predicates != null) {
+                for (int j = 0; j < predicates.length; j++) {
+                    if (j != 0) {
+                        context = new UnionContext(context, new EvalContext[]{context});
+                    }
+                    context = new PredicateContext(context, predicates[j]);
+                }
+            }
+        }
+        return context;
     }
 
     @Override
@@ -70,6 +128,99 @@ public abstract class Path extends Expression {
         return false;
     }
 
+    /**
+     * Different axes are serviced by different contexts. This method
+     * allocates the right context for the supplied step.
+     * @param context evaluation context
+     * @param axis code
+     * @param nodeTest node test
+     * @return EvalContext
+     */
+    protected EvalContext createContextForStep(
+        final EvalContext context,
+        final int axis,
+        NodeTest nodeTest) {
+        if (nodeTest instanceof NodeNameTest) {
+            final QName qname = ((NodeNameTest) nodeTest).getNodeName();
+            final String prefix = qname.getPrefix();
+            if (prefix != null) {
+                final String namespaceURI = context.getJXPathContext()
+                        .getNamespaceURI(prefix);
+                nodeTest = new NodeNameTest(qname, namespaceURI);
+            }
+        }
+
+        switch (axis) {
+        case Compiler.AXIS_ANCESTOR :
+            return new AncestorContext(context, false, nodeTest);
+        case Compiler.AXIS_ANCESTOR_OR_SELF :
+            return new AncestorContext(context, true, nodeTest);
+        case Compiler.AXIS_ATTRIBUTE :
+            return new AttributeContext(context, nodeTest);
+        case Compiler.AXIS_CHILD :
+            return new ChildContext(context, nodeTest, false, false);
+        case Compiler.AXIS_DESCENDANT :
+            return new DescendantContext(context, false, nodeTest);
+        case Compiler.AXIS_DESCENDANT_OR_SELF :
+            return new DescendantContext(context, true, nodeTest);
+        case Compiler.AXIS_FOLLOWING :
+            return new PrecedingOrFollowingContext(context, nodeTest, false);
+        case Compiler.AXIS_FOLLOWING_SIBLING :
+            return new ChildContext(context, nodeTest, true, false);
+        case Compiler.AXIS_NAMESPACE :
+            return new NamespaceContext(context, nodeTest);
+        case Compiler.AXIS_PARENT :
+            return new ParentContext(context, nodeTest);
+        case Compiler.AXIS_PRECEDING :
+            return new PrecedingOrFollowingContext(context, nodeTest, true);
+        case Compiler.AXIS_PRECEDING_SIBLING :
+            return new ChildContext(context, nodeTest, true, true);
+        case Compiler.AXIS_SELF :
+            return new SelfContext(context, nodeTest);
+        default:
+            return null; // Never happens
+        }
+    }
+
+    /**
+     * Given a root context, walks a path therefrom and builds a context
+     * that contains all nodes matching the path.
+     * @param context evaluation context
+     * @return EvaluationContext
+     */
+    protected EvalContext evalSteps(final EvalContext context) {
+        return buildContextChain(context, steps.length, false);
+    }
+
+    /**
+     * Given a root context, walks a path therefrom and finds the
+     * pointer to the first element matching the path.
+     * @param context evaluation context
+     * @return Pointer
+     */
+    protected Pointer getSingleNodePointerForSteps(final EvalContext context) {
+        if (steps.length == 0) {
+            return context.getSingleNodePointer();
+        }
+
+        if (isSimplePath()) {
+            final NodePointer ptr = (NodePointer) context.getSingleNodePointer();
+            return SimplePathInterpreter.interpretSimpleLocationPath(
+                context,
+                ptr,
+                steps);
+        }
+        return searchForPath(context);
+    }
+
+    /**
+     * Gets the steps.
+     * @return Step[]
+     */
+    public Step[] getSteps() {
+        return steps;
+    }
+
     /**
      * Recognizes paths formatted as {@code foo/bar[3]/baz[@name = 'biz']}.
      * The evaluation of such "simple" paths is optimized and
@@ -124,57 +275,6 @@ public abstract class Path extends Expression {
         return false;
     }
 
-    /**
-     * Learn whether the elements of the specified array are "basic" predicates.
-     * @param predicates the Expression[] to check
-     * @return boolean
-     */
-    protected boolean areBasicPredicates(final Expression[] predicates) {
-        if (predicates != null && predicates.length != 0) {
-            boolean firstIndex = true;
-            for (final Expression predicate : predicates) {
-                if (predicate instanceof NameAttributeTest) {
-                    if (((NameAttributeTest) predicate)
-                        .getNameTestExpression()
-                        .isContextDependent()) {
-                        return false;
-                    }
-                }
-                else if (predicate.isContextDependent()) {
-                    return false;
-                }
-                else {
-                    if (!firstIndex) {
-                        return false;
-                    }
-                    firstIndex = false;
-                }
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Given a root context, walks a path therefrom and finds the
-     * pointer to the first element matching the path.
-     * @param context evaluation context
-     * @return Pointer
-     */
-    protected Pointer getSingleNodePointerForSteps(final EvalContext context) {
-        if (steps.length == 0) {
-            return context.getSingleNodePointer();
-        }
-
-        if (isSimplePath()) {
-            final NodePointer ptr = (NodePointer) context.getSingleNodePointer();
-            return SimplePathInterpreter.interpretSimpleLocationPath(
-                context,
-                ptr,
-                steps);
-        }
-        return searchForPath(context);
-    }
-
     /**
      * The idea here is to return a NullPointer rather than null if that's at
      * all possible. Take for example this path: "//map/key". Let's say, "map"
@@ -226,104 +326,4 @@ public abstract class Path extends Expression {
         }
         return null;
     }
-
-    /**
-     * Given a root context, walks a path therefrom and builds a context
-     * that contains all nodes matching the path.
-     * @param context evaluation context
-     * @return EvaluationContext
-     */
-    protected EvalContext evalSteps(final EvalContext context) {
-        return buildContextChain(context, steps.length, false);
-    }
-
-    /**
-     * Build a context from a chain of contexts.
-     * @param context evaluation context
-     * @param stepCount number of steps to descend
-     * @param createInitialContext whether to create the initial context
-     * @return created context
-     */
-    protected EvalContext buildContextChain(
-            EvalContext context,
-            final int stepCount,
-            final boolean createInitialContext) {
-        if (createInitialContext) {
-            context = new InitialContext(context);
-        }
-        if (steps.length == 0) {
-            return context;
-        }
-        for (int i = 0; i < stepCount; i++) {
-            context =
-                createContextForStep(
-                    context,
-                    steps[i].getAxis(),
-                    steps[i].getNodeTest());
-            final Expression[] predicates = steps[i].getPredicates();
-            if (predicates != null) {
-                for (int j = 0; j < predicates.length; j++) {
-                    if (j != 0) {
-                        context = new UnionContext(context, new EvalContext[]{context});
-                    }
-                    context = new PredicateContext(context, predicates[j]);
-                }
-            }
-        }
-        return context;
-    }
-
-    /**
-     * Different axes are serviced by different contexts. This method
-     * allocates the right context for the supplied step.
-     * @param context evaluation context
-     * @param axis code
-     * @param nodeTest node test
-     * @return EvalContext
-     */
-    protected EvalContext createContextForStep(
-        final EvalContext context,
-        final int axis,
-        NodeTest nodeTest) {
-        if (nodeTest instanceof NodeNameTest) {
-            final QName qname = ((NodeNameTest) nodeTest).getNodeName();
-            final String prefix = qname.getPrefix();
-            if (prefix != null) {
-                final String namespaceURI = context.getJXPathContext()
-                        .getNamespaceURI(prefix);
-                nodeTest = new NodeNameTest(qname, namespaceURI);
-            }
-        }
-
-        switch (axis) {
-        case Compiler.AXIS_ANCESTOR :
-            return new AncestorContext(context, false, nodeTest);
-        case Compiler.AXIS_ANCESTOR_OR_SELF :
-            return new AncestorContext(context, true, nodeTest);
-        case Compiler.AXIS_ATTRIBUTE :
-            return new AttributeContext(context, nodeTest);
-        case Compiler.AXIS_CHILD :
-            return new ChildContext(context, nodeTest, false, false);
-        case Compiler.AXIS_DESCENDANT :
-            return new DescendantContext(context, false, nodeTest);
-        case Compiler.AXIS_DESCENDANT_OR_SELF :
-            return new DescendantContext(context, true, nodeTest);
-        case Compiler.AXIS_FOLLOWING :
-            return new PrecedingOrFollowingContext(context, nodeTest, false);
-        case Compiler.AXIS_FOLLOWING_SIBLING :
-            return new ChildContext(context, nodeTest, true, false);
-        case Compiler.AXIS_NAMESPACE :
-            return new NamespaceContext(context, nodeTest);
-        case Compiler.AXIS_PARENT :
-            return new ParentContext(context, nodeTest);
-        case Compiler.AXIS_PRECEDING :
-            return new PrecedingOrFollowingContext(context, nodeTest, true);
-        case Compiler.AXIS_PRECEDING_SIBLING :
-            return new ChildContext(context, nodeTest, true, true);
-        case Compiler.AXIS_SELF :
-            return new SelfContext(context, nodeTest);
-        default:
-            return null; // Never happens
-        }
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/Step.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/Step.java
index 09c23b3..7cbc63f 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/Step.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/Step.java
@@ -21,8 +21,48 @@ import org.apache.commons.jxpath.ri.Compiler;
 /**
  */
 public class Step {
+    /**
+     * Decode an axis code to its name.
+     * @param axis int code
+     * @return String name.
+     * @see Compiler
+     * @see "http://www.w3.org/TR/xpath#axes"
+     */
+    public static String axisToString(final int axis) {
+        switch (axis) {
+            case Compiler.AXIS_SELF :
+                return "self";
+            case Compiler.AXIS_CHILD :
+                return "child";
+            case Compiler.AXIS_PARENT :
+                return "parent";
+            case Compiler.AXIS_ANCESTOR :
+                return "ancestor";
+            case Compiler.AXIS_ATTRIBUTE :
+                return "attribute";
+            case Compiler.AXIS_NAMESPACE :
+                return "namespace";
+            case Compiler.AXIS_PRECEDING :
+                return "preceding";
+            case Compiler.AXIS_FOLLOWING :
+                return "following";
+            case Compiler.AXIS_DESCENDANT :
+                return "descendant";
+            case Compiler.AXIS_ANCESTOR_OR_SELF :
+                return "ancestor-or-self";
+            case Compiler.AXIS_FOLLOWING_SIBLING :
+                return "following-sibling";
+            case Compiler.AXIS_PRECEDING_SIBLING :
+                return "preceding-sibling";
+            case Compiler.AXIS_DESCENDANT_OR_SELF :
+                return "descendant-or-self";
+            default:
+                return "UNKNOWN";
+        }
+    }
     private final int axis;
     private final NodeTest nodeTest;
+
     private final Expression[] predicates;
 
     /**
@@ -121,44 +161,4 @@ public class Step {
         }
         return buffer.toString();
     }
-
-    /**
-     * Decode an axis code to its name.
-     * @param axis int code
-     * @return String name.
-     * @see Compiler
-     * @see "http://www.w3.org/TR/xpath#axes"
-     */
-    public static String axisToString(final int axis) {
-        switch (axis) {
-            case Compiler.AXIS_SELF :
-                return "self";
-            case Compiler.AXIS_CHILD :
-                return "child";
-            case Compiler.AXIS_PARENT :
-                return "parent";
-            case Compiler.AXIS_ANCESTOR :
-                return "ancestor";
-            case Compiler.AXIS_ATTRIBUTE :
-                return "attribute";
-            case Compiler.AXIS_NAMESPACE :
-                return "namespace";
-            case Compiler.AXIS_PRECEDING :
-                return "preceding";
-            case Compiler.AXIS_FOLLOWING :
-                return "following";
-            case Compiler.AXIS_DESCENDANT :
-                return "descendant";
-            case Compiler.AXIS_ANCESTOR_OR_SELF :
-                return "ancestor-or-self";
-            case Compiler.AXIS_FOLLOWING_SIBLING :
-                return "following-sibling";
-            case Compiler.AXIS_PRECEDING_SIBLING :
-                return "preceding-sibling";
-            case Compiler.AXIS_DESCENDANT_OR_SELF :
-                return "descendant-or-self";
-            default:
-                return "UNKNOWN";
-        }
-    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java
index 2fb074d..033a59e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java
@@ -26,45 +26,80 @@ public class TreeCompiler implements Compiler {
     private static final QName QNAME_NAME = new QName(null, "name");
 
     @Override
-    public Object number(final String value) {
-        return new Constant(Double.valueOf(value));
+    public Object and(final Object[] arguments) {
+        return new CoreOperationAnd(toExpressionArray(arguments));
     }
 
     @Override
-    public Object literal(final String value) {
-        return new Constant(value);
+    public Object divide(final Object left, final Object right) {
+        return new CoreOperationDivide((Expression) left, (Expression) right);
     }
 
     @Override
-    public Object qname(final String prefix, final String name) {
-        return new QName(prefix, name);
+    public Object equal(final Object left, final Object right) {
+        return isNameAttributeTest((Expression) left)
+                ? new NameAttributeTest((Expression) left, (Expression) right)
+                : new CoreOperationEqual((Expression) left, (Expression) right);
     }
 
     @Override
-    public Object sum(final Object[] arguments) {
-        return new CoreOperationAdd(toExpressionArray(arguments));
+    public Object expressionPath(final Object expression, final Object[] predicates,
+            final Object[] steps) {
+        return new ExpressionPath(
+            (Expression) expression,
+            toExpressionArray(predicates),
+            toStepArray(steps));
     }
 
     @Override
-    public Object minus(final Object left, final Object right) {
-        return new CoreOperationSubtract(
-            (Expression) left,
-            (Expression) right);
+    public Object function(final int code, final Object[] args) {
+        return new CoreFunction(code, toExpressionArray(args));
     }
 
     @Override
-    public Object multiply(final Object left, final Object right) {
-        return new CoreOperationMultiply((Expression) left, (Expression) right);
+    public Object function(final Object name, final Object[] args) {
+        return new ExtensionFunction((QName) name, toExpressionArray(args));
     }
 
     @Override
-    public Object divide(final Object left, final Object right) {
-        return new CoreOperationDivide((Expression) left, (Expression) right);
+    public Object greaterThan(final Object left, final Object right) {
+        return new CoreOperationGreaterThan(
+            (Expression) left,
+            (Expression) right);
     }
 
     @Override
-    public Object mod(final Object left, final Object right) {
-        return new CoreOperationMod((Expression) left, (Expression) right);
+    public Object greaterThanOrEqual(final Object left, final Object right) {
+        return new CoreOperationGreaterThanOrEqual(
+            (Expression) left,
+            (Expression) right);
+    }
+
+    /**
+     * Learn whether arg is a name attribute test.
+     * @param arg Expression to test
+     * @return boolean
+     */
+    private boolean isNameAttributeTest(final Expression arg) {
+        if (!(arg instanceof LocationPath)) {
+            return false;
+        }
+
+        final Step[] steps = ((LocationPath) arg).getSteps();
+        if (steps.length != 1) {
+            return false;
+        }
+        if (steps[0].getAxis() != AXIS_ATTRIBUTE) {
+            return false;
+        }
+        final NodeTest test = steps[0].getNodeTest();
+        if (!(test instanceof NodeNameTest)) {
+            return false;
+        }
+        if (!((NodeNameTest) test).getNodeName().equals(QNAME_NAME)) {
+            return false;
+        }
+        return true;
     }
 
     @Override
@@ -80,29 +115,13 @@ public class TreeCompiler implements Compiler {
     }
 
     @Override
-    public Object greaterThan(final Object left, final Object right) {
-        return new CoreOperationGreaterThan(
-            (Expression) left,
-            (Expression) right);
-    }
-
-    @Override
-    public Object greaterThanOrEqual(final Object left, final Object right) {
-        return new CoreOperationGreaterThanOrEqual(
-            (Expression) left,
-            (Expression) right);
-    }
-
-    @Override
-    public Object equal(final Object left, final Object right) {
-        return isNameAttributeTest((Expression) left)
-                ? new NameAttributeTest((Expression) left, (Expression) right)
-                : new CoreOperationEqual((Expression) left, (Expression) right);
+    public Object literal(final String value) {
+        return new Constant(value);
     }
 
     @Override
-    public Object notEqual(final Object left, final Object right) {
-        return new CoreOperationNotEqual((Expression) left, (Expression) right);
+    public Object locationPath(final boolean absolute, final Object[] steps) {
+        return new LocationPath(absolute, toStepArray(steps));
     }
 
     @Override
@@ -111,62 +130,55 @@ public class TreeCompiler implements Compiler {
     }
 
     @Override
-    public Object variableReference(final Object qName) {
-        return new VariableReference((QName) qName);
-    }
-
-    @Override
-    public Object function(final int code, final Object[] args) {
-        return new CoreFunction(code, toExpressionArray(args));
+    public Object minus(final Object left, final Object right) {
+        return new CoreOperationSubtract(
+            (Expression) left,
+            (Expression) right);
     }
 
     @Override
-    public Object function(final Object name, final Object[] args) {
-        return new ExtensionFunction((QName) name, toExpressionArray(args));
+    public Object mod(final Object left, final Object right) {
+        return new CoreOperationMod((Expression) left, (Expression) right);
     }
 
     @Override
-    public Object and(final Object[] arguments) {
-        return new CoreOperationAnd(toExpressionArray(arguments));
+    public Object multiply(final Object left, final Object right) {
+        return new CoreOperationMultiply((Expression) left, (Expression) right);
     }
 
     @Override
-    public Object or(final Object[] arguments) {
-        return new CoreOperationOr(toExpressionArray(arguments));
+    public Object nodeNameTest(final Object qname) {
+        return new NodeNameTest((QName) qname);
     }
 
     @Override
-    public Object union(final Object[] arguments) {
-        return new CoreOperationUnion(toExpressionArray(arguments));
+    public Object nodeTypeTest(final int nodeType) {
+        return new NodeTypeTest(nodeType);
     }
 
     @Override
-    public Object locationPath(final boolean absolute, final Object[] steps) {
-        return new LocationPath(absolute, toStepArray(steps));
+    public Object notEqual(final Object left, final Object right) {
+        return new CoreOperationNotEqual((Expression) left, (Expression) right);
     }
 
     @Override
-    public Object expressionPath(final Object expression, final Object[] predicates,
-            final Object[] steps) {
-        return new ExpressionPath(
-            (Expression) expression,
-            toExpressionArray(predicates),
-            toStepArray(steps));
+    public Object number(final String value) {
+        return new Constant(Double.valueOf(value));
     }
 
     @Override
-    public Object nodeNameTest(final Object qname) {
-        return new NodeNameTest((QName) qname);
+    public Object or(final Object[] arguments) {
+        return new CoreOperationOr(toExpressionArray(arguments));
     }
 
     @Override
-    public Object nodeTypeTest(final int nodeType) {
-        return new NodeTypeTest(nodeType);
+    public Object processingInstructionTest(final String instruction) {
+        return new ProcessingInstructionTest(instruction);
     }
 
     @Override
-    public Object processingInstructionTest(final String instruction) {
-        return new ProcessingInstructionTest(instruction);
+    public Object qname(final String prefix, final String name) {
+        return new QName(prefix, name);
     }
 
     @Override
@@ -177,6 +189,11 @@ public class TreeCompiler implements Compiler {
             toExpressionArray(predicates));
     }
 
+    @Override
+    public Object sum(final Object[] arguments) {
+        return new CoreOperationAdd(toExpressionArray(arguments));
+    }
+
     /**
      * Gets an Object[] as an Expression[].
      * @param array Object[]
@@ -209,30 +226,13 @@ public class TreeCompiler implements Compiler {
         return stepArray;
     }
 
-    /**
-     * Learn whether arg is a name attribute test.
-     * @param arg Expression to test
-     * @return boolean
-     */
-    private boolean isNameAttributeTest(final Expression arg) {
-        if (!(arg instanceof LocationPath)) {
-            return false;
-        }
+    @Override
+    public Object union(final Object[] arguments) {
+        return new CoreOperationUnion(toExpressionArray(arguments));
+    }
 
-        final Step[] steps = ((LocationPath) arg).getSteps();
-        if (steps.length != 1) {
-            return false;
-        }
-        if (steps[0].getAxis() != AXIS_ATTRIBUTE) {
-            return false;
-        }
-        final NodeTest test = steps[0].getNodeTest();
-        if (!(test instanceof NodeNameTest)) {
-            return false;
-        }
-        if (!((NodeNameTest) test).getNodeName().equals(QNAME_NAME)) {
-            return false;
-        }
-        return true;
+    @Override
+    public Object variableReference(final Object qName) {
+        return new VariableReference((QName) qName);
     }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java
index c0f664c..41a0091 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java
@@ -34,22 +34,9 @@ public class VariableReference extends Expression {
         this.varName = varName;
     }
 
-    /**
-     * Gets the variable name.
-     * @return QName
-     */
-    public QName getVariableName() {
-        return varName;
-    }
-
-    @Override
-    public String toString() {
-        return "$" + varName;
-    }
-
     @Override
-    public boolean isContextDependent() {
-        return false;
+    public Object compute(final EvalContext context) {
+        return computeValue(context);
     }
 
     @Override
@@ -57,11 +44,6 @@ public class VariableReference extends Expression {
         return false;
     }
 
-    @Override
-    public Object compute(final EvalContext context) {
-        return computeValue(context);
-    }
-
     /**
      * Returns the value of the variable.
      * @param context EvalContext against which to compute the variable's value.
@@ -71,4 +53,22 @@ public class VariableReference extends Expression {
     public Object computeValue(final EvalContext context) {
         return context.getRootContext().getVariableContext(varName);
     }
+
+    /**
+     * Gets the variable name.
+     * @return QName
+     */
+    public QName getVariableName() {
+        return varName;
+    }
+
+    @Override
+    public boolean isContextDependent() {
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return "$" + varName;
+    }
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/NodeIterator.java b/src/main/java/org/apache/commons/jxpath/ri/model/NodeIterator.java
index 4205226..9521fdf 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/NodeIterator.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/NodeIterator.java
@@ -21,6 +21,12 @@ package org.apache.commons.jxpath.ri.model;
  */
 public interface NodeIterator {
 
+    /**
+     * Gets the NodePointer at the current position.
+     * @return NodePointer
+     */
+    NodePointer getNodePointer();
+
     /**
      * Gets the current iterator position.
      * @return int position
@@ -33,10 +39,4 @@ public interface NodeIterator {
      * @return {@code true} if there is a node at {@code position}.
      */
     boolean setPosition(int position);
-
-    /**
-     * Gets the NodePointer at the current position.
-     * @return NodePointer
-     */
-    NodePointer getNodePointer();
 }
diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/NodePointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/NodePointer.java
index 04dfa2d..b69c206 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/NodePointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/NodePointer.java
@@ -52,36 +52,23 @@ public abstract class NodePointer implements Pointer {
     /** Constant to indicate unknown namespace */
     public static final String UNKNOWN_NAMESPACE = "<<unknown namespace>>";
 
-    /** Index for this NodePointer */
-    protected int index = WHOLE_COLLECTION;
-
-    private boolean attribute = false;
-    private NamespaceResolver namespaceResolver;
-    private ExceptionHandler exceptionHandler;
-    private transient Object rootNode;
-
     /**
-     * Allocates an entirely new NodePointer by iterating through all installed
+     * 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
-     * @param locale Locale
      * @return NodePointer
      */
-    public static NodePointer newNodePointer(
+    public static NodePointer newChildNodePointer(
+        final NodePointer parent,
         final QName name,
-        final Object bean,
-        final Locale locale) {
-        NodePointer pointer;
-        if (bean == null) {
-            pointer = new NullPointer(name, locale);
-            return pointer;
-        }
-
+        final Object bean) {
         final NodePointerFactory[] factories =
             JXPathContextReferenceImpl.getNodePointerFactories();
         for (final NodePointerFactory element : factories) {
-            pointer = element.createNodePointer(name, bean, locale);
+            final NodePointer pointer =
+                element.createNodePointer(parent, name, bean);
             if (pointer != null) {
                 return pointer;
             }
@@ -92,22 +79,27 @@ public abstract class NodePointer implements Pointer {
     }
 
     /**
-     * Allocates an new child NodePointer by iterating through all installed
+     * Allocates an entirely new 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
+     * @param locale Locale
      * @return NodePointer
      */
-    public static NodePointer newChildNodePointer(
-        final NodePointer parent,
+    public static NodePointer newNodePointer(
         final QName name,
-        final Object bean) {
+        final Object bean,
+        final Locale locale) {
+        NodePointer pointer;
+        if (bean == null) {
+            pointer = new NullPointer(name, locale);
+            return pointer;
+        }
+
         final NodePointerFactory[] factories =
             JXPathContextReferenceImpl.getNodePointerFactories();
         for (final NodePointerFactory element : factories) {
-            final NodePointer pointer =
-                element.createNodePointer(parent, name, bean);
+            pointer = element.createNodePointer(name, bean, locale);
             if (pointer != null) {
                 return pointer;
             }
@@ -116,6 +108,70 @@ public abstract class NodePointer implements Pointer {
             "Could not allocate a NodePointer for object of "
                 + bean.getClass());
     }
+    /**
+     * Print deep
+     * @param pointer to print
+     * @param indent indentation level
+     */
+    private static void printDeep(final NodePointer pointer, final String indent) {
+        if (indent.length() == 0) {
+            System.err.println(
+                "POINTER: "
+                    + pointer
+                    + "("
+                    + pointer.getClass().getName()
+                    + ")");
+        }
+        else {
+            System.err.println(
+                indent
+                    + " of "
+                    + pointer
+                    + "("
+                    + pointer.getClass().getName()
+                    + ")");
+        }
+        if (pointer.getImmediateParentPointer() != null) {
+            printDeep(pointer.getImmediateParentPointer(), indent + "  ");
+        }
+    }
+    private static boolean safeEquals(final Object o1, final Object o2) {
+        return o1 == o2 || o1 != null && o1.equals(o2);
+    }
+    /**
+     * Verify the structure of a given NodePointer.
+     * @param nodePointer to check
+     * @return nodePointer
+     * @throws JXPathNotFoundException Thrown when there is no value at the NodePointer.
+     */
+    public static NodePointer verify(final NodePointer nodePointer) {
+        if (!nodePointer.isActual()) {
+            // We need to differentiate between pointers representing
+            // a non-existing property and ones representing a property
+            // whose value is null.  In the latter case, the pointer
+            // is going to have isActual == false, but its parent,
+            // which is a non-node pointer identifying the bean property,
+            // will return isActual() == true.
+            final NodePointer parent = nodePointer.getImmediateParentPointer();
+            if (parent == null
+                || !parent.isContainer()
+                || !parent.isActual()) {
+                throw new JXPathNotFoundException("No value for xpath: " + nodePointer);
+            }
+        }
+        return nodePointer;
+    }
+
+    /** Index for this NodePointer */
+    protected int index = WHOLE_COLLECTION;
+
+    private boolean attribute = false;
+
+    private NamespaceResolver namespaceResolver;
+
+    private ExceptionHandler exceptionHandler;
+
+    private transient Object rootNode;
 
     /** Parent pointer */
     protected NodePointer parent;
@@ -142,199 +198,288 @@ public abstract class NodePointer implements Pointer {
     }
 
     /**
-     * Gets the NamespaceResolver associated with this NodePointer.
-     * @return NamespaceResolver
+     * Returns an XPath that maps to this Pointer.
+     * @return String xpath expression
      */
-    public NamespaceResolver getNamespaceResolver() {
-        if (namespaceResolver == null && parent != null) {
-            namespaceResolver = parent.getNamespaceResolver();
+    @Override
+    public String asPath() {
+        // If the parent of this node is a container, it is responsible
+        // for appended this node's part of the path.
+        if (parent != null && parent.isContainer()) {
+            return parent.asPath();
         }
-        return namespaceResolver;
-    }
-
-    /**
-     * Sets the NamespaceResolver for this NodePointer.
-     * @param namespaceResolver NamespaceResolver
-     */
-    public void setNamespaceResolver(final NamespaceResolver namespaceResolver) {
-        this.namespaceResolver = namespaceResolver;
-    }
 
-    /**
-     * Gets the parent pointer.
-     * @return NodePointer
-     */
-    public NodePointer getParent() {
-        NodePointer pointer = parent;
-        while (pointer != null && pointer.isContainer()) {
-            pointer = pointer.getImmediateParentPointer();
+        final StringBuilder buffer = new StringBuilder();
+        if (parent != null) {
+            buffer.append(parent.asPath());
         }
-        return pointer;
-    }
 
-    /**
-     * Gets the immediate parent pointer.
-     * @return NodePointer
-     */
-    public NodePointer getImmediateParentPointer() {
-        return parent;
-    }
+        if (buffer.length() == 0
+            || buffer.charAt(buffer.length() - 1) != '/') {
+            buffer.append('/');
+        }
+        if (attribute) {
+            buffer.append('@');
+        }
+        buffer.append(getName());
 
-    /**
-     * Sets to true if the pointer represents the "attribute::" axis.
-     * @param attribute boolean
-     */
-    public void setAttribute(final boolean attribute) {
-        this.attribute = attribute;
+        if (index != WHOLE_COLLECTION && isCollection()) {
+            buffer.append('[').append(index + 1).append(']');
+        }
+        return buffer.toString();
     }
 
     /**
-     * Returns true if the pointer represents the "attribute::" axis.
-     * @return boolean
+     * Returns a NodeIterator that iterates over all attributes of the current
+     * node matching the supplied node name (could have a wildcard).
+     * May return null if the object does not support the attributes.
+     * @param qname the attribute name to test
+     * @return NodeIterator
      */
-    public boolean isAttribute() {
-        return attribute;
+    public NodeIterator attributeIterator(final QName qname) {
+        final NodePointer valuePointer = getValuePointer();
+        return valuePointer == null || valuePointer == this ? null
+                : valuePointer.attributeIterator(qname);
     }
 
     /**
-     * Returns true if this Pointer has no parent.
-     * @return boolean
+     * Returns a NodeIterator that iterates over all children or all children
+     * that match the given NodeTest, starting with the specified one.
+     * @param test NodeTest to filter children
+     * @param reverse specified iteration direction
+     * @param startWith the NodePointer to start with
+     * @return NodeIterator
      */
-    public boolean isRoot() {
-        return parent == null;
+    public NodeIterator childIterator(
+        final NodeTest test,
+        final boolean reverse,
+        final NodePointer startWith) {
+        final NodePointer valuePointer = getValuePointer();
+        return valuePointer == null || valuePointer == this ? null
+                : valuePointer.childIterator(test, reverse, startWith);
     }
 
     /**
-     * If true, this node does not have children
-     * @return boolean
-     */
-    public abstract boolean isLeaf();
-
-    /**
-     * Learn whether this pointer is considered to be a node.
-     * @return boolean
-     * @deprecated Please use !isContainer()
+     * Clone this NodePointer.
+     * @return cloned NodePointer
      */
-    @Deprecated
-    public boolean isNode() {
-        return !isContainer();
+    @Override
+    public Object clone() {
+        try {
+            final NodePointer ptr = (NodePointer) super.clone();
+            if (parent != null) {
+                ptr.parent = (NodePointer) parent.clone();
+            }
+            return ptr;
+        }
+        catch (final CloneNotSupportedException ex) {
+            // Of course it is supported
+            ex.printStackTrace();
+        }
+        return null;
     }
 
     /**
-     * If true, this node is auxiliary and can only be used as an intermediate in
-     * the chain of pointers.
-     * @return boolean
+     * Compares two child NodePointers and returns a positive number,
+     * zero or a positive number according to the order of the pointers.
+     * @param pointer1 first pointer to be compared
+     * @param pointer2 second pointer to be compared
+     * @return int per Java comparison conventions
      */
-    public boolean isContainer() {
-        return false;
-    }
+    public abstract int compareChildNodePointers(
+            NodePointer pointer1, NodePointer pointer2);
 
     /**
-     * If the pointer represents a collection, the index identifies
-     * an element of that collection.  The default value of {@code index}
-     * is {@code WHOLE_COLLECTION}, which just means that the pointer
-     * is not indexed at all.
-     * Note: the index on NodePointer starts with 0, not 1.
-     * @return int
+     * Compare node pointers.
+     * @param p1 pointer 1
+     * @param depth1 depth 1
+     * @param p2 pointer 2
+     * @param depth2 depth 2
+     * @return comparison result: (< 0) -> (p1 lt p2); (0) -> (p1 eq p2); (> 0) -> (p1 gt p2)
      */
-    public int getIndex() {
-        return index;
+    private int compareNodePointers(
+        final NodePointer p1,
+        final int depth1,
+        final NodePointer p2,
+        final int depth2) {
+        if (depth1 < depth2) {
+            final int r = compareNodePointers(p1, depth1, p2.parent, depth2 - 1);
+            return r == 0 ? -1 : r;
+        }
+        if (depth1 > depth2) {
+            final int r = compareNodePointers(p1.parent, depth1 - 1, p2, depth2);
+            return r == 0 ? 1 : r;
+        }
+        //henceforth depth1 == depth2:
+        if (safeEquals(p1, p2)) {
+            return 0;
+        }
+        if (depth1 == 1) {
+            throw new JXPathException(
+                    "Cannot compare pointers that do not belong to the same tree: '"
+                    + p1 + "' and '" + p2 + "'");
+        }
+        final int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1);
+        return r == 0 ? p1.parent.compareChildNodePointers(p1, p2) : r;
     }
 
-    /**
-     * Sets the index of this NodePointer.
-     * @param index int
-     */
-    public void setIndex(final int index) {
-        this.index = index;
+    @Override
+    public int compareTo(final Object object) {
+        if (object == this) {
+            return 0;
+        }
+        // Let it throw a ClassCastException
+        final NodePointer pointer = (NodePointer) object;
+        if (safeEquals(parent, pointer.parent)) {
+            return parent == null ? 0 : parent.compareChildNodePointers(this, pointer);
+        }
+
+        // Task 1: find the common parent
+        int depth1 = 0;
+        NodePointer p1 = this;
+        final HashSet parents1 = new HashSet();
+        while (p1 != null) {
+            depth1++;
+            p1 = p1.parent;
+            if (p1 != null) {
+                parents1.add(p1);
+            }
+        }
+        boolean commonParentFound = false;
+        int depth2 = 0;
+        NodePointer p2 = pointer;
+        while (p2 != null) {
+            depth2++;
+            p2 = p2.parent;
+            if (parents1.contains(p2)) {
+                commonParentFound = true;
+            }
+        }
+        //nodes from different graphs are equal, else continue comparison:
+        return commonParentFound ? compareNodePointers(this, depth1, pointer, depth2) : 0;
     }
 
     /**
-     * Returns {@code true} if the value of the pointer is an array or
-     * a Collection.
-     * @return boolean
+     * Called to create a non-existing attribute
+     * @param context the owning JXPathCOntext
+     * @param name the QName at which an attribute should be created
+     * @return created NodePointer
      */
-    public abstract boolean isCollection();
+    public NodePointer createAttribute(final JXPathContext context, final QName name) {
+        throw new JXPathException("Cannot create an attribute for path "
+                + asPath() + "/@" + name
+                + ", operation is not allowed for this type of node");
+    }
 
     /**
-     * If the pointer represents a collection (or collection element),
-     * returns the length of the collection.
-     * Otherwise returns 1 (even if the value is null).
-     * @return int
+     * Called by a child pointer when it needs to create a parent object for a
+     * non-existent collection element. It may have to expand the collection,
+     * then create an element object and return a new pointer describing the
+     * newly created element.
+     * @param context the owning JXPathCOntext
+     * @param name the QName at which a child should be created
+     * @param index child index.
+     * @return created NodePointer
      */
-    public abstract int getLength();
+    public NodePointer createChild(final JXPathContext context, final QName name, final int index) {
+        throw new JXPathException("Cannot create an object for path "
+                + asPath() + "/" + name + "[" + (index + 1) + "]"
+                + ", operation is not allowed for this type of node");
+    }
 
     /**
-     * By default, returns {@code getNode()}, can be overridden to
-     * return a "canonical" value, like for instance a DOM element should
-     * return its string value.
-     * @return Object value
+     * Called by a child pointer if that child needs to assign the value
+     * supplied in the createPath(context, value) call to a non-existent
+     * node. This method may have to expand the collection in order to assign
+     * the element.
+     * @param context the owning JXPathCOntext
+     * @param name the QName at which a child should be created
+     * @param index child index.
+     * @param value node value to set
+     * @return created NodePointer
      */
-    @Override
-    public Object getValue() {
-        final NodePointer valuePointer = getValuePointer();
-        if (valuePointer != this) {
-            return valuePointer.getValue();
-        }
-        // Default behavior is to return the same as getNode()
-        return getNode();
+    public NodePointer createChild(
+        final JXPathContext context,
+        final QName name,
+        final int index,
+        final Object value) {
+        throw new JXPathException("Cannot create an object for path "
+                + asPath() + "/" + name + "[" + (index + 1) + "]"
+                + ", operation is not allowed for this type of node");
     }
 
     /**
-     * If this pointer manages a transparent container, like a variable,
-     * this method returns the pointer to the contents.
-     * Only an auxiliary (non-node) pointer can (and should) return a
-     * value pointer other than itself.
-     * Note that you probably don't want to override
-     * {@code getValuePointer()} directly.  Override the
-     * {@code getImmediateValuePointer()} method instead.  The
-     * {@code getValuePointer()} method is calls
-     * {@code getImmediateValuePointer()} and, if the result is not
-     * {@code this}, invokes {@code getValuePointer()} recursively.
-     * The idea here is to open all nested containers. Let's say we have a
-     * container within a container within a container. The
-     * {@code getValuePointer()} method should then open all those
-     * containers and return the pointer to the ultimate contents. It does so
-     * with the above recursion.
-     * @return NodePointer
+     * Called by a child pointer when it needs to create a parent object.
+     * Must create an object described by this pointer and return
+     * a new pointer that properly describes the new object.
+     * @param context the owning JXPathContext
+     * @return created NodePointer
      */
-    public NodePointer getValuePointer() {
-        final NodePointer ivp = getImmediateValuePointer();
-        return ivp == this ? this : ivp.getValuePointer();
+    public NodePointer createPath(final JXPathContext context) {
+        return this;
     }
 
     /**
-     * @see #getValuePointer()
-     * @return NodePointer is either {@code this} or a pointer
-     *   for the immediately contained value.
+     *  Called directly by JXPathContext. Must create path and
... 29910 lines suppressed ...


(commons-jxpath) 15/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 459a318abd9a0915b3bb2e61c991d36112a95093
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:29:47 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/ri/model/VariablePointer.java  | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/VariablePointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
index c9a97ef..964f8af 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
@@ -251,11 +251,7 @@ public class VariablePointer extends NodePointer {
     public NodePointer getImmediateValuePointer() {
         if (valuePointer == null) {
             Object value;
-            if (actual) {
-                value = getImmediateNode();
-                valuePointer = newChildNodePointer(this, null, value);
-            }
-            else {
+            if (!actual) {
                 return new NullPointer(this, getName()) {
                     private static final long serialVersionUID = 1L;
 
@@ -266,6 +262,8 @@ public class VariablePointer extends NodePointer {
                     }
                 };
             }
+            value = getImmediateNode();
+            valuePointer = newChildNodePointer(this, null, value);
         }
         return valuePointer;
     }


(commons-jxpath) 09/18: Use final

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 452f5f454fe62d7dfb832bec1ea09a449c85508a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:26:53 2025 -0400

    Use final
---
 src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
index 849a197..1e995ba 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
@@ -65,7 +65,7 @@ public class JXPath113Test extends AbstractJXPathTest
         final Document doc = JAXP.getDocument("<xml/>");
         final JXPathContext context = JXPathContext.newContext(doc);
 
-        List result = context.selectNodes("//following-sibling::node()");
+        final List result = context.selectNodes("//following-sibling::node()");
         assertNotNull(result);
         assertTrue(result.isEmpty());
     }


(commons-jxpath) 16/18: Remove trailing whitespace

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 9c1b79d382c740affb5798b574157b8749146710
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:30:01 2025 -0400

    Remove trailing whitespace
---
 src/main/java/org/apache/commons/jxpath/ri/parser/XPathParser.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/parser/XPathParser.java b/src/main/java/org/apache/commons/jxpath/ri/parser/XPathParser.java
index 76d0818..d2d657e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/parser/XPathParser.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/parser/XPathParser.java
@@ -31,7 +31,7 @@ import org.apache.commons.jxpath.ri.Compiler;
           }
 
         static private final class LookaheadSuccess extends Error {
-        
+
             /**
              *
              */


(commons-jxpath) 06/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 7c01db1583bd19a7db99a0480218ac5d591c87af
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:26:21 2025 -0400

    No need to nest else
---
 .../commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java  | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java
index 9390a81..064e67f 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/dynabeans/DynaBeanPropertyPointer.java
@@ -62,12 +62,10 @@ public class DynaBeanPropertyPointer extends PropertyPointer {
         final DynaProperty property = dynaClass.getDynaProperty(getPropertyName());
         Class type = property.getType();
         if (element) {
-            if (type.isArray()) {
-                type = type.getComponentType();
-            }
-            else {
+            if (!type.isArray()) {
                 return value; // No need to convert
             }
+            type = type.getComponentType();
         }
 
         try {


(commons-jxpath) 04/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit be4c125066361e65ecd3a404b25f9cfe5920879d
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:25:47 2025 -0400

    No need to nest else
---
 src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
index 75c9cf0..22e5e49 100644
--- a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
+++ b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
@@ -60,7 +60,7 @@ public class ClassLoaderUtilTest {
       if ( EXAMPLE_CLASS_NAME.equals(name) ) {
         throw new ClassNotFoundException();
       }
-      else if ( TEST_CASE_CLASS_NAME.equals(name) ) {
+      if ( TEST_CASE_CLASS_NAME.equals(name) ) {
         if ( testCaseClass == null ) {
           final URL clazzUrl = getParent().getResource("org/apache/commons/jxpath/util/ClassLoaderUtilTest.class");
 


(commons-jxpath) 02/18: Sort imports

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit fcb63039d7dbe0819b63421490fbaa98556b4529
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:23:36 2025 -0400

    Sort imports
---
 .../org/apache/commons/jxpath/AbstractJXPathTest.java   |  6 +++---
 .../org/apache/commons/jxpath/BasicNodeSetTest.java     |  4 ++--
 .../org/apache/commons/jxpath/issues/JXPath113Test.java |  8 ++++----
 .../org/apache/commons/jxpath/issues/JXPath118Test.java |  5 ++---
 .../org/apache/commons/jxpath/issues/JXPath149Test.java |  2 +-
 .../commons/jxpath/issues/JXPath172DynamicTest.java     | 11 +++++------
 .../org/apache/commons/jxpath/issues/JXPath172Test.java | 13 ++++++-------
 .../org/apache/commons/jxpath/issues/JXPath177Test.java |  7 +++----
 .../apache/commons/jxpath/ri/ExceptionHandlerTest.java  |  8 ++++----
 .../commons/jxpath/ri/JXPathCompiledExpressionTest.java |  6 +++---
 .../jxpath/ri/JXPathContextReferenceImplTestCase.java   |  1 -
 .../java/org/apache/commons/jxpath/ri/StressTest.java   |  7 +++----
 .../commons/jxpath/ri/axes/RecursiveAxesTest.java       |  2 +-
 .../jxpath/ri/axes/SimplePathInterpreterTest.java       |  9 ++++-----
 .../jxpath/ri/compiler/ContextDependencyTest.java       |  4 ++--
 .../commons/jxpath/ri/compiler/CoreFunctionTest.java    |  2 +-
 .../commons/jxpath/ri/compiler/CoreOperationTest.java   |  2 +-
 .../jxpath/ri/compiler/ExtensionFunctionTest.java       |  8 ++++----
 .../apache/commons/jxpath/ri/compiler/VariableTest.java | 10 +++++-----
 .../commons/jxpath/ri/model/AbstractBeanModelTest.java  | 10 +++++-----
 .../commons/jxpath/ri/model/AbstractXMLModelTest.java   | 10 +++++-----
 .../jxpath/ri/model/AliasedNamespaceIterationTest.java  |  2 +-
 .../jxpath/ri/model/EmbeddedColonMapKeysTest.java       |  2 +-
 .../commons/jxpath/ri/model/EmptyCollectionTest.java    |  2 +-
 .../jxpath/ri/model/ExternalXMLNamespaceTest.java       |  2 +-
 .../apache/commons/jxpath/ri/model/JXPath151Test.java   |  2 +-
 .../apache/commons/jxpath/ri/model/JXPath154Test.java   |  6 +++---
 .../apache/commons/jxpath/ri/model/MixedModelTest.java  |  8 ++++----
 .../commons/jxpath/ri/model/XMLPreserveSpaceTest.java   |  6 +++---
 .../apache/commons/jxpath/ri/model/XMLSpaceTest.java    |  6 +++---
 .../jxpath/ri/model/XMLUpperCaseElementsTest.java       |  6 +++---
 .../ri/model/beans/BadlyImplementedFactoryTest.java     |  7 +++----
 .../jxpath/ri/model/container/ContainerModelTest.java   |  6 +++---
 .../commons/jxpath/ri/model/dom/DOMModelTest.java       |  4 ++--
 .../jxpath/ri/model/dynabeans/LazyDynaBeanTest.java     |  6 +++---
 .../ri/model/dynamic/DynamicPropertiesModelTest.java    |  8 ++++----
 .../commons/jxpath/ri/model/jdom/JDOMModelTest.java     |  4 ++--
 .../jxpath/servlet/JXPathServletContextTest.java        | 17 ++++++++---------
 .../commons/jxpath/util/BasicTypeConverterTest.java     |  9 ++++-----
 .../apache/commons/jxpath/util/ClassLoaderUtilTest.java |  9 ++++-----
 .../org/apache/commons/jxpath/util/ValueUtilsTest.java  |  6 +++---
 41 files changed, 121 insertions(+), 132 deletions(-)

diff --git a/src/test/java/org/apache/commons/jxpath/AbstractJXPathTest.java b/src/test/java/org/apache/commons/jxpath/AbstractJXPathTest.java
index 1725896..dc33742 100644
--- a/src/test/java/org/apache/commons/jxpath/AbstractJXPathTest.java
+++ b/src/test/java/org/apache/commons/jxpath/AbstractJXPathTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jxpath;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -28,9 +31,6 @@ import java.util.Set;
 import org.apache.commons.jxpath.ri.model.NodePointer;
 import org.junit.jupiter.api.BeforeEach;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 /**
  * Abstract superclass for various JXPath tests.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/BasicNodeSetTest.java b/src/test/java/org/apache/commons/jxpath/BasicNodeSetTest.java
index 14565ba..50a6d93 100644
--- a/src/test/java/org/apache/commons/jxpath/BasicNodeSetTest.java
+++ b/src/test/java/org/apache/commons/jxpath/BasicNodeSetTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.jxpath;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.util.Iterator;
 import java.util.List;
 
@@ -23,8 +25,6 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Element;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Test BasicNodeSet
  */
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
index 397fc4a..849a197 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath113Test.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jxpath.issues;
 
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.io.StringReader;
 import java.util.List;
 
@@ -23,15 +26,12 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 public class JXPath113Test extends AbstractJXPathTest
 {
 
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java
index fb75561..d7ac25a 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath118Test.java
@@ -16,15 +16,14 @@
  */
 package org.apache.commons.jxpath.issues;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.util.Iterator;
 
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
-
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Testcase proving JXPATH-118 issue with asPath() returning wrong names.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath149Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath149Test.java
index 35086e8..f6d3953 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath149Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath149Test.java
@@ -16,8 +16,8 @@
  */
 package org.apache.commons.jxpath.issues;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.Test;
 
 public class JXPath149Test extends AbstractJXPathTest {
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
index 95a6c82..3b47431 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath172DynamicTest.java
@@ -16,19 +16,18 @@
  */
 package org.apache.commons.jxpath.issues;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 import java.util.HashMap;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer;
-
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
 public class JXPath172DynamicTest extends AbstractJXPathTest
 {
 
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath172Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath172Test.java
index 66c3767..5e6e20d 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath172Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath172Test.java
@@ -16,20 +16,19 @@
  */
 package org.apache.commons.jxpath.issues;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathNotFoundException;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer;
 import org.apache.commons.jxpath.ri.model.beans.NullPropertyPointer;
-
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 public class JXPath172Test extends AbstractJXPathTest
 {
 
diff --git a/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java b/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java
index 419f722..236af32 100644
--- a/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java
+++ b/src/test/java/org/apache/commons/jxpath/issues/JXPath177Test.java
@@ -16,18 +16,17 @@
  */
 package org.apache.commons.jxpath.issues;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.Variables;
-
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
 public class JXPath177Test
 {
     private static final class JXPathVariablesResolver implements Variables
diff --git a/src/test/java/org/apache/commons/jxpath/ri/ExceptionHandlerTest.java b/src/test/java/org/apache/commons/jxpath/ri/ExceptionHandlerTest.java
index 792652c..21c4b35 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/ExceptionHandlerTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/ExceptionHandlerTest.java
@@ -16,14 +16,14 @@
  */
 package org.apache.commons.jxpath.ri;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
-
 /**
  * Test simple ExceptionHandler.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java b/src/test/java/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java
index 7289740..36b1a04 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/JXPathCompiledExpressionTest.java
@@ -16,8 +16,10 @@
  */
 package org.apache.commons.jxpath.ri;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.ri.compiler.Constant;
 import org.apache.commons.jxpath.ri.compiler.CoreFunction;
 import org.apache.commons.jxpath.ri.compiler.CoreOperationAdd;
@@ -42,8 +44,6 @@ import org.apache.commons.jxpath.ri.compiler.NameAttributeTest;
 import org.apache.commons.jxpath.ri.compiler.VariableReference;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Test compiler.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImplTestCase.java b/src/test/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImplTestCase.java
index f10bc72..48587b7 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImplTestCase.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImplTestCase.java
@@ -18,7 +18,6 @@
 package org.apache.commons.jxpath.ri;
 
 import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory;
-
 import org.junit.jupiter.api.Test;
 
 public class JXPathContextReferenceImplTestCase {
diff --git a/src/test/java/org/apache/commons/jxpath/ri/StressTest.java b/src/test/java/org/apache/commons/jxpath/ri/StressTest.java
index 003069e..f2f192e 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/StressTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/StressTest.java
@@ -16,13 +16,12 @@
  */
 package org.apache.commons.jxpath.ri;
 
-import org.apache.commons.jxpath.JXPathContext;
-
-import org.junit.jupiter.api.Test;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.fail;
 
+import org.apache.commons.jxpath.JXPathContext;
+import org.junit.jupiter.api.Test;
+
 /**
  * Test thread safety.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/axes/RecursiveAxesTest.java b/src/test/java/org/apache/commons/jxpath/ri/axes/RecursiveAxesTest.java
index 14c032d..041d09a 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/axes/RecursiveAxesTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/axes/RecursiveAxesTest.java
@@ -16,8 +16,8 @@
  */
 package org.apache.commons.jxpath.ri.axes;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java b/src/test/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java
index a21a04c..f1749d3 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreterTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.commons.jxpath.ri.axes;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
 import java.util.HashMap;
 
 import org.apache.commons.jxpath.JXPathContext;
@@ -34,14 +38,9 @@ import org.apache.commons.jxpath.ri.model.beans.TestBeanFactory;
 import org.apache.commons.jxpath.ri.model.dom.DOMNodePointer;
 import org.apache.commons.jxpath.ri.model.dynamic.DynamicPointer;
 import org.apache.commons.jxpath.ri.model.dynamic.DynamicPropertyPointer;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
 public class SimplePathInterpreterTest  {
 
     private TestBeanWithNode bean;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/ContextDependencyTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/ContextDependencyTest.java
index daad916..347a7d3 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/ContextDependencyTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/ContextDependencyTest.java
@@ -16,12 +16,12 @@
  */
 package org.apache.commons.jxpath.ri.compiler;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.ri.Parser;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Tests the determination of whether an expression is context dependent.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
index 0ea6c81..b1a43bf 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
@@ -20,9 +20,9 @@ import java.text.DecimalFormatSymbols;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.ExtendedKeyManager;
 import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.NodeSet;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.TestMixedModelBean;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreOperationTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreOperationTest.java
index bb5186f..3f69280 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreOperationTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/CoreOperationTest.java
@@ -16,8 +16,8 @@
  */
 package org.apache.commons.jxpath.ri.compiler;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Variables;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
index 36befa1..bc03739 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java
@@ -16,18 +16,21 @@
  */
 package org.apache.commons.jxpath.ri.compiler;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.ClassFunctions;
 import org.apache.commons.jxpath.ExpressionContext;
 import org.apache.commons.jxpath.Function;
 import org.apache.commons.jxpath.FunctionLibrary;
 import org.apache.commons.jxpath.Functions;
 import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.NodeSet;
 import org.apache.commons.jxpath.PackageFunctions;
 import org.apache.commons.jxpath.Pointer;
@@ -41,9 +44,6 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-
 /**
  * Test extension functions.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/compiler/VariableTest.java b/src/test/java/org/apache/commons/jxpath/ri/compiler/VariableTest.java
index 77666b6..89dd78e 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/compiler/VariableTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/compiler/VariableTest.java
@@ -16,17 +16,17 @@
  */
 package org.apache.commons.jxpath.ri.compiler;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.TestMixedModelBean;
 import org.apache.commons.jxpath.Variables;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  * Test basic functionality of JXPath - infoset types,
  * operations.
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/AbstractBeanModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/AbstractBeanModelTest.java
index 9e60737..15d0ffd 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/AbstractBeanModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/AbstractBeanModelTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -23,9 +27,9 @@ import java.util.List;
 import java.util.Locale;
 
 import org.apache.commons.jxpath.AbstractFactory;
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.ClassFunctions;
 import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.NestedTestBean;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.ri.QName;
@@ -37,10 +41,6 @@ import org.apache.commons.jxpath.ri.model.dynabeans.DynaBeanModelTest;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  * Abstract superclass for Bean access with JXPath.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/AbstractXMLModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/AbstractXMLModelTest.java
index 30b14ec..e9d4b14 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/AbstractXMLModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/AbstractXMLModelTest.java
@@ -16,20 +16,20 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import org.apache.commons.jxpath.AbstractFactory;
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathException;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.Variables;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  * Abstract superclass for pure XPath 1.0.  Subclasses
  * apply the same XPaths to contexts using different models:
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
index 1e1c529..0a513b4 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/AliasedNamespaceIterationTest.java
@@ -18,8 +18,8 @@ package org.apache.commons.jxpath.ri.model;
 
 import java.util.Collection;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/EmbeddedColonMapKeysTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/EmbeddedColonMapKeysTest.java
index b2601e8..e07cbfb 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/EmbeddedColonMapKeysTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/EmbeddedColonMapKeysTest.java
@@ -18,8 +18,8 @@ package org.apache.commons.jxpath.ri.model;
 
 import java.util.HashMap;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/EmptyCollectionTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/EmptyCollectionTest.java
index 6446ada..b7f749d 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/EmptyCollectionTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/EmptyCollectionTest.java
@@ -18,8 +18,8 @@ package org.apache.commons.jxpath.ri.model;
 
 import java.util.Collections;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.junit.jupiter.api.Test;
 
 /**
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
index 6bb186f..7237d56 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
@@ -16,8 +16,8 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/JXPath151Test.java b/src/test/java/org/apache/commons/jxpath/ri/model/JXPath151Test.java
index b452e25..45b017e 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/JXPath151Test.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/JXPath151Test.java
@@ -19,8 +19,8 @@ package org.apache.commons.jxpath.ri.model;
 import java.util.HashMap;
 import java.util.Locale;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.TestBean;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/JXPath154Test.java b/src/test/java/org/apache/commons/jxpath/ri/model/JXPath154Test.java
index c133e0d..460ceba 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/JXPath154Test.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/JXPath154Test.java
@@ -17,13 +17,13 @@
 
 package org.apache.commons.jxpath.ri.model;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 public class JXPath154Test extends AbstractJXPathTest {
 
     protected JXPathContext context;
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/MixedModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/MixedModelTest.java
index 3677185..2e0ca5d 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/MixedModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/MixedModelTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -25,8 +28,8 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Vector;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.TestBean;
 import org.apache.commons.jxpath.TestMixedModelBean;
@@ -35,9 +38,6 @@ import org.apache.commons.jxpath.Variables;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  * Tests JXPath with mixed model: beans, maps, DOM etc.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/XMLPreserveSpaceTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/XMLPreserveSpaceTest.java
index 60a2266..3d995a5 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/XMLPreserveSpaceTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/XMLPreserveSpaceTest.java
@@ -16,13 +16,13 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Test for text trimming from JXPATH-83.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
index 9f5a74b..0d26e8b 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/XMLSpaceTest.java
@@ -16,13 +16,13 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Test for text trimming from JXPATH-83.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
index 4bd4052..1f09ee3 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/XMLUpperCaseElementsTest.java
@@ -16,13 +16,13 @@
  */
 package org.apache.commons.jxpath.ri.model;
 
-import org.apache.commons.jxpath.JXPathContext;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.xml.DocumentContainer;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Test for uppercase element matching, etc. showing JXPATH-136 is not reproducible.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
index 6b7f726..2012778 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jxpath.ri.model.beans;
 
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -24,13 +27,9 @@ import org.apache.commons.jxpath.JXPathAbstractFactoryException;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathException;
 import org.apache.commons.jxpath.Pointer;
-
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  * Badly-implemented Factory test.  From JIRA JXPATH-68.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java
index 439272b..f041994 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/container/ContainerModelTest.java
@@ -16,18 +16,18 @@
  */
 package org.apache.commons.jxpath.ri.model.container;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.Container;
 import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
 /**
  * Tests JXPath with containers as root or value of a variable, property, etc.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java
index 500ab15..938eb4e 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.jxpath.ri.model.dom;
 
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
 import org.apache.commons.jxpath.AbstractFactory;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.ri.model.AbstractXMLModelTest;
@@ -27,8 +29,6 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-
 /**
  * Tests JXPath with DOM
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
index f3e1338..44e81a3 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
@@ -16,15 +16,15 @@
  */
 package org.apache.commons.jxpath.ri.model.dynabeans;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 import org.apache.commons.beanutils.LazyDynaBean;
+import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathNotFoundException;
-import org.apache.commons.jxpath.AbstractJXPathTest;
 import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
 /**
  */
 public class LazyDynaBeanTest extends AbstractJXPathTest {
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java
index f5dbf66..805e84b 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/dynamic/DynamicPropertiesModelTest.java
@@ -16,20 +16,20 @@
  */
 package org.apache.commons.jxpath.ri.model.dynamic;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.AbstractJXPathTest;
+import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.TestBean;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
 /**
  * TODO more iterator testing with maps
  */
diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java
index b5ab068..849d6b0 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/jdom/JDOMModelTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.jxpath.ri.model.jdom;
 
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
 import java.util.List;
 
 import org.apache.commons.jxpath.AbstractFactory;
@@ -30,8 +32,6 @@ import org.jdom.Text;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-
 /**
  * Tests JXPath with JDOM
  */
diff --git a/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java b/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
index 710a51f..ce9a0f7 100644
--- a/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
+++ b/src/test/java/org/apache/commons/jxpath/servlet/JXPathServletContextTest.java
@@ -17,6 +17,13 @@
 
 package org.apache.commons.jxpath.servlet;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.Iterator;
 
 import javax.servlet.ServletContext;
@@ -24,6 +31,7 @@ import javax.servlet.ServletContext;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.Variables;
+import org.junit.jupiter.api.Test;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
 import com.mockrunner.mock.web.MockHttpSession;
@@ -31,15 +39,6 @@ import com.mockrunner.mock.web.MockPageContext;
 import com.mockrunner.mock.web.MockServletConfig;
 import com.mockrunner.mock.web.MockServletContext;
 
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 /**
  */
 public class JXPathServletContextTest {
diff --git a/src/test/java/org/apache/commons/jxpath/util/BasicTypeConverterTest.java b/src/test/java/org/apache/commons/jxpath/util/BasicTypeConverterTest.java
index ac42883..9257700 100644
--- a/src/test/java/org/apache/commons/jxpath/util/BasicTypeConverterTest.java
+++ b/src/test/java/org/apache/commons/jxpath/util/BasicTypeConverterTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.commons.jxpath.util;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.lang.reflect.Array;
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -26,13 +30,8 @@ import java.util.List;
 
 import org.apache.commons.jxpath.NodeSet;
 import org.apache.commons.jxpath.Pointer;
-
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 /**
  * Tests BasicTypeConverter
  */
diff --git a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
index 323cdfb..75c9cf0 100644
--- a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
+++ b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.commons.jxpath.util;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -25,15 +29,10 @@ import java.net.URL;
 
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.JXPathException;
-
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
-
 /**
  * Tests org.apache.commons.jxpath.util.ClassLoaderUtil.
  */
diff --git a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java
index b2405c4..65827a7 100644
--- a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java
+++ b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jxpath.util;
 
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -23,9 +26,6 @@ import java.util.Set;
 
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
 public class ValueUtilsTest {
 
     @Test


(commons-jxpath) 03/18: Use final

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 44cadb53af65a725ca02b8044df13e71bb9138fb
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:24:54 2025 -0400

    Use final
---
 .../commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java b/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
index 2012778..45f752b 100644
--- a/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
+++ b/src/test/java/org/apache/commons/jxpath/ri/model/beans/BadlyImplementedFactoryTest.java
@@ -51,7 +51,7 @@ public class BadlyImplementedFactoryTest {
 
     @Test
     public void testBadFactoryImplementation() {
-        JXPathException e = assertThrows(JXPathException.class, () -> context.createPath("foo/bar"),
+        final JXPathException e = assertThrows(JXPathException.class, () -> context.createPath("foo/bar"),
             "should fail with JXPathException caused by JXPathAbstractFactoryException");
         assertInstanceOf(JXPathAbstractFactoryException.class, e.getCause());
     }


(commons-jxpath) 07/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit d4d218b6d068343a67c5ad0af28aa24b4d9aebe2
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:26:37 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java  | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java b/src/main/java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java
index 2104d75..5a55a13 100644
--- a/src/main/java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java
+++ b/src/main/java/org/apache/commons/jxpath/servlet/HttpSessionHandler.java
@@ -62,12 +62,10 @@ public class HttpSessionHandler extends ServletContextHandler {
         final HttpSessionAndServletContext handle =
             (HttpSessionAndServletContext) bean;
         final HttpSession session = handle.getSession();
-        if (session != null) {
-            session.setAttribute(property, value);
-        }
-        else {
+        if (session == null) {
             throw new JXPathException("Cannot set session attribute: "
                     + "there is no session");
         }
+        session.setAttribute(property, value);
     }
 }


(commons-jxpath) 10/18: Type casts are not needed

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit c71f011cc8839387e9080b4c0937ab2391fd413e
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:28:56 2025 -0400

    Type casts are not needed
---
 .../java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java b/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
index 1bfae39..551f92c 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
@@ -156,8 +156,8 @@ public class JXPathContextReferenceImpl extends JXPathContext {
                 (NodePointerFactory[]) nodeFactories.
                     toArray(new NodePointerFactory[nodeFactories.size()]);
             Arrays.sort(nodeFactoryArray, (a, b) -> {
-                final int orderA = ((NodePointerFactory) a).getOrder();
-                final int orderB = ((NodePointerFactory) b).getOrder();
+                final int orderA = a.getOrder();
+                final int orderB = b.getOrder();
                 return orderA - orderB;
             });
         }


(commons-jxpath) 17/18: Move less edited sections to the bottom

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 4757ea8dda9acad84fd0b7abd5e9137ef96b7a51
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:31:42 2025 -0400

    Move less edited sections to the bottom
---
 pom.xml | 85 ++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 42 insertions(+), 43 deletions(-)

diff --git a/pom.xml b/pom.xml
index a915d94..b746920 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,54 +35,11 @@
     <url>http://issues.apache.org/jira/browse/JXPATH</url>
   </issueManagement>
   <inceptionYear>2001</inceptionYear>
-  <developers>
-    <developer>
-      <id>dmitri</id>
-      <name>Dmitri Plotnikov</name>
-      <email>dmitri@apache.org</email>
-      <organization />
-    </developer>
-    <developer>
-      <id>craigmcc</id>
-      <name>Craig McClanahan</name>
-      <email>Craig.McClanahan@eng.sun.com</email>
-      <organization>Sun Microsystems</organization>
-    </developer>
-    <developer>
-      <id>mbenson</id>
-      <name>Matt Benson</name>
-      <email>mbenson@apache.org</email>
-    </developer>
-    <developer>
-      <id>ggregory</id>
-      <name>Gary Gregory</name>
-      <email>ggregory at apache.org</email>
-      <url>https://www.garygregory.com</url>
-      <organization>The Apache Software Foundation</organization>
-      <organizationUrl>https://www.apache.org/</organizationUrl>
-      <roles>
-        <role>PMC Member</role>
-      </roles>
-      <timezone>America/New_York</timezone>
-      <properties>
-        <picUrl>https://people.apache.org/~ggregory/img/garydgregory80.png</picUrl>
-      </properties>
-    </developer>
-  </developers>
-  <contributors>
-    <contributor>
-      <name>Michele Vivoda</name>
-    </contributor>
-    <contributor>
-      <name>Uwe Barthel</name>
-    </contributor>
-  </contributors>
   <scm>
     <connection>scm:git:https://gitbox.apache.org/repos/asf/commons-jxpath</connection>
     <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-jxpath</developerConnection>
     <url>https://gitbox.apache.org/repos/asf/commons-jxpath</url>
   </scm>
-
   <properties>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
@@ -338,4 +295,46 @@
     <system>GitHub</system>
     <url>https://github.com/apache/commons-jaxpth/actions</url>
   </ciManagement>
+  <developers>
+    <developer>
+      <id>dmitri</id>
+      <name>Dmitri Plotnikov</name>
+      <email>dmitri@apache.org</email>
+      <organization />
+    </developer>
+    <developer>
+      <id>craigmcc</id>
+      <name>Craig McClanahan</name>
+      <email>Craig.McClanahan@eng.sun.com</email>
+      <organization>Sun Microsystems</organization>
+    </developer>
+    <developer>
+      <id>mbenson</id>
+      <name>Matt Benson</name>
+      <email>mbenson@apache.org</email>
+    </developer>
+    <developer>
+      <id>ggregory</id>
+      <name>Gary Gregory</name>
+      <email>ggregory at apache.org</email>
+      <url>https://www.garygregory.com</url>
+      <organization>The Apache Software Foundation</organization>
+      <organizationUrl>https://www.apache.org/</organizationUrl>
+      <roles>
+        <role>PMC Member</role>
+      </roles>
+      <timezone>America/New_York</timezone>
+      <properties>
+        <picUrl>https://people.apache.org/~ggregory/img/garydgregory80.png</picUrl>
+      </properties>
+    </developer>
+  </developers>
+  <contributors>
+    <contributor>
+      <name>Michele Vivoda</name>
+    </contributor>
+    <contributor>
+      <name>Uwe Barthel</name>
+    </contributor>
+  </contributors>
 </project>


(commons-jxpath) 11/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 447adc669b760fb01c0fbbc5a5d67aa490a0a935
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:29:04 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java  | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java b/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
index cde04bc..740fd95 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/NamespaceContext.java
@@ -60,16 +60,14 @@ public class NamespaceContext extends EvalContext {
             if (testName.getPrefix() != null) {
                 return false;
             }
-            if (nodeNameTest.isWildcard()) {
-                iterator =
-                    parentContext.getCurrentNodePointer().namespaceIterator();
-            }
-            else {
+            if (!nodeNameTest.isWildcard()) {
                 currentNodePointer =
                     parentContext.getCurrentNodePointer().namespacePointer(
                             testName.getName());
                 return currentNodePointer != null;
             }
+            iterator =
+                parentContext.getCurrentNodePointer().namespaceIterator();
         }
 
         if (iterator == null) {


(commons-jxpath) 13/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 21fb8dfc510ad250bbdeee1212c0f36668243a4c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:29:30 2025 -0400

    No need to nest else
---
 .../ri/model/beans/PropertyOwnerPointer.java       | 32 +++++++++-------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
index 860ea50..dfd464a 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/beans/PropertyOwnerPointer.java
@@ -144,14 +144,12 @@ public abstract class PropertyOwnerPointer extends NodePointer {
     @Override
     public void remove() {
         this.value = null;
-        if (parent != null) {
-            parent.remove();
-        }
-        else {
+        if (parent == null) {
             throw new UnsupportedOperationException(
                 "Cannot remove an object that is not "
                     + "some other object's property or a collection element");
         }
+        parent.remove();
     }
 
     @Override
@@ -170,23 +168,19 @@ public abstract class PropertyOwnerPointer extends NodePointer {
     @Override
     public void setValue(final Object value) {
         this.value = value;
-        if (parent != null) {
-            if (parent.isContainer()) {
-                parent.setValue(value);
-            }
-            else {
-                if (index == WHOLE_COLLECTION) {
-                    throw new UnsupportedOperationException(
-                        "Cannot setValue of an object that is not "
-                            + "some other object's property");
-                }
-                throw new JXPathInvalidAccessException(
-                    "The specified collection element does not exist: " + this);
-            }
-        }
-        else {
+        if (parent == null) {
             throw new UnsupportedOperationException(
                 "Cannot replace the root object");
         }
+        if (!parent.isContainer()) {
+            if (index == WHOLE_COLLECTION) {
+                throw new UnsupportedOperationException(
+                    "Cannot setValue of an object that is not "
+                        + "some other object's property");
+            }
+            throw new JXPathInvalidAccessException(
+                "The specified collection element does not exist: " + this);
+        }
+        parent.setValue(value);
     }
 }


(commons-jxpath) 12/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit 8dea6ed77b95436b67acafa4ee1ad1355fd68fb5
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:29:16 2025 -0400

    No need to nest else
---
 .../jxpath/ri/model/beans/NullPropertyPointer.java    | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java b/src/main/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
index ce4c1fa..f7d5e64 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
@@ -216,21 +216,18 @@ public class NullPropertyPointer extends PropertyPointer {
                     + 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
-            final PropertyPointer propertyPointer =
-                ((PropertyOwnerPointer) parent).getPropertyPointer();
-            propertyPointer.setPropertyName(propertyName);
-            propertyPointer.setValue(value);
-        }
-        else {
+        if (!(parent instanceof PropertyOwnerPointer) || !((PropertyOwnerPointer) parent)
+                .isDynamicPropertyDeclarationSupported()) {
             throw new JXPathInvalidAccessException(
                 "Cannot set property "
                     + asPath()
                     + ", path does not match a changeable location");
         }
+        // If the parent property owner can create
+        // a property automatically - let it do so
+        final PropertyPointer propertyPointer =
+            ((PropertyOwnerPointer) parent).getPropertyPointer();
+        propertyPointer.setPropertyName(propertyName);
+        propertyPointer.setValue(value);
     }
 }


(commons-jxpath) 05/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit c0240aa872f063c7175f892e77b8f13420a9b649
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:26:11 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java    | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
index c36a991..815bf6e 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
@@ -390,12 +390,10 @@ public class CoreFunction extends Operation {
         EvalContext ec = null;
         if (value instanceof EvalContext) {
             ec = (EvalContext) value;
-            if (ec.hasNext()) {
-                value = ((NodePointer) ec.next()).getValue();
-            }
-            else { // empty context -> empty results
+            if (!ec.hasNext()) { // empty context -> empty results
                 return new NodeSetContext(context, new BasicNodeSet());
             }
+            value = ((NodePointer) ec.next()).getValue();
         }
         final JXPathContext jxpathContext = context.getJXPathContext();
         NodeSet nodeSet = jxpathContext.getNodeSetByKey(key, value);


(commons-jxpath) 14/18: No need to nest else

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit c57b62718d75b13f15a22d952aa07bb60fb634e8
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 16 13:29:39 2025 -0400

    No need to nest else
---
 .../java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java b/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
index 285a481..3f07a38 100644
--- a/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
+++ b/src/main/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
@@ -557,7 +557,7 @@ public class SimplePathInterpreter {
                 if (quality == PERFECT_MATCH) {
                     return pointer;
                 }
-                else if (quality > bestQuality) {
+                if (quality > bestQuality) {
                     bestQuality = quality;
                     bestMatch = (NodePointer) pointer.clone();
                 }