Author: mbenson
Date: Wed Jul 18 13:22:16 2007
New Revision: 557381
URL: http://svn.apache.org/viewvc?view=rev&rev=557381
Log:
[JXPATH-96] use NodePointerFactory for VariablePointers
Added:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
(with props)
Modified:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
Modified:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java?view=diff&rev=557381&r1=557380&r2=557381
==============================================================================
---
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
(original)
+++
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
Wed Jul 18 13:22:16 2007
@@ -37,7 +37,6 @@
import org.apache.commons.jxpath.JXPathNotFoundException;
import org.apache.commons.jxpath.JXPathTypeConversionException;
import org.apache.commons.jxpath.Pointer;
-import org.apache.commons.jxpath.Variables;
import org.apache.commons.jxpath.ri.axes.InitialContext;
import org.apache.commons.jxpath.ri.axes.RootContext;
import org.apache.commons.jxpath.ri.compiler.Expression;
@@ -46,7 +45,7 @@
import org.apache.commons.jxpath.ri.compiler.TreeCompiler;
import org.apache.commons.jxpath.ri.model.NodePointer;
import org.apache.commons.jxpath.ri.model.NodePointerFactory;
-import org.apache.commons.jxpath.ri.model.VariablePointer;
+import org.apache.commons.jxpath.ri.model.VariablePointerFactory;
import org.apache.commons.jxpath.ri.model.beans.BeanPointerFactory;
import org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory;
import org.apache.commons.jxpath.ri.model.container.ContainerPointerFactory;
@@ -72,12 +71,13 @@
private static Map compiled = new HashMap();
private static int cleanupCount = 0;
- private static Vector nodeFactories = new Vector();
+ private static final Vector nodeFactories = new Vector();
private static NodePointerFactory nodeFactoryArray[] = null;
static {
nodeFactories.add(new CollectionPointerFactory());
nodeFactories.add(new BeanPointerFactory());
nodeFactories.add(new DynamicPointerFactory());
+ nodeFactories.add(new VariablePointerFactory());
// DOM factory is only registered if DOM support is on the classpath
Object domFactory = allocateConditionally(
@@ -618,26 +618,8 @@
}
public NodePointer getVariablePointer(QName name) {
- String varName = name.toString();
- JXPathContext varCtx = this;
- Variables vars = null;
- while (varCtx != null) {
- vars = varCtx.getVariables();
- if (vars.isDeclaredVariable(varName)) {
- break;
- }
- varCtx = varCtx.getParentContext();
- vars = null;
- }
- if (vars != null) {
- return new VariablePointer(vars, name);
- }
- else {
- // The variable is not declared, but we will create
- // a pointer anyway in case the user want to set, rather
- // than get, the value of the variable.
- return new VariablePointer(name);
- }
+ return NodePointer.newNodePointer(name, VariablePointerFactory
+ .contextWrapper(this), getLocale());
}
public Function getFunction(QName functionName, Object[] parameters) {
Added:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java?view=auto&rev=557381
==============================================================================
---
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
(added)
+++
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
Wed Jul 18 13:22:16 2007
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jxpath.ri.model;
+
+import java.util.Locale;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.Variables;
+import org.apache.commons.jxpath.ri.QName;
+
+/**
+ * NodePointerFactory to create VariablePointers.
+ * @author Matt Benson
+ * @since JXPath 1.3
+ * @version $Revision$ $Date$
+ */
+public class VariablePointerFactory implements NodePointerFactory {
+ public static final int VARIABLE_POINTER_FACTORY_ORDER = 890;
+
+ /**
+ * Node value wrapper to trigger a VariablePointerFactory.
+ */
+ public static class VariableContextWrapper {
+ final JXPathContext context;
+
+ private VariableContextWrapper(JXPathContext context) {
+ this.context = context;
+ }
+ }
+
+ /**
+ * VariableContextWrapper factory method.
+ * @param context the JXPathContext to wrap.
+ * @return VariableContextWrapper.
+ */
+ public static VariableContextWrapper contextWrapper(JXPathContext context)
{
+ return new VariableContextWrapper(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.commons.jxpath.ri.model.NodePointerFactory#createNodePointer(org.apache.commons.jxpath.ri.QName,
+ * java.lang.Object, java.util.Locale)
+ */
+ public NodePointer createNodePointer(QName name, Object object,
+ Locale locale) {
+ if (object instanceof VariableContextWrapper) {
+ JXPathContext varCtx = ((VariableContextWrapper) object).context;
+ while (varCtx != null) {
+ Variables vars = varCtx.getVariables();
+ if (vars.isDeclaredVariable(name.toString())) {
+ return new VariablePointer(vars, name);
+ }
+ varCtx = varCtx.getParentContext();
+ }
+ // The variable is not declared, but we will create
+ // a pointer anyway in case the user wants to set, rather
+ // than get, the value of the variable.
+ return new VariablePointer(name);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.commons.jxpath.ri.model.NodePointerFactory#createNodePointer(org.apache.commons.jxpath.ri.model.NodePointer,
+ * org.apache.commons.jxpath.ri.QName, java.lang.Object)
+ */
+ public NodePointer createNodePointer(NodePointer parent, QName name,
+ Object object) {
+ return createNodePointer(name, object, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.commons.jxpath.ri.model.NodePointerFactory#getOrder()
+ */
+ public int getOrder() {
+ return VARIABLE_POINTER_FACTORY_ORDER;
+ }
+
+}
Propchange:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/VariablePointerFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]