You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2006/02/21 21:08:22 UTC

svn commit: r379568 - in /cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding: JXPathBindingBase.java JXPathBindingBuilderBase.java

Author: bruno
Date: Tue Feb 21 12:08:20 2006
New Revision: 379568

URL: http://svn.apache.org/viewcvs?rev=379568&view=rev
Log:
Thought I committed this two weeks ago, must not have paid enough attention :-/

CForms: binding: implemented support for a new attribute "jxpath-factory"
(can be used on any binding element) to change the factory used by JXPath
when it needs to create new paths (currently this is fixed to the
DOMFactory). This is useful when using non-DOM, non-bean data models.

Modified:
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java
    cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java?rev=379568&r1=379567&r2=379568&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java (original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java Tue Feb 21 12:08:20 2006
@@ -26,6 +26,7 @@
 import org.apache.cocoon.util.jxpath.DOMFactory;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
+import org.apache.commons.jxpath.AbstractFactory;
 import org.apache.commons.jxpath.ri.model.beans.BeanPropertyPointer;
 import org.apache.commons.jxpath.util.TypeUtils;
 import org.apache.commons.lang.exception.NestableRuntimeException;
@@ -293,7 +294,13 @@
         if (!(objModel instanceof JXPathContext)) {
             jxpc = JXPathContext.newContext(objModel);
             jxpc.setLenient(true);
-            jxpc.setFactory(new BindingJXPathFactory());
+
+            AbstractFactory jxPathFactory;
+            if (commonAtts.jxPathFactory != null)
+                jxPathFactory = commonAtts.jxPathFactory;
+            else
+                jxPathFactory = new BindingJXPathFactory();
+            jxpc.setFactory(jxPathFactory);
         } else {
             jxpc = (JXPathContext) objModel;
         }

Modified: cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java?rev=379568&r1=379567&r2=379568&view=diff
==============================================================================
--- cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java (original)
+++ cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java Tue Feb 21 12:08:20 2006
@@ -21,6 +21,7 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.cocoon.forms.util.DomHelper;
 import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.jxpath.AbstractFactory;
 import org.w3c.dom.Element;
 
 /**
@@ -128,8 +129,19 @@
             if (nsDeclarationMap != null && nsDeclarationMap.values().contains(null))
                 throw new BindingException("Error in binding file " + location
                                 + "\nBinding doesn't support having namespace-declarations without explicit prefixes.");
+
+            String jxPathFactoryName = bindingElm.getAttribute("jxpath-factory");
+            AbstractFactory jxPathFactory = null;
+            if (jxPathFactoryName != null && jxPathFactoryName.trim().length() > 0) {
+                try {
+                    Class jxPathFactoryClass = JXPathBindingBuilderBase.class.getClassLoader().loadClass(jxPathFactoryName);
+                    jxPathFactory = (AbstractFactory)jxPathFactoryClass.newInstance();
+                } catch (Exception e) {
+                    throw new BindingException("Error with specified jxpath factory " + jxPathFactoryName, e);
+                }
+            }
             
-            return new CommonAttributes(location, direction, leniency, nsDeclarationMap);
+            return new CommonAttributes(location, direction, leniency, nsDeclarationMap, jxPathFactory);
         } catch (BindingException e) {
             throw e;
         } catch (Exception e) {
@@ -155,9 +167,13 @@
     	String direction = existing.direction;
     	if(extra.direction!=null) // was defined
     		direction = extra.direction;
-    	
-    	
-    	return new CommonAttributes(extra.location,direction,strLeniency,extra.nsDeclarations);
+
+        AbstractFactory jxPathFactory = existing.jxPathFactory;
+        if (extra.jxPathFactory != null)
+            jxPathFactory = extra.jxPathFactory;
+
+
+        return new CommonAttributes(extra.location,direction,strLeniency,extra.nsDeclarations, jxPathFactory);
     }
 
      /**
@@ -192,21 +208,27 @@
          * Array of namespace-declarations (prefix-uri pairs) that need to be set on the jxpath 
          */
         final Map nsDeclarations;
+         /**
+          * The factory to be set on the JXPath Context object
+          */
+        final AbstractFactory jxPathFactory;
 
-        final static CommonAttributes DEFAULT = new CommonAttributes("location unknown", true, true, null, null);
+        final static CommonAttributes DEFAULT = new CommonAttributes("location unknown", true, true, null, null, null);
 
-        CommonAttributes(String location, String direction, String leniency, Map nsDeclarations){
-            this(location, isLoadEnabled(direction), isSaveEnabled(direction), decideLeniency(leniency), nsDeclarations);
+        CommonAttributes(String location, String direction, String leniency, Map nsDeclarations, AbstractFactory jxPathFactory){
+            this(location, isLoadEnabled(direction), isSaveEnabled(direction), decideLeniency(leniency), nsDeclarations, jxPathFactory);
             this.direction = direction;
         }
 
-        CommonAttributes(String location, boolean loadEnabled, boolean saveEnabled, Boolean leniency, Map nsDeclarations){
+        CommonAttributes(String location, boolean loadEnabled, boolean saveEnabled, Boolean leniency,
+                Map nsDeclarations, AbstractFactory jxPathFactory){
         	this.direction = null;
             this.location = location;
             this.loadEnabled = loadEnabled;
             this.saveEnabled = saveEnabled;
             this.leniency = leniency;
             this.nsDeclarations = nsDeclarations;
+            this.jxPathFactory = jxPathFactory;
         }
 
         /**
@@ -237,6 +259,6 @@
         private static Boolean decideLeniency(String leniency) {
             return BooleanUtils.toBooleanObject(leniency);
         }
-        
+
     }
 }



Re: svn commit: r379568 - in /cocoon/trunk/cocoon-forms/cocoon-forms-impl/src/main/java/org/apache/cocoon/forms/binding: JXPathBindingBase.java JXPathBindingBuilderBase.java

Posted by Joerg Heinicke <jo...@gmx.de>.
On 21.02.2006 21:08, bruno@apache.org wrote:
> Author: bruno
> Date: Tue Feb 21 12:08:20 2006
> New Revision: 379568
> 
> URL: http://svn.apache.org/viewcvs?rev=379568&view=rev
> Log:
> Thought I committed this two weeks ago, must not have paid enough attention :-/

Nobody paid enough attention to your commit: 
http://marc.theaimsgroup.com/?l=xml-cocoon-cvs&m=113956765013652&w=4
See the list of committed files ;)

Jörg