craigmcc    01/08/19 21:14:19

  Modified:    workflow/src/java/org/apache/commons/workflow/base
                        BaseContext.java BaseContextBean.java
                        BaseScope.java
               workflow/src/test/org/apache/commons/workflow/base
                        BaseContextTestCase.java
  Log:
  The problem with JPath integration was that JPath needed to be told that
  BaseScope was a "dynamic class".  Now, a bean named "foo" in local scope
  can be accessed by XPath expression "local/foo", while (assuming the web
  integration layer provided by WebContext) a session attribute would be
  accessed as "local/session/foo".
  
  The next step will be to update the core "get" and "put" step
  implementations to support XPath syntax as well.
  
  Revision  Changes    Path
  1.6       +14 -4     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java
  
  Index: BaseContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseContext.java  2001/08/19 23:53:10     1.5
  +++ BaseContext.java  2001/08/20 04:14:19     1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
 1.5 2001/08/19 23:53:10 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2001/08/19 23:53:10 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
 1.6 2001/08/20 04:14:19 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/08/20 04:14:19 $
    *
    * ====================================================================
    * 
  @@ -84,7 +84,7 @@
    * class.  If it is used in a multiple thread environment, callers must
    * take suitable precations.</p>
    *
  - * @version $Revision: 1.5 $ $Date: 2001/08/19 23:53:10 $
  + * @version $Revision: 1.6 $ $Date: 2001/08/20 04:14:19 $
    * @author Craig R. McClanahan
    */
   
  @@ -367,6 +367,16 @@
               scopes[scope] = impl;
           }
           bean = null;
  +
  +    }
  +
  +
  +    /**
  +     * Return the Scope instance for our local Scope as a simple property.
  +     */
  +    public Scope getLocal() {
  +
  +        return (getScope(LOCAL_SCOPE));
   
       }
   
  
  
  
  1.2       +4 -17     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContextBean.java
  
  Index: BaseContextBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContextBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseContextBean.java      2001/08/19 23:53:10     1.1
  +++ BaseContextBean.java      2001/08/20 04:14:19     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContextBean.java,v
 1.1 2001/08/19 23:53:10 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/19 23:53:10 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContextBean.java,v
 1.2 2001/08/20 04:14:19 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/08/20 04:14:19 $
    *
    * ====================================================================
    * 
  @@ -84,20 +84,7 @@
       }
   
       public Map getLocal() {
  -        return ((Map) baseContext.getScope(Context.LOCAL_SCOPE));
  -    }
  -
  -    public Map getScopes() {
  -        if (scopes != null)
  -            return (scopes);
  -        scopes = new HashMap();
  -        String names[] = baseContext.getScopeNames();
  -        for (int i = 0; i < names.length; i++) {
  -            if (names[i] == null)
  -                continue;
  -            scopes.put(names[i], baseContext.getScope(i));
  -        }
  -        return (scopes);
  +        return (baseContext.getScope(Context.LOCAL_SCOPE));
       }
   
   }
  
  
  
  1.2       +19 -4     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java
  
  Index: BaseScope.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseScope.java    2001/08/13 21:16:01     1.1
  +++ BaseScope.java    2001/08/20 04:14:19     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java,v
 1.1 2001/08/13 21:16:01 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/13 21:16:01 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java,v
 1.2 2001/08/20 04:14:19 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/08/20 04:14:19 $
    *
    * ====================================================================
    * 
  @@ -67,6 +67,8 @@
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Set;
  +import org.apache.commons.jpath.JPathIntrospector;
  +import org.apache.commons.jpath.tree.MapDynamicPropertyHandler;
   import org.apache.commons.workflow.Scope;
   import org.apache.commons.workflow.ScopeListener;
   import org.apache.commons.workflow.util.ScopeSupport;
  @@ -82,11 +84,24 @@
    * class.  If it is used in a multiple thread environment, callers must
    * take suitable precations.</p>
    *
  - * @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
  + * @version $Revision: 1.2 $ $Date: 2001/08/20 04:14:19 $
    * @author Craig R. McClanahan
    */
   
   public class BaseScope implements Scope {
  +
  +
  +    // -------------------------------------------------- Static Initialization
  +
  +
  +    /**
  +     * Register ourselves with JPathIntrospector as an instance of a
  +     * dynamic class (in JPath terminology).
  +     */
  +    static {
  +        JPathIntrospector.registerDynamicClass
  +            (BaseScope.class, MapDynamicPropertyHandler.class);
  +    }
   
   
       // ----------------------------------------------------- Instance Variables
  
  
  
  1.5       +10 -80    
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java
  
  Index: BaseContextTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseContextTestCase.java  2001/08/19 23:53:10     1.4
  +++ BaseContextTestCase.java  2001/08/20 04:14:19     1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v
 1.4 2001/08/19 23:53:10 craigmcc Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/08/19 23:53:10 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v
 1.5 2001/08/20 04:14:19 craigmcc Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/08/20 04:14:19 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,7 @@
    * functions that are not dependent upon an associated Activity.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2001/08/19 23:53:10 $
  + * @version $Revision: 1.5 $ $Date: 2001/08/20 04:14:19 $
    */
   
   public class BaseContextTestCase extends TestCase {
  @@ -280,85 +280,18 @@
           // Extract the associated JPathContext
           JPathContext jpc = context.getJPathContext();
           assertNotNull("Context can find JPathContext", jpc);
  -        assertNotNull("JPathContext can find scopes",
  -                      jpc.getValue("scopes"));
           assertNotNull("JPathContext can find local",
  -                      jpc.getValue("scopes/local"));
  -        assertNotNull("JPathContext can find extra #1",
  -                      jpc.getValue("scopes/extra"));
  -        try {
  -            Object value = jpc.getValue("local");
  -            System.out.println("local --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("local --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("local/extra");
  -            System.out.println("local/extra --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("local/extra --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("local/local0");
  -            System.out.println("local/local0 --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("local/local0 --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("scopes/extra");
  -            System.out.println("scopes/extra --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("scopes/extra --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("scopes/extra/extra0");
  -            System.out.println("scopes/extra/extra0 --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("scopes/extra/extra0 --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("scopes/local");
  -            System.out.println("scopes/local --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("scopes/local --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("scopes/local/extra");
  -            System.out.println("scopes/local/extra --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("scopes/local/extra --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -        try {
  -            Object value = jpc.getValue("scopes/local/local0");
  -            System.out.println("scopes/local/local0 --> " + value);
  -        } catch (Throwable t) {
  -            System.out.println("scopes/local/local0 --> EXCEPTION");
  -            t.printStackTrace(System.out);
  -        }
  -
  -
  -        /* FIXME - these fail accessing a Scope as a Map is not working
  -        assertNotNull("JPathContext can find extra #2",
  -                          jpc.getValue("scopes/local/extra"));
  +                      jpc.getValue("local"));
  +        assertNotNull("JPathContext can find extra",
  +                          jpc.getValue("local/extra"));
   
           // Validate access using JPath access methods
           assertEquals("JPathContext can find local0",
                        "This is local0",
  -                     (String) jpc.getValue("scopes/local/local0"));
  -        assertEquals("JPathContext can find extra0 #1",
  +                     (String) jpc.getValue("local/local0"));
  +        assertEquals("JPathContext can find extra0",
                        "This is extra0",
  -                     (String) jpc.getValue("scopes/extra/extra0"));
  -        assertEquals("JPathContext can find extra0 #1",
  -                     "This is extra0",
  -                     (String) jpc.getValue("scopes/local/extra/extra0"));
  -        */
  +                     (String) jpc.getValue("local/extra/extra0"));
   
       }
   
  @@ -384,15 +317,12 @@
           assertEquals("Get lastName", "Test Last Name",
                        (String) jpc.getValue("lastName"));
           assertNotNull("Get addresses", jpc.getValue("addresses"));
  -        System.out.println("addresses is " + jpc.getValue("addresses"));
           assertEquals("Get addresses/home/zipCode",
                        "HmZip",
                        (String) jpc.getValue("addresses/home/zipCode"));
           assertEquals("Get addresses/office/zipCode",
                        "OfZip",
                        (String) jpc.getValue("addresses/office/zipCode"));
  -        System.out.println("addresses/home is " + jpc.getValue("addresses/home"));
  -        System.out.println("addresses/office is " + 
jpc.getValue("addresses/office"));
   
       }
   
  
  
  

Reply via email to