commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model XMLModelTestCase.java
Date Thu, 30 Dec 2004 21:59:36 GMT
dmitri      2004/12/30 13:59:36

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
                        DOMNodePointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri
                        NamespaceResolver.java
                        JXPathContextReferenceImpl.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        XMLModelTestCase.java
  Log:
  Made namespace mappings inherited by child contexts
  
  Revision  Changes    Path
  1.26      +5 -1      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
  
  Index: DOMNodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- DOMNodePointer.java	6 Oct 2004 00:34:14 -0000	1.25
  +++ DOMNodePointer.java	30 Dec 2004 21:59:36 -0000	1.26
  @@ -226,6 +226,10 @@
           }
   
           namespaces.put(prefix, namespace);
  +        if (namespace == UNKNOWN_NAMESPACE) {
  +            return null;
  +        }
  +        
           // TBD: We are supposed to resolve relative URIs to absolute ones.
           return namespace;
       }
  
  
  
  1.3       +18 -2     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/NamespaceResolver.java
  
  Index: NamespaceResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/NamespaceResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- NamespaceResolver.java	29 Jun 2004 22:57:20 -0000	1.2
  +++ NamespaceResolver.java	30 Dec 2004 21:59:36 -0000	1.3
  @@ -31,11 +31,15 @@
    * @version $Revision$ $Date$
    */
   public class NamespaceResolver implements Cloneable {
  -    
  +    final protected NamespaceResolver parent;
       protected HashMap namespaceMap = new HashMap();
       protected HashMap reverseMap;
       protected NodePointer pointer;
       private boolean sealed;
  +        
  +    public NamespaceResolver(NamespaceResolver parent) {
  +        this.parent = parent;
  +    }
       
       /**
        * Registers a namespace prefix.
  @@ -56,6 +60,9 @@
       }
       
       public Pointer getNamespaceContextPointer() {
  +        if (pointer == null && parent != null) {
  +            return parent.getNamespaceContextPointer();
  +        }
           return pointer;
       }
       
  @@ -74,6 +81,9 @@
           if (uri == null && pointer != null) {
               uri = pointer.getNamespaceURI(prefix);
           }
  +        if (uri == null && parent != null) {
  +            return parent.getNamespaceURI(prefix);
  +        }
   //        System.err.println("For prefix " + prefix + " URI=" + uri);
           return uri;
       }
  @@ -96,6 +106,9 @@
               }
           }
           String prefix = (String) reverseMap.get(namespaceURI);
  +        if (prefix == null && parent != null) {
  +            return parent.getPrefix(namespaceURI);
  +        }
           return prefix;
       }
       
  @@ -105,6 +118,9 @@
       
       public void seal() {
           sealed = true;
  +        if (parent != null) {
  +            parent.seal();
  +        }
       }
       
       public Object clone() {
  
  
  
  1.44      +6 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
  
  Index: JXPathContextReferenceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- JXPathContextReferenceImpl.java	4 Apr 2004 23:16:23 -0000	1.43
  +++ JXPathContextReferenceImpl.java	30 Dec 2004 21:59:36 -0000	1.44
  @@ -146,7 +146,11 @@
               this.rootPointer = this.contextPointer;
           }
           
  -        namespaceResolver = new NamespaceResolver();
  +        NamespaceResolver parentNR = null;
  +        if (parentContext instanceof JXPathContextReferenceImpl) {
  +            parentNR = ((JXPathContextReferenceImpl)parentContext).getNamespaceResolver();
  +        }
  +        namespaceResolver = new NamespaceResolver(parentNR);
           namespaceResolver
                   .setNamespaceContextPointer((NodePointer) this.contextPointer);
       }
  
  
  
  1.25      +17 -1     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
  
  Index: XMLModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- XMLModelTestCase.java	6 Oct 2004 00:34:14 -0000	1.24
  +++ XMLModelTestCase.java	30 Dec 2004 21:59:36 -0000	1.25
  @@ -800,5 +800,21 @@
                   "//product:name",
                   "Box of oranges",
                   "/vendor[1]/product[1]/goods:name[1]");
  +        
  +        // Same, but with a child context        
  +        JXPathContext childCtx = 
  +            JXPathContext.newContext(context, context.getContextBean());
  +        assertXPathValueAndPointer(childCtx,
  +                "//product:name",
  +                "Box of oranges",
  +                "/vendor[1]/product[1]/goods:name[1]");
  +        
  +        // Same, but with a relative context        
  +        JXPathContext relativeCtx = 
  +            context.getRelativeContext(context.getPointer("/vendor"));
  +        assertXPathValueAndPointer(relativeCtx,
  +                "product/product:name",
  +                "Box of oranges",
  +                "/vendor[1]/product[1]/goods:name[1]");
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message