[jbpm-commits] JBoss JBPM SVN: r1851 - in jbpm4/pvm/trunk/modules: core/src/main/java/org/jbpm/pvm/internal and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Aug 8 09:23:00 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-08-08 09:23:00 -0400 (Fri, 08 Aug 2008)
New Revision: 1851

Added:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/ExecutionEnvironment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/usercode/
Removed:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ExecutionEnvironment.java
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Environment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/NodeImpl.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/TransitionImpl.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentFactoryRefBinding.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentFactoryDescriptor.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/EnvironmentSearchOrderTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/EnvWireTest.java
   jbpm4/pvm/trunk/modules/minimal/
Log:
Environment api cleanup

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Environment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Environment.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/Environment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -145,19 +145,18 @@
    */
   public abstract <T> T get(Class<T> type);
 
+  /** searches an object based on type.  The search doesn take superclasses of the context elements 
+   * into account.
+   * @return the first object of the given type or null in case no such element was found.  
+   */
+  public abstract <T> T get(Class<T> type, String[] searchOrder);
+
   /** get the authenticated user id */
   public abstract String getUserId();
   
   /** set the authenticated user id */
   public abstract void setUserId(String userId);
 
-  /** for clients to indicate that an exception has occurred in this environment block.
-   * Behaviour of method is configurable.*/
-  public abstract void setException(Throwable exception);
-  
-  /** retrieves the first exception that was reported in this environment block. */
-  public abstract Throwable getException();
-
   /**
    * closes the Environment by removing all its contexts.
    */
@@ -167,8 +166,6 @@
   public abstract void addContext(Context context);
   public abstract void removeContext(Context context);
   
-  public abstract EnvironmentFactory getEnvironmentFactory();
-
   public abstract ClassLoader getClassLoader();
   public abstract void setClassLoader(ClassLoader classLoader);
 

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/env/PvmEnvironmentFactory.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -69,8 +69,8 @@
    private static final Log log = Log.getLog(PvmEnvironmentFactory.class.getName());
    protected static PvmEnvironmentFactoryParser pvmEnvironmentFactoryParser = new PvmEnvironmentFactoryParser();
 
-   protected WireContext applicationWireContext = null;
-   protected WireDefinition blockWireDefinition = null;
+   protected WireContext environmentFactoryCtxWireContext = null;
+   protected WireDefinition environmentCtxWireDefinition = null;
 
    public PvmEnvironmentFactory() {
    }
@@ -114,30 +114,23 @@
       log.debug("opening "+environment);
 
       // set the classloader
-      ClassLoader classLoader = applicationWireContext.getClassLoader();
+      ClassLoader classLoader = environmentFactoryCtxWireContext.getClassLoader();
       if (classLoader!=null) {
          environment.setClassLoader(classLoader);
       }
 
       // add the environment-factory context
-      environment.addContext(applicationWireContext);
+      environment.addContext(environmentFactoryCtxWireContext);
 
       // add the environment block context
-      WireContext blockContext = new WireContext(blockWireDefinition, Context.CONTEXTNAME_ENVIRONMENT, environment, true);
+      WireContext environmentContext = new WireContext(environmentCtxWireDefinition, Context.CONTEXTNAME_ENVIRONMENT, environment, true);
       // add the environment block context to the environment
-      environment.addContext(blockContext);
+      environment.addContext(environmentContext);
 
-      // push the created environment so that Environment.getCurrent() returns it
-      // This is required to construct some objects in blockContext 
-      Environment.pushEnvironment(environment);
-      
       try {
         // finish the creation of the environment wire context
-        blockContext.create();
+        environmentContext.create();
 
-        // fire an open environment event
-        applicationWireContext.fire(PvmEnvironment.EVENT_OPENENVIRONMENT, environment);
-
       } catch (RuntimeException e) {
         // On exception, pop environment
         Environment.popEnvironment();
@@ -148,57 +141,48 @@
    }
 
    public void close() {
-      applicationWireContext.fire(WireContext.EVENT_CLOSE, null);
+      environmentFactoryCtxWireContext.fire(WireContext.EVENT_CLOSE, null);
    }
 
-   public void handleException(PvmEnvironment pvmEnvironment, Throwable exception) {
-      log.error("exception in environment block:"+exception.getMessage(), exception);
-      WireContext wireContext = (WireContext) pvmEnvironment.getEnvironmentContext();
-      wireContext.fire(PvmEnvironment.EVENT_EXCEPTION, this);
-   }
-
    // environment-factory context delegation methods ///////////////////////////////////
 
    public Object get(String key) {
-      return applicationWireContext.get(key);
+      return environmentFactoryCtxWireContext.get(key);
    }
 
    public <T> T get(Class<T> type) {
-      return applicationWireContext.get(type);
+      return environmentFactoryCtxWireContext.get(type);
    }
 
    public String getName() {
-      return applicationWireContext.getName();
+      return environmentFactoryCtxWireContext.getName();
    }
 
    public boolean has(String key) {
-      return applicationWireContext.has(key);
+      return environmentFactoryCtxWireContext.has(key);
    }
 
    public Set<String> keys() {
-      return applicationWireContext.keys();
+      return environmentFactoryCtxWireContext.keys();
    }
 
    public Object set(String key, Object value) {
-      return applicationWireContext.set(key, value);
+      return environmentFactoryCtxWireContext.set(key, value);
    }
 
    // getters and setters //////////////////////////////////////////////////////
 
