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 BeanModelTestCase.java
Date Sun, 04 May 2003 23:51:59 GMT
dmitri      2003/05/04 16:51:59

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
               jxpath/src/java/org/apache/commons/jxpath JXPathContext.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        BeanModelTestCase.java
  Log:
  Fixed inheritance of functions and leniency
  Cached context factory
  
  Revision  Changes    Path
  1.32      +7 -11     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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- JXPathContextReferenceImpl.java	25 Mar 2003 02:41:33 -0000	1.31
  +++ JXPathContextReferenceImpl.java	4 May 2003 23:51:59 -0000	1.32
  @@ -553,11 +553,11 @@
           return new JXPathContextReferenceImpl(this, contextBean, pointer);
       }
       
  -    public synchronized Pointer getContextPointer() {
  +    public Pointer getContextPointer() {
           return contextPointer;
       }
   
  -    private synchronized NodePointer getAbsoluteRootPointer() {
  +    private NodePointer getAbsoluteRootPointer() {
           return (NodePointer) rootPointer;
       }
   
  @@ -604,12 +604,8 @@
                   if (func != null) {
                       return func;
                   }
  -
  -                funcCtx = funcCtx.getParentContext();
  -            }
  -            else {
  -                break;
               }
  +            funcCtx = funcCtx.getParentContext();
           }
           func = GENERIC_FUNCTIONS.getFunction(namespace, name, parameters);
           if (func != null) {
  
  
  
  1.17      +26 -9     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java
  
  Index: JXPathContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JXPathContext.java	11 Mar 2003 00:59:12 -0000	1.16
  +++ JXPathContext.java	4 May 2003 23:51:59 -0000	1.17
  @@ -427,18 +427,20 @@
       protected Functions functions;
       protected AbstractFactory factory;
       protected Locale locale;
  +    protected boolean lenientSet = false;
       protected boolean lenient = false;
       protected IdentityManager idManager;
       protected KeyManager keyManager;
       protected HashMap decimalFormats;
   
  +    private static JXPathContextFactory contextFactory;
       private static JXPathContext compilationContext;
   
       /**
        * Creates a new JXPathContext with the specified object as the root node.
        */
       public static JXPathContext newContext(Object contextBean) {
  -        return JXPathContextFactory.newInstance().newContext(null, contextBean);
  +        return getContextFactory().newContext(null, contextBean);
       }
   
       /**
  @@ -450,12 +452,20 @@
           JXPathContext parentContext,
           Object contextBean) 
       {
  -        return JXPathContextFactory.newInstance().newContext(
  -            parentContext,
  -            contextBean);
  +        return getContextFactory().newContext(parentContext, contextBean);
       }
   
       /**
  +     * Acquires a context factory and caches it. 
  +     */
  +    private static JXPathContextFactory getContextFactory () {
  +        if (contextFactory == null) {
  +            contextFactory = JXPathContextFactory.newInstance();            
  +        }
  +        return contextFactory;
  +    }
  +    
  +    /**
        * This  constructor should remain protected - it is to be overridden by
        * subclasses, but never explicitly invoked by clients.
        */
  @@ -477,7 +487,7 @@
       public Object getContextBean() {
           return contextBean;
       }
  -
  +    
       /**
        * Returns a Pointer for the context bean.
        */
  @@ -598,6 +608,9 @@
        */
       public DecimalFormatSymbols getDecimalFormatSymbols(String name) {
           if (decimalFormats == null) {
  +            if (parentContext != null) {
  +                return parentContext.getDecimalFormatSymbols(name);
  +            }
               return null;
           }
           return (DecimalFormatSymbols) decimalFormats.get(name);
  @@ -614,12 +627,16 @@
        */
       public void setLenient(boolean lenient) {
           this.lenient = lenient;
  +        lenientSet = true;
       }
   
       /**
        * @see #setLenient(boolean)
        */
       public boolean isLenient() {
  +        if (!lenientSet && parentContext != null) {
  +            return parentContext.isLenient();
  +        }
           return lenient;
       }
   
  
  
  
  1.14      +16 -4     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java
  
  Index: BeanModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/BeanModelTestCase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- BeanModelTestCase.java	25 Mar 2003 02:41:35 -0000	1.13
  +++ BeanModelTestCase.java	4 May 2003 23:51:59 -0000	1.14
  @@ -68,12 +68,14 @@
   import java.util.Locale;
   
   import org.apache.commons.jxpath.AbstractFactory;
  +import org.apache.commons.jxpath.ClassFunctions;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.JXPathTestCase;
   import org.apache.commons.jxpath.NestedTestBean;
   import org.apache.commons.jxpath.Pointer;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
  +import org.apache.commons.jxpath.ri.compiler.TestFunctions;
   import org.apache.commons.jxpath.ri.model.beans.PropertyOwnerPointer;
   import org.apache.commons.jxpath.ri.model.beans.PropertyPointer;
   
  @@ -985,5 +987,15 @@
               "../integers[2]", 
               new Integer(2), 
               "/integers[2]");
  +    }
  +    
  +    public void testRelativeContextInheritance() {
  +        context.setFunctions(new ClassFunctions(TestFunctions.class, "test"));
  +        JXPathContext relative =
  +            context.getRelativeContext(context.getPointer("nestedBean"));
  +        
  +        assertXPathValue(relative, 
  +            "test:countPointers(strings)", 
  +            new Integer(3));
       }
   }
  
  
  

---------------------------------------------------------------------
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