-   public WireDefinition getBlockContextDefinition() {
-      return blockWireDefinition;
+   public void setEnvironmentCtxWireDefinition(WireDefinition blockWireDefinition) {
+      this.environmentCtxWireDefinition = blockWireDefinition;
    }
-   public void setBlockWireDefinition(WireDefinition blockWireDefinition) {
-      this.blockWireDefinition = blockWireDefinition;
+   public WireContext getEnvironmentFactoryCtxWireContext() {
+      return environmentFactoryCtxWireContext;
    }
-   public WireContext getApplicationWireContext() {
-      return applicationWireContext;
+   public void setEnvironmentFactoryCtxWireContext(WireContext applicationWireContext) {
+      this.environmentFactoryCtxWireContext = applicationWireContext;
    }
-   public void setApplicationWireContext(WireContext applicationWireContext) {
-      this.applicationWireContext = applicationWireContext;
+   public WireDefinition getEnvironmentCtxWireDefinition() {
+      return environmentCtxWireDefinition;
    }
-   public WireDefinition getBlockWireDefinition() {
-      return blockWireDefinition;
-   }
 
 }

Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.env;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Context;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.log.Log;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class BasicEnvironment extends Environment {
+
+  private static final long serialVersionUID = 1L;
+  
+  private static final Log log = Log.getLog(BasicEnvironment.class.getName()); 
+
+  protected String userId;
+  protected Map<String, Context> contexts;
+  protected ArrayList<String> defaultSearchOrderList;
+  protected String[] defaultSearchOrder;
+  protected Throwable exception;
+
+  protected transient ClassLoader classLoader;
+
+  public BasicEnvironment() {
+    contexts = new HashMap<String, Context>();
+    defaultSearchOrderList = new ArrayList<String>();
+    defaultSearchOrder = null;
+    pushEnvironment(this);
+  }
+
+  // context methods ////////////////////////////////////////////////////////////
+
+  public Context getContext(String contextName) {
+    return contexts.get(contextName);
+  }
+
+  public void addContext(Context context) {
+    String key = context.getName();
+    contexts.put(key, context);
+    defaultSearchOrderList.add(key);
+    defaultSearchOrder = null;
+  }
+
+  public void removeContext(Context context) {
+    String contextName = context.getName();
+    Context removedContext = contexts.remove(contextName);
+    if (removedContext!=null) {
+      defaultSearchOrderList.remove(contextName);
+      defaultSearchOrder = null;
+    }
+  }
+
+  public Context getEnvironmentFactoryContext() {
+    return getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
+  }
+
+  public Context getEnvironmentContext() {
+    return getContext(Context.CONTEXTNAME_ENVIRONMENT);
+  }
+
+  // userId methods ///////////////////////////////////////////////////////////
+  
+  public String getUserId() {
+    // if the authenticated user was explicitely set
+    if (userId!=null) {
+      // return that one
+      return userId;
+    }
+    
+    // if an Authentication was specified
+    Authentication authentication = get(Authentication.class);
+    if (authentication!=null) {
+      // let the authentication do the work
+      return authentication.getUserId();
+    }
+
+    return null; 
+  }
+  
+  public void setUserId(String userId) {
+    this.userId = userId;
+  }
+
+  // classloader methods //////////////////////////////////////////////////////
+
+  public ClassLoader getClassLoader() {
+    return classLoader;
+  }
+  public void setClassLoader(ClassLoader classLoader) {
+    this.classLoader = classLoader;
+  }
+  
+  // search methods ///////////////////////////////////////////////////////////
+
+  public Object get(String name) {
+    return get(name, null);
+  }
+  
+  public Object get(String name, String[] searchOrder) {
+    if (searchOrder==null) {
+      searchOrder = getDefaultSearchOrder();
+    }
+    for (int i=0; i<searchOrder.length; i++){
+      Context context = contexts.get(searchOrder[i]);
+      if (context.has(name)) {
+        return context.get(name);
+      }
+    }
+    return null;
+  }
+
+  public <T> T get(Class<T> type) {
+    return get(type, null);
+  }
+
+  public <T> T get(Class<T> type, String[] searchOrder) {
+    if (searchOrder==null) {
+      searchOrder = getDefaultSearchOrder();
+    }
+    for (int i=0; i<searchOrder.length; i++){
+      Context context = contexts.get(searchOrder[i]);
+      T o = context.get(type);
+      if (o!=null) {
+        return o;
+      }
+    }
+    return null;
+  }
+  
+  // close ////////////////////////////////////////////////////////////////////
+
+  public void close() {
+    log.trace("closing "+this);
+
+    Environment popped = Environment.popEnvironment();
+    if (this!=popped) {
+      throw new PvmException("environment nesting problem");
+    }
+  }
+  
+  // private methods //////////////////////////////////////////////////////////
+
+  protected String[] getDefaultSearchOrder() {
+    if (defaultSearchOrder==null) {
+      int size = defaultSearchOrderList.size();
+      defaultSearchOrder = (String[]) new String[size];
+      for (int i=0; i<size; i++) {
+        defaultSearchOrder[i] = defaultSearchOrderList.get(size-1-i);
+      }
+    }
+    return defaultSearchOrder;
+  }
+}

Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/ExecutionEnvironment.java (from rev 1835, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ExecutionEnvironment.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/ExecutionEnvironment.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/ExecutionEnvironment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.env;
+
+import org.jbpm.pvm.Execution;
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExecutionEnvironment extends BasicEnvironment {
+
+  private static final long serialVersionUID = 1L;
+  
+  public ExecutionEnvironment(Execution execution) {
+    addContext(new ExecutionContext(execution));
+  }
+}


Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/ExecutionEnvironment.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -21,14 +21,7 @@
  */
 package org.jbpm.pvm.internal.env;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jbpm.pvm.PvmException;
 import org.jbpm.pvm.env.Context;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.EnvironmentFactory;
 import org.jbpm.pvm.env.PvmEnvironmentFactory;
 import org.jbpm.pvm.internal.log.Log;
 import org.jbpm.pvm.internal.util.Closable;
@@ -37,159 +30,32 @@
 /**
  * @author Tom Baeyens
  */
-public class PvmEnvironment extends Environment {
+public class PvmEnvironment extends BasicEnvironment {
 
   private static final long serialVersionUID = 1L;
   
   private static final Log log = Log.getLog(PvmEnvironment.class.getName()); 
 
-  /** is fired for each exception reported in an environment block with 
-   * {@link Environment#setException(Throwable)}. */ 
-  public static final String EVENT_EXCEPTION = "exception";
-
-  /** is fired when a environment created by this factory is being closed.  The
-   * info object is the environment that was just opened. */
-  public static final String EVENT_CLOSEENVIRONMENT = "close-environment";
-
-  /** is fired when a new environment is being opened with this environment factory.  The
-   * info object is the environment that was just opened. */
-  public static final String EVENT_OPENENVIRONMENT = "open-environment";
-
-
-  protected String userId;
   protected PvmEnvironmentFactory pvmEnvironmentFactory;
-  protected Map<String, Context> contexts;
-  protected ArrayList<String> defaultSearchOrderList;
-  protected String[] defaultSearchOrder;
-  protected transient ClassLoader classLoader;
-  protected Throwable exception;
 
   public PvmEnvironment(PvmEnvironmentFactory pvmEnvironmentFactory) {
     this.pvmEnvironmentFactory = pvmEnvironmentFactory;
-    contexts = new HashMap<String, Context>();
-    defaultSearchOrderList = new ArrayList<String>();
-    defaultSearchOrder = null;
   }
 
-  // context methods ////////////////////////////////////////////////////////////
-
-  public Context getContext(String contextName) {
-    return contexts.get(contextName);
+  public String toString() {
+    return "PvmEnvironment["+System.identityHashCode(this)+"]";
   }
-
-  public void addContext(Context context) {
-    String key = context.getName();
-    contexts.put(key, context);
-    defaultSearchOrderList.add(key);
-    defaultSearchOrder = null;
-  }
-
-  public void removeContext(Context context) {
-    String contextName = context.getName();
-    Context removedContext = contexts.remove(contextName);
-    if (removedContext!=null) {
-      defaultSearchOrderList.remove(contextName);
-      defaultSearchOrder = null;
+  public void close() {
+    Context context = getEnvironmentContext();
+    if (context instanceof Closable) {
+      ((Closable)context).close();
     }
+    super.close();
+    log.debug("closed "+this);
   }
 
-  public Context getEnvironmentFactoryContext() {
-    return getContext(Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
-  }
-
-  public Context getEnvironmentContext() {
-    return getContext(Context.CONTEXTNAME_ENVIRONMENT);
-  }
-
-  public EnvironmentFactory getEnvironmentFactory() {
-    return pvmEnvironmentFactory;
-  }
-
-  // userId methods ///////////////////////////////////////////////////////////
   
-  public String getUserId() {
-    // if the authenticated user was explicitely set
-    if (userId!=null) {
-      // return that one
-      return userId;
-    }
-    
-    // if an Authentication was specified
-    Authentication authentication = get(Authentication.class);
-    if (authentication!=null) {
-      // let the authentication do the work
-      return authentication.getUserId();
-    }
-
-    return null; 
-  }
-  
-  public void setUserId(String userId) {
-    this.userId = userId;
-  }
-
-  // classloader methods //////////////////////////////////////////////////////
-
-  public ClassLoader getClassLoader() {
-    return classLoader;
-  }
-  public void setClassLoader(ClassLoader classLoader) {
-    this.classLoader = classLoader;
-  }
-  
-  // search methods ///////////////////////////////////////////////////////////
-
-  public Object get(String name) {
-    return get(name, null);
-  }
-  
-  public Object get(String name, String[] searchOrder) {
-    if (searchOrder==null) {
-      searchOrder = getDefaultSearchOrder();
-    }
-    for (int i=0; i<searchOrder.length; i++){
-      Context context = contexts.get(searchOrder[i]);
-      if (context.has(name)) {
-        return context.get(name);
-      }
-    }
-    return null;
-  }
-
-  public <T> T get(Class<T> type) {
-    return find(type, null);
-  }
-
-  public <T> T find(Class<T> type, String[] searchOrder) {
-    if (searchOrder==null) {
-      searchOrder = getDefaultSearchOrder();
-    }
-    for (int i=0; i<searchOrder.length; i++){
-      Context context = contexts.get(searchOrder[i]);
-      T o = context.get(type);
-      if (o!=null) {
-        return o;
-      }
-    }
-    return null;
-  }
-  
-  // exception ////////////////////////////////////////////////////////////////
-
-  public void setException(Throwable exception) {
-    this.exception = exception;
-    pvmEnvironmentFactory.handleException(this, exception);
-
-    // if an exception was thrown
-    if (exception!=null) {
-      rethrow(exception);
-    }
-  }
-
-  public Throwable getException() {
-    return exception;
-  }
-
+  /*
   // close ////////////////////////////////////////////////////////////////////
 
   public void close() {
@@ -208,10 +74,6 @@
     }
     log.debug("closed "+this);
   }
-  
-  public String toString() {
-    return "Environment["+System.identityHashCode(this)+"]";
-  }
 
   protected static void rethrow(Throwable exception) throws Error {
     if (exception instanceof Error) {
@@ -222,18 +84,5 @@
     }
     throw new PvmException(exception);
   }
-
-  // private methods //////////////////////////////////////////////////////////
-
-  private String[] getDefaultSearchOrder() {
-    if (defaultSearchOrder==null) {
-      int size = defaultSearchOrderList.size();
-      defaultSearchOrder = (String[]) new String[size];
-      for (int i=0; i<size; i++) {
-        defaultSearchOrder[i] = defaultSearchOrderList.get(size-1-i);
-      }
-    }
-    return defaultSearchOrder;
-  }
-
+  */
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/env/PvmEnvironmentFactoryParser.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -80,13 +80,13 @@
     WireDefinition environmentWireDefinition = getBlockWireDefinition(documentElement, parse);
 
     // create the application wire context from the definition
-    WireContext environmentFactoryWireContext = new WireContext(environmentFactoryWireDefinition, Context.CONTEXTNAME_ENVIRONMENT_FACTORY, pvmEnvironmentFactory);
+    WireContext environmentFactoryWireContext = new WireContext(environmentFactoryWireDefinition, Context.CONTEXTNAME_ENVIRONMENT_FACTORY);
     // propagate the parser classloader to the application context
     environmentFactoryWireContext.setClassLoader(classLoader);
 
     // configure the default environment factory
-    pvmEnvironmentFactory.setApplicationWireContext(environmentFactoryWireContext);
-    pvmEnvironmentFactory.setBlockWireDefinition(environmentWireDefinition);
+    pvmEnvironmentFactory.setEnvironmentFactoryCtxWireContext(environmentFactoryWireContext);
+    pvmEnvironmentFactory.setEnvironmentCtxWireDefinition(environmentWireDefinition);
     
     parse.setDocumentObject(pvmEnvironmentFactory);
 

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerImpl.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -29,6 +29,7 @@
 import org.jbpm.pvm.PvmException;
 import org.jbpm.pvm.env.Environment;
 import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.cmd.CommandService;
 import org.jbpm.pvm.internal.log.Log;
 import org.jbpm.pvm.internal.model.op.MoveToChildNode;
 import org.jbpm.pvm.internal.wire.Descriptor;
@@ -121,10 +122,14 @@
       Transaction transaction = (environment!=null ? environment.get(Transaction.class) : null);
       if (transaction!=null) {
         log.trace("registering exception handler to "+transaction);
+        CommandService commandService = environment.get(CommandService.class);
+        if (commandService==null) {
+          throw new PvmException("environment doesn't have a command service for registering transactional exception handler", exception);
+        }
         ExceptionHandlerSynchronization exceptionHandlerSynchronization = new ExceptionHandlerSynchronization(
                 this, execution, 
                 exception,
-                environment.getEnvironmentFactory()
+                commandService
         );
         // registration of the synchronization is delegated to the AfterTxCompletionListener
         // to avoid a dependency on class Synchronization

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExceptionHandlerSynchronization.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -40,23 +40,19 @@
   
   protected ExecutionImpl execution;
   protected Exception exception;
-  protected EnvironmentFactory environmentFactory;
+  protected CommandService commandService;
 
-  public ExceptionHandlerSynchronization(ExceptionHandlerImpl exceptionHandler, ExecutionImpl execution, Exception exception, EnvironmentFactory environmentFactory) {
+  public ExceptionHandlerSynchronization(ExceptionHandlerImpl exceptionHandler, ExecutionImpl execution, Exception exception, CommandService commandService) {
     this.exceptionHandler = exceptionHandler;
     this.execution = execution;
     this.exception = exception;
-    this.environmentFactory = environmentFactory;
+    this.commandService = commandService;
   }
 
   public void afterCompletion(int status) {
     if (status!=Status.STATUS_ROLLEDBACK) {
       ExceptionHandlerImpl.log.info("WARNING: no rollback after transactional exception handler. did you forget to rollback the transaction ?");
     }
-    CommandService commandService = environmentFactory.get(CommandService.class);
-    if (commandService==null) {
-      throw new PvmException("environment factory doesn't have a command service");
-    }
     commandService.execute(this);
   }
 

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -1061,7 +1061,7 @@
   }
   
   public void handleException(ObservableElementImpl observableElement,
-                              EventImpl actionEvent,
+                              EventImpl event,
                               EventListenerReference eventListenerReference,
                               Exception exception,
                               String rethrowMessage) {
@@ -1070,8 +1070,8 @@
     if (eventListenerReference!=null) {
       processElements.add(eventListenerReference);
     }
-    if (actionEvent!=null) {
-      processElements.add(actionEvent);
+    if (event!=null) {
+      processElements.add(event);
     }
     while (observableElement!=null) {
       processElements.add(observableElement);

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/NodeImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/NodeImpl.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/NodeImpl.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -99,15 +99,20 @@
    * @throws NullPointerException if destination is null.
    */
   public TransitionImpl createOutgoingTransition(NodeImpl destination, String transitionName) {
+    TransitionImpl transition = createOutgoingTransition(transitionName);
+    if (destination!=null) {
+      destination.addIncomingTransition(transition);
+    }
+    return transition;
+  }
+  
+  public TransitionImpl createOutgoingTransition(String transitionName) {
     // create a new transition
     TransitionImpl transition = new TransitionImpl();
     transition.setName(transitionName);
     
     // wire it between the source and destination
     addOutgoingTransition(transition);
-    if (destination!=null) {
-      destination.addIncomingTransition(transition);
-    }
 
     // if there is no default transition yet
     if (defaultTransition==null) {

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/TransitionImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/TransitionImpl.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/TransitionImpl.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -41,9 +41,7 @@
   protected ObjectReference<Condition> waitConditionReference;
   protected boolean isTakeAsync;
   
-  /**
-   * Use {@link NodeImpl#createOutgoingTransition(NodeImpl)} instead.
-   */
+  /* Use one of the NodeImpl.createOutgoingTransition methods instead. */
   TransitionImpl() {
     super();
   }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/EnvironmentBindings.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -60,7 +60,9 @@
   protected Context getReadContext(Object key) {
     for (String readContextName: readContextNames) {
       Context readContext = environment.getContext(readContextName);
-      if (readContext.has((String) key)) {
+      if ( (readContext!=null)
+           && (readContext.has((String) key))
+         ) {
         return readContext;
       }
     }

Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ExecutionEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ExecutionEnvironment.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ExecutionEnvironment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.script;
-
-import org.jbpm.pvm.env.Context;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.EnvironmentFactory;
-import org.jbpm.pvm.env.Transaction;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-
-
-/**
- * @author Tom Baeyens
- */
-public class ExecutionEnvironment extends Environment {
-
-  private static final long serialVersionUID = 1L;
-  
-  ExecutionImpl execution;
-
-  public ExecutionEnvironment(ExecutionImpl execution) {
-    this.execution = execution;
-  }
-
-  public Object get(String name) {
-    return execution.getVariable(name);
-  }
-
-  public void addContext(Context context) {
-  }
-
-  public void close() {
-  }
-
-  public Object get(String name, String[] searchOrder) {
-    return null;
-  }
-
-  public <T> T get(Class<T> type) {
-    return null;
-  }
-
-  public ClassLoader getClassLoader() {
-    return null;
-  }
-
-  public Context getContext(String contextName) {
-    return null;
-  }
-
-  public EnvironmentFactory getEnvironmentFactory() {
-    return null;
-  }
-
-  public Throwable getException() {
-    return null;
-  }
-
-  public String getUserId() {
-    return null;
-  }
-
-  public void removeContext(Context context) {
-  }
-
-  public void setClassLoader(ClassLoader classLoader) {
-  }
-
-  public void setException(Throwable exception) {
-  }
-
-  public void setUserId(String userId) {
-  }
-}

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -31,7 +31,7 @@
 import org.jbpm.pvm.PvmException;
 import org.jbpm.pvm.env.Environment;
 import org.jbpm.pvm.internal.env.ExecutionContext;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.env.ExecutionEnvironment;
 import org.jbpm.pvm.internal.wire.WireContext;
 import org.jbpm.pvm.internal.wire.WireDefinition;
 import org.jbpm.pvm.internal.wire.xml.WireParser;
@@ -96,15 +96,27 @@
       throw new PvmException("no scripting engine configured for language "+language);
     }
 
-    ExecutionContext executionContext = null;
     Environment environment = Environment.getCurrent();
     if (environment==null) {
-      environment = new ExecutionEnvironment((ExecutionImpl) execution);
-    } else if (execution!=null) {
-      executionContext = new ExecutionContext(execution);
+      environment = new ExecutionEnvironment(execution);
+      try {
+        return evaluate(scriptEngine, script);
+      } finally {
+        environment.close();
+      }
+
+    } else {
+      ExecutionContext executionContext = new ExecutionContext(execution);
       environment.addContext(executionContext);
+      try {
+        return evaluate(scriptEngine, script);
+      } finally {
+        environment.removeContext(executionContext);
+      }
     }
-
+  }
+  
+  protected Object evaluate(ScriptEngine scriptEngine, String script) {
     Bindings bindings = new EnvironmentBindings(readContextNames, writeContextName);
     scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
     
@@ -112,10 +124,6 @@
       return scriptEngine.eval(script);
     } catch (ScriptException e) {
       throw new PvmException("script evaluation error: "+e.getMessage(), e);
-    } finally {
-      if (executionContext!=null) {
-        environment.removeContext(executionContext);
-      }
     }
   }
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -26,10 +26,9 @@
 import java.util.Map;
 
 import org.jbpm.pvm.env.Context;
-import org.jbpm.pvm.env.Environment;
 import org.jbpm.pvm.env.EnvironmentFactory;
 import org.jbpm.pvm.env.SpringEnvironmentFactory;
-import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.env.BasicEnvironment;
 import org.springframework.context.ApplicationContext;
 
 /** sees the prototype beans in the application context and 
@@ -37,97 +36,17 @@
  * 
  * @author Tom Baeyens
  */
-public class SpringEnvironment extends Environment {
+public class SpringEnvironment extends BasicEnvironment {
 
-  // TODO pull up the common behaviour between this class 
-  // and the DefaultEnvironment (only do this after/if this 
-  // design is adopted) 
-
   private static final long serialVersionUID = 1L;
   
   protected ApplicationContext applicationContext;
 
-  protected Map<String, Context> contexts = new HashMap<String, Context>();
-  protected ArrayList<String> defaultSearchOrderList = new ArrayList<String>();
-  protected String[] defaultSearchOrder;
-
   public SpringEnvironment(SpringEnvironmentFactory springEnvironmentFactory) {
     addContext(springEnvironmentFactory);
     addContext(new SpringEnvironmentContext(springEnvironmentFactory.getApplicationContext()));
   }
 
-  // context methods ////////////////////////////////////////////////////////////
-
-  public Context getContext(String contextName) {
-    return contexts.get(contextName);
-  }
-
-  public void addContext(Context context) {
-    String key = context.getName();
-    contexts.put(key, context);
-    defaultSearchOrderList.add(key);
-    defaultSearchOrder = null;
-  }
-
-  public void removeContext(Context context) {
-    String contextName = context.getName();
-    Context removedContext = contexts.remove(contextName);
-    if (removedContext!=null) {
-      defaultSearchOrderList.remove(contextName);
-      defaultSearchOrder = null;
-    }
-  }
-
-  // search methods ///////////////////////////////////////////////////////////
-
-  public Object get(String name) {
-    return get(name, null);
-  }
-  
-  public Object get(String name, String[] searchOrder) {
-    if (searchOrder==null) {
-      searchOrder = getDefaultSearchOrder();
-    }
-    for (int i=0; i<searchOrder.length; i++){
-      Context context = contexts.get(searchOrder[i]);
-      if (context.has(name)) {
-        return context.get(name);
-      }
-    }
-    return null;
-  }
-
-  public <T> T get(Class<T> type) {
-    return find(type, null);
-  }
-
-  public <T> T find(Class<T> type, String[] searchOrder) {
-    if (searchOrder==null) {
-      searchOrder = getDefaultSearchOrder();
-    }
-    for (int i=0; i<searchOrder.length; i++){
-      Context context = contexts.get(searchOrder[i]);
-      T o = context.get(type);
-      if (o!=null) {
-        return o;
-      }
-    }
-    return null;
-  }
-  
-  private String[] getDefaultSearchOrder() {
-    if (defaultSearchOrder==null) {
-      int size = defaultSearchOrderList.size();
-      defaultSearchOrder = (String[]) new String[size];
-      for (int i=0; i<size; i++) {
-        defaultSearchOrder[i] = defaultSearchOrderList.get(size-1-i);
-      }
-    }
-    return defaultSearchOrder;
-  }
-  
-  
-
   public void close() {
   }
 

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/WireContext.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -202,7 +202,6 @@
   // member fields ////////////////////////////////////////////////////////////
 
   protected String name = "wire-context";
-  protected EnvironmentFactory environmentFactory;
   protected transient ClassLoader classLoader;
   protected WireDefinition wireDefinition;
 
@@ -231,11 +230,10 @@
 
   /** when this {@link Context} is used in an {@link Environment}, it 
    * needs a name.  */
-  public WireContext(WireDefinition wireDefinition, String name, EnvironmentFactory environmentFactory) {
+  public WireContext(WireDefinition wireDefinition, String name) {
     this.wireDefinition = wireDefinition;
     this.name = name;
     this.classLoader = (wireDefinition!=null ? wireDefinition.getClassLoader() : null);
-    this.environmentFactory = environmentFactory;
     create();
   }
 
@@ -252,9 +250,6 @@
     this.wireDefinition = wireDefinition;
     this.name = name;
     this.classLoader = (wireDefinition!=null ? wireDefinition.getClassLoader() : null);
-    if (environment!=null) {
-      this.environmentFactory = environment.getEnvironmentFactory();
-    }
 
     if (! delayCreate) {
       create();
@@ -740,7 +735,4 @@
   public void setWireDefinition(WireDefinition wireDefinition) {
     this.wireDefinition = wireDefinition;
   }
-  public EnvironmentFactory getEnvironmentFactory() {
-    return environmentFactory;
-  }
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentFactoryRefBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentFactoryRefBinding.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentFactoryRefBinding.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -41,6 +41,7 @@
   }
 
   public Object parse(Element element, Parse parse, Parser parser) {
-    return new EnvironmentFactoryDescriptor();
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) parse.getDocumentObject();
+    return new EnvironmentFactoryDescriptor(environmentFactory);
   }
 }
\ No newline at end of file

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/EnvironmentInterceptorBinding.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.pvm.internal.wire.binding;
 
+import org.jbpm.pvm.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.wire.descriptor.EnvironmentInterceptorDescriptor;
 import org.jbpm.pvm.internal.xml.Parse;
 import org.jbpm.pvm.internal.xml.Parser;
@@ -30,13 +31,14 @@
  * @author Tom Baeyens
  */
 public class EnvironmentInterceptorBinding extends WireInterceptorBinding {
-
+    
   public EnvironmentInterceptorBinding() {
     super("environment-interceptor");
   }
 
   public Object parse(Element element, Parse parse, Parser parser) {
-    return new EnvironmentInterceptorDescriptor();
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) parse.getDocumentObject();
+    return new EnvironmentInterceptorDescriptor(environmentFactory);
   }
 
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentFactoryDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentFactoryDescriptor.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentFactoryDescriptor.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -11,8 +11,14 @@
 public class EnvironmentFactoryDescriptor extends AbstractDescriptor {
 
   private static final long serialVersionUID = 1L;
+  
+  EnvironmentFactory environmentFactory;
 
+  public EnvironmentFactoryDescriptor(EnvironmentFactory environmentFactory) {
+    this.environmentFactory = environmentFactory;
+  }
+
   public Object construct(WireContext wireContext) {
-    return wireContext.getEnvironmentFactory();
+    return environmentFactory;
   }
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/EnvironmentInterceptorDescriptor.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -31,13 +31,16 @@
 public class EnvironmentInterceptorDescriptor extends AbstractDescriptor {
 
   private static final long serialVersionUID = 1L;
+  
+  EnvironmentFactory environmentFactory;
+  
+  public EnvironmentInterceptorDescriptor(EnvironmentFactory environmentFactory) {
+    this.environmentFactory = environmentFactory;
+  }
 
   public Object construct(WireContext wireContext) {
     EnvironmentInterceptor environmentInterceptor = new EnvironmentInterceptor();
-    
-    EnvironmentFactory environmentFactory = wireContext.getEnvironmentFactory();
     environmentInterceptor.setEnvironmentFactory(environmentFactory);
-    
     return environmentInterceptor;
   }
 }

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -277,9 +277,6 @@
             ) {
               autoWireValue = wireContext;
 
-            } else if ("environmentFactory".equals(fieldName)) {
-              autoWireValue = Environment.getCurrent().getEnvironmentFactory();
-
             } else if (wireContext.has(fieldName)) {
               autoWireValue = wireContext.get(fieldName);
 

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/EnvironmentSearchOrderTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/EnvironmentSearchOrderTest.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/env/EnvironmentSearchOrderTest.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -128,7 +128,7 @@
         "  <string name='a' value='added-a' />" +
         "</objects>"
       );
-      WireContext addedContext = new WireContext(wireDefinition, "added", environmentFactory);
+      WireContext addedContext = new WireContext(wireDefinition, "added");
       
       // add the new context to the enviromnent
       environment.addContext(addedContext);
@@ -162,7 +162,7 @@
         "  <string name='a' value='added-a' />" +
         "</objects>"
       );
-      WireContext addedContext = new WireContext(wireDefinition, "added", environmentFactory);
+      WireContext addedContext = new WireContext(wireDefinition, "added");
       
       // add the new context to the enviromnent
       environment.addContext(addedContext);

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/ContextBlockSubscriptionTest.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -77,14 +77,14 @@
     // In this test, there is no eager initialization
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"'>" +
       "      <subscribe />" +
       "    </object>" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -127,14 +127,14 @@
     // In this test, there is eager initialisation
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
       "      <subscribe />" +
       "    </object>" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -161,7 +161,7 @@
     // In this test, there is eager initialisation
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
@@ -169,7 +169,7 @@
       "    </object>" +
       "    <object name='o' class='"+Object.class.getName()+"' />" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -202,14 +202,14 @@
     // In this test, there is eager initialisation
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
       "      <subscribe event='interestingevent'/>" +
       "    </object>" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -238,14 +238,14 @@
     // In this test, there is eager initialisation
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
       "      <subscribe events='constructing, open, constructed, interestingevent, close'/>" +
       "    </object>" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -285,7 +285,7 @@
     // In this test, there is eager initialisation
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
@@ -293,7 +293,7 @@
       "    </object>" +
       "    <object name='o' class='"+Object.class.getName()+"' />" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -321,7 +321,7 @@
 
   public void testOtherWireScope() {
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory>" +
       "    <object name='factory' class='"+Object.class.getName()+"' />" +
       "  </environment-factory>" +
@@ -331,20 +331,17 @@
       "    </object>" +
       "    <object name='product' factory='factory' method='getClass' />" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     int index=0;
 
     Environment environment = environmentFactory.openEnvironment();
     try {
-      assertEquals(events.toString(), 1, events.size());
-      assertEquals("open-environment", events.get(index).eventName);
-      assertSame(environment, events.get(index).info);
+      assertEquals(events.toString(), 0, events.size());
 
       assertNotNull(environment.get("product"));
 
-      index++;
       assertEquals("constructing", events.get(index).eventName);
       assertEquals("factory", ((WireObjectEventInfo)events.get(index).info).getObjectName());
       index++;
@@ -362,23 +359,19 @@
       environment.close();
     }
 
-    index++;
-    assertEquals("close-environment", events.get(index).eventName);
-    assertEquals(environment, events.get(index).info);
-
     environmentFactory.close();
 
     index++;
     assertEquals("close", events.get(index).eventName);
     PvmEnvironmentFactory pvmEnvironmentFactory = (PvmEnvironmentFactory) environmentFactory;
-    WireContext applicationWireContext = pvmEnvironmentFactory.getApplicationWireContext();
+    WireContext applicationWireContext = pvmEnvironmentFactory.getEnvironmentFactoryCtxWireContext();
     assertEquals(applicationWireContext, events.get(index).source);
     assertNull(events.get(index).info);
   }
 
   public void testOtherWireScopeWithEventFiltering() {
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory>" +
       "    <object name='factory' class='"+Object.class.getName()+"' />" +
       "  </environment-factory>" +
@@ -388,7 +381,7 @@
       "    </object>" +
       "    <object name='product' factory='factory' method='getClass' />" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     int index=0;
@@ -416,14 +409,14 @@
 
   public void testUnexistingScope() {
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='recorder' class='"+Recorder.class.getName()+"' init='eager'>" +
       "      <subscribe context='unexistingcontext' />" +
       "    </object>" +
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     assertNull(Environment.getCurrent());
@@ -445,7 +438,7 @@
     // In this test, there is no eager initialization
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='a' class='"+A.class.getName()+"'>" +
@@ -456,7 +449,7 @@
       "      </field>" +
       "     </object>"+
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();
@@ -504,7 +497,7 @@
     // In this test, there is no eager initialization
 
     EnvironmentFactory environmentFactory = PvmEnvironmentFactory.parseXmlString(
-      "<environment-scopes>" +
+      "<contexts>" +
       "  <environment-factory />" +
       "  <environment>" +
       "    <object name='a' class='"+A.class.getName()+"'>" +
@@ -519,7 +512,7 @@
       "      </field>" +
       "     </object>"+
       "  </environment>" +
-      "</environment-scopes>"
+      "</contexts>"
     );
 
     Environment environment = environmentFactory.openEnvironment();

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/EnvWireTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/EnvWireTest.java	2008-08-07 11:54:56 UTC (rev 1850)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/EnvWireTest.java	2008-08-08 13:23:00 UTC (rev 1851)
@@ -52,7 +52,6 @@
 
         assertNotNull(f);
         assertEquals(environmentFactory, f);
-        assertEquals(f, environment.getEnvironmentFactory());
       } finally {
         environment.close();
       }


Property changes on: jbpm4/pvm/trunk/modules/minimal
___________________________________________________________________
Name: svn:ignore
   + target





More information about the jbpm-commits mailing list