[jbpm-commits] JBoss JBPM SVN: r4721 - in jbpm4/branches/ainze/modules: pvm/src/main/java/org/jbpm/pvm/internal/cfg and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon May 4 17:01:08 EDT 2009


Author: ainze
Date: 2009-05-04 17:01:08 -0400 (Mon, 04 May 2009)
New Revision: 4721

Added:
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
Removed:
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java
Modified:
   jbpm4/branches/ainze/modules/api/src/main/java/org/jbpm/api/Configuration.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
   jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java
   jbpm4/branches/ainze/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
Log:
initial working release

Modified: jbpm4/branches/ainze/modules/api/src/main/java/org/jbpm/api/Configuration.java
===================================================================
--- jbpm4/branches/ainze/modules/api/src/main/java/org/jbpm/api/Configuration.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/api/src/main/java/org/jbpm/api/Configuration.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -60,8 +60,8 @@
       implementationClassNames = new HashMap<String, String>();
       // null represents the default configuration (== the JbpmConfiguration)
       implementationClassNames.put(null, "org.jbpm.pvm.internal.cfg.JbpmConfiguration");
+      implementationClassNames.put("spring-test", "org.jbpm.pvm.internal.cfg.SpringConfiguration");
       // TODO 
-      // implementationClasses.put("spring", "org.jbpm.pvm.internal.cfg.SpringConfiguration");
       // implementationClasses.put("mc", "org.jbpm.pvm.internal.cfg.McConfiguration");
       // implementationClasses.put("programatic", "org.jbpm.pvm.internal.cfg.ProgramaticConfiguration");
     }

Modified: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/cfg/SpringConfiguration.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -21,85 +21,147 @@
  */
 package org.jbpm.pvm.internal.cfg;
 
-import java.util.HashSet;
+import java.io.IOException;
 import java.util.List;
-import java.util.Set;
 
+import org.jbpm.api.ProcessEngine;
+import org.jbpm.api.env.Context;
 import org.jbpm.api.env.Environment;
 import org.jbpm.api.env.EnvironmentFactory;
 import org.jbpm.api.env.WireObject;
-import org.jbpm.pvm.internal.spring.SpringEnvironment;
-import org.jbpm.pvm.internal.util.ReflectUtil;
+import org.jbpm.pvm.internal.env.PvmEnvironment;
+import org.jbpm.pvm.internal.env.SpringContext;
+import org.jbpm.pvm.internal.wire.WireContext;
+import org.jbpm.pvm.internal.wire.WireDefinition;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.io.ClassPathResource;
 
-/** this environment factory will see only the singleton beans.
+/**
+ * this environment factory will see only the singleton beans.
  * 
- * The created {@link SpringEnvironment}s will see the prototype 
- * beans and it will cache them.
- *  
- * @author Tom Baeyens
+ * The created {@link SpringEnvironment}s will see the prototype beans and it
+ * will cache them.
+ * 
+ * @author Andries Inze
  */
-public class SpringConfiguration implements EnvironmentFactory, ApplicationContextAware {
-  
-  // TODO pull up the common behaviour between this class and the SpringEnvironmentContext
-  
-  private static final long serialVersionUID = 1L;
-  
-  ApplicationContext applicationContext;
-  
-  public SpringEnvironment openEnvironment() {
-    return new SpringEnvironment(this);
-  }
+public class SpringConfiguration extends JbpmConfiguration implements
+        EnvironmentFactory, ProcessEngine, ApplicationContextAware {
 
-  public boolean has(String key) {
-    return applicationContext.isSingleton(key);
-  }
+    private static final long serialVersionUID = 1L;
 
-  public Object get(String key) {
-    if (has(key)) {
-      return applicationContext.getBean(key);
+    private ApplicationContext applicationContext;
+
+    private String jbpmConfigurationLocation;
+
+    /**
+     * Instantiates a new spring configuration.
+     */
+    public SpringConfiguration(String jbpmConfigurationLocation) {
+        try {
+            super.setInputStream(new ClassPathResource(
+                    jbpmConfigurationLocation).getInputStream());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
-    return null;
-  }
 
-  public <T> T get(Class<T> type) {
-    String name = ReflectUtil.getUnqualifiedClassName(type);
-    name = name.substring(0, 1).toLowerCase() + name.substring(1);
-    return (T) get(name);
-  }
+    public SpringConfiguration() {
+        // By jbpmTestCase
+    }
 
-  public Set<String> keys() {
-    HashSet<String> keys = new HashSet<String>();
-    for (String key : applicationContext.getBeanDefinitionNames()) {
-      if (has(key)) {
-        keys.add(key);
-      }
+    @Override
+    public ProcessEngine buildProcessEngine() {
+        if (applicationContext == null) {
+            applicationContext = new ClassPathXmlApplicationContext(System
+                    .getProperty("jbpm.test.cfg.applicationContext"));
+        }
+
+        return super.buildProcessEngine();
     }
-    return keys;
-  }
-  
-  public ApplicationContext getApplicationContext() {
-    return applicationContext;
-  }
 
-  public void setApplicationContext(ApplicationContext applicationContext) {
-    this.applicationContext = applicationContext;
-  }
+    /**
+     * {@inheritDoc)
 
-  
-  public void close() {
-  }
+     */
+    @Override
+    public Environment openEnvironment(List<WireObject> txWireObjects) {
 
-  public String getName() {
-    return null;
-  }
+        PvmEnvironment environment = new PvmEnvironment(this);
 
-  public Object set(String key, Object value) {
-    return null;
-  }
+        // FIXME: All beneath should be a super call
 
-  public Environment openEnvironment(List<WireObject> txWireObjects) {
-    return null;
-  }
+        // set the classloader
+        ClassLoader classLoader = processEngineWireContext.getClassLoader();
+        if (classLoader != null) {
+            environment.setClassLoader(classLoader);
+        }
+
+        // add the process-engine context
+        environment.addContext(new SpringContext(applicationContext));
+        environment.addContext(processEngineWireContext);
+
+        // add the transaction context
+        WireDefinition usedWireDefinition = transactionWireDefinition;
+        if (txWireObjects != null) {
+            usedWireDefinition = new WireDefinition(transactionWireDefinition,
+                    txWireObjects);
+        }
+
+        WireContext transactionContext = new WireContext(usedWireDefinition,
+                Context.CONTEXTNAME_TRANSACTION, environment, true);
+        // add the environment block context to the environment
+        environment.addContext(transactionContext);
+
+        Environment.pushEnvironment(environment);
+        try {
+            // finish the creation of the environment wire context
+            transactionContext.create();
+
+        } catch (RuntimeException e) {
+            Environment.popEnvironment();
+            throw e;
+        }
+
+        // if all went well, return the created environment
+        return environment;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T get(Class<T> type) {
+        String[] names = applicationContext.getBeanNamesForType(type);
+        if (names.length == 1) {
+            return (T) applicationContext.getBean(names[0]);
+        }
+
+        return super.get(type);
+    }
+
+    @Override
+    public Object get(String key) {
+        if (applicationContext.containsBean(key)) {
+            return applicationContext.getBean(key);
+        }
+
+        return super.get(key);
+    }
+
+    /**
+     * {@inheritDoc)
+
+     */
+    public void setApplicationContext(ApplicationContext applicationContext) {
+        this.applicationContext = applicationContext;
+    }
+
+    /**
+     * Gets the application context.
+     * 
+     * @return the application context
+     */
+    public ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
 }

Added: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -0,0 +1,83 @@
+/**
+ * 
+ */
+package org.jbpm.pvm.internal.env;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jbpm.api.env.Context;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * @author Andries Inze
+ * 
+ */
+public class SpringContext implements Context {
+
+	private ApplicationContext applicationContext;
+
+	public SpringContext(ApplicationContext applicationContext) {
+		this.applicationContext = applicationContext;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jbpm.api.env.Context#get(java.lang.String)
+	 */
+	public Object get(String key) {
+		if (applicationContext.containsBean(key)) {
+			return applicationContext.getBean(key);
+		}
+		return null;
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T> T get(Class<T> type) {
+		String[] names = applicationContext.getBeanNamesForType(type);
+		if (names.length == 1) {
+			return (T) applicationContext.getBean(names[0]);
+		}
+		return null;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jbpm.api.env.Context#getName()
+	 */
+	public String getName() {
+		return "SpringContext";
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jbpm.api.env.Context#has(java.lang.String)
+	 */
+	public boolean has(String key) {
+		return applicationContext.containsBean(key);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jbpm.api.env.Context#keys()
+	 */
+	public Set<String> keys() {
+		Set set = new HashSet<String>(Arrays.asList(applicationContext.getBeanDefinitionNames()));
+		return set;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.jbpm.api.env.Context#set(java.lang.String, java.lang.Object)
+	 */
+	public Object set(String key, Object value) {
+		throw new RuntimeException("Can't add to the spring context");
+	}
+
+}


Property changes on: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/SpringContext.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/CommandTransactionCallback.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -22,33 +22,34 @@
 package org.jbpm.pvm.internal.spring;
 
 import org.jbpm.api.cmd.Command;
-import org.jbpm.api.env.Environment;
-import org.jbpm.api.env.EnvironmentFactory;
+import org.jbpm.api.cmd.CommandService;
+import org.springframework.orm.hibernate3.HibernateTransactionManager;
+import org.springframework.orm.hibernate3.SessionFactoryUtils;
+import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.util.Assert;
 
 /**
- * @author Tom Baeyens
+ * @author Andries Inze
  */
 public class CommandTransactionCallback<T> implements TransactionCallback {
-  
-  Command<T> command;
-  EnvironmentFactory environmentFactory;
-  
-  public CommandTransactionCallback(Command<T> command, EnvironmentFactory environmentFactory) {
-    this.command = command;
-    this.environmentFactory = environmentFactory;
-  }
 
-  public T doInTransaction(TransactionStatus status) {
-    Environment environment = environmentFactory.openEnvironment();
-    try {
-      return command.execute(environment);
-    } catch (Exception e) {
-      throw new RuntimeException("ooops", e);
-    } finally {
-      environment.close();
+    private Command<T> command;
+    private CommandService commandService;
+    private PlatformTransactionManager manager;
+
+    public CommandTransactionCallback(Command<T> command,
+            CommandService commandService, PlatformTransactionManager platformTransactionManager) {
+        this.command = command;
+        this.commandService = commandService;
+        this.manager = platformTransactionManager;
     }
-  }
 
+    public T doInTransaction(TransactionStatus status) {
+        System.out.println("Running tx " + status);
+        ((HibernateTransactionManager) manager).getSessionFactory().getCurrentSession();
+        Assert.isTrue(SessionFactoryUtils.isSessionTransactional(((HibernateTransactionManager) manager).getSessionFactory().getCurrentSession(), ((HibernateTransactionManager) manager).getSessionFactory()));
+        return commandService.execute(command);
+    }
 }

Deleted: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/HibernateSessionManager.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -1,30 +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.spring;
-
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-/**
- * @author Tom Baeyens
- */
-public class HibernateSessionManager extends HibernateDaoSupport {
-}

Deleted: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringCommandService.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -1,58 +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.spring;
-
-import org.hibernate.Session;
-import org.jbpm.api.cmd.Command;
-import org.jbpm.api.cmd.CommandService;
-import org.jbpm.api.env.Environment;
-import org.jbpm.api.env.EnvironmentFactory;
-import org.springframework.orm.hibernate3.HibernateTransactionManager;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-import org.springframework.transaction.support.TransactionTemplate;
-
-
-/**
- * @author Tom Baeyens
- */
-public class SpringCommandService implements CommandService {
-  
-  TransactionTemplate transactionTemplate;
-  EnvironmentFactory environmentFactory;
-  
-  public void setEnvironmentFactory(EnvironmentFactory environmentFactory) {
-    this.environmentFactory = environmentFactory;
-  }
-
-  public void setTransactionManager(HibernateTransactionManager transactionManager) {
-    this.transactionTemplate = new TransactionTemplate(transactionManager);
-  }
-  
-  public <T> T execute(Command<T> command) {
-    return (T) transactionTemplate.execute(
-        new CommandTransactionCallback(command, environmentFactory)
-    );
-  }
-  
-  
-
-}

Deleted: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironment.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -1,70 +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.spring;
-
-import org.jbpm.api.env.EnvironmentFactory;
-import org.jbpm.pvm.internal.cfg.SpringConfiguration;
-import org.jbpm.pvm.internal.env.BasicEnvironment;
-import org.springframework.context.ApplicationContext;
-
-/** sees the prototype beans in the application context and 
- * this environment will cache all the prototyped objects.
- * 
- * @author Tom Baeyens
- */
-public class SpringEnvironment extends BasicEnvironment {
-
-  private static final long serialVersionUID = 1L;
-  
-  protected ApplicationContext applicationContext;
-
-  public SpringEnvironment(SpringConfiguration springConfiguration) {
-    addContext(springConfiguration);
-    addContext(new SpringEnvironmentContext(springConfiguration.getApplicationContext()));
-    pushEnvironment(this);
-  }
-
-  public ClassLoader getClassLoader() {
-    return null;
-  }
-
-  public EnvironmentFactory getEnvironmentFactory() {
-    return null;
-  }
-
-  public Throwable getException() {
-    return null;
-  }
-
-  public String getUserId() {
-    return null;
-  }
-
-  public void setClassLoader(ClassLoader classLoader) {
-  }
-
-  public void setException(Throwable exception) {
-  }
-
-  public void setUserId(String userId) {
-  }
-}

Deleted: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/spring/SpringEnvironmentContext.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -1,98 +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.spring;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.jbpm.api.env.Context;
-import org.jbpm.api.env.Environment;
-import org.jbpm.pvm.internal.util.ReflectUtil;
-import org.springframework.context.ApplicationContext;
-import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
-
-
-/**
- * @author Tom Baeyens
- */
-public class SpringEnvironmentContext implements Context {
-  
-  // TODO pull up the common behaviour between this class and the SpringEnvironmentFactory
-  
-  ApplicationContext applicationContext;
-  Map<String, Object> cache = new HashMap<String, Object>();
-
-  public SpringEnvironmentContext(ApplicationContext applicationContext) {
-    this.applicationContext = applicationContext;
-  }
-
-  public boolean has(String key) {
-    return applicationContext.isPrototype(key);
-  }
-
-  public Object get(String key) {
-    if (cache.containsKey(key)) {
-      return cache.get(key);
-    }
-    if (has(key)) {
-      Object bean = applicationContext.getBean(key);
-      // cache.put(key, bean);
-      return bean;
-    }
-    return null;
-  }
-
-  public <T> T get(Class<T> type) {
-    String name = ReflectUtil.getUnqualifiedClassName(type);
-    name = name.substring(0, 1).toLowerCase() + name.substring(1);
-    return (T) get(name);
-  }
-
-  public Set<String> keys() {
-    HashSet<String> keys = new HashSet<String>();
-    for (String key : applicationContext.getBeanDefinitionNames()) {
-      if (has(key)) {
-        keys.add(key);
-      }
-    }
-    return keys;
-  }
-  
-  public ApplicationContext getApplicationContext() {
-    return applicationContext;
-  }
-
-  public void setApplicationContext(ApplicationContext applicationContext) {
-    this.applicationContext = applicationContext;
-  }
-
-  
-  public String getName() {
-    return null;
-  }
-
-  public Object set(String key, Object value) {
-    return null;
-  }
-}

Added: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -0,0 +1,74 @@
+/*
+ * 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.tx;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.spring.CommandTransactionCallback;
+import org.jbpm.pvm.internal.svc.Interceptor;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+import org.springframework.util.Assert;
+
+
+/** calls setRollbackOnly on the transaction in the environment 
+ * in case an exception occurs during execution of the command.
+ * 
+ * @author Andries Inze
+ */
+public class SpringTransactionInterceptor extends Interceptor {
+  
+  private static final Log log = Log.getLog(SpringTransactionInterceptor.class.getName());
+  
+  @SuppressWarnings("unchecked")
+public <T> T execute(Command<T> command) {
+	Environment environment = Environment.getCurrent();
+	if (environment==null) {
+	    throw new JbpmException("no environment for managing hibernate transaction");
+	}
+    
+    StandardTransaction standardTransaction = environment.get(StandardTransaction.class);
+    if (standardTransaction==null) {
+      throw new JbpmException("no spring-transaction in environment");
+    }
+    
+    standardTransaction.begin();
+
+    try {
+    	PlatformTransactionManager platformTransactionManager = environment.get(PlatformTransactionManager.class);
+        Assert.notNull(platformTransactionManager);
+        TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
+        TransactionCallback transactionCallback = new CommandTransactionCallback<T>(command, next, platformTransactionManager);
+        return (T) template.execute(transactionCallback);
+      
+    } catch (RuntimeException e) {
+      standardTransaction.setRollbackOnly();
+      throw e;
+      
+    } finally {
+      standardTransaction.complete();
+    }
+  }
+}


Property changes on: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/SpringTransactionInterceptor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java	                        (rev 0)
+++ jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java	2009-05-04 21:01:08 UTC (rev 4721)
@@ -0,0 +1,47 @@
+/*
+ * 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.wire.binding;
+
+import org.jbpm.pvm.internal.tx.SpringTransactionInterceptor;
+import org.jbpm.pvm.internal.tx.StandardTransactionInterceptor;
+import org.jbpm.pvm.internal.wire.descriptor.ProvidedObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/** parses a descriptor for creating a {@link StandardTransactionInterceptor}.
+ * 
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class SpringTransactionInterceptorBinding extends WireInterceptorBinding {
+
+  public SpringTransactionInterceptorBinding() {
+    super("spring-transaction-interceptor");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    SpringTransactionInterceptor springTransactionInterceptor = new SpringTransactionInterceptor();
+    return new ProvidedObjectDescriptor(springTransactionInterceptor);
+  }
+}


Property changes on: jbpm4/branches/ainze/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/SpringTransactionInterceptorBinding.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/branches/ainze/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
===================================================================
--- jbpm4/branches/ainze/modules/pvm/src/main/resources/jbpm.wire.bindings.xml	2009-05-04 21:00:45 UTC (rev 4720)
+++ jbpm4/branches/ainze/modules/pvm/src/main/resources/jbpm.wire.bindings.xml	2009-05-04 21:01:08 UTC (rev 4721)
@@ -97,5 +97,8 @@
 
   <!-- jpdl bindings -->
   <binding class="org.jbpm.jpdl.internal.xml.JpdlDeployerBinding" />
+  
+  <!-- spring bindings -->
+  <binding class="org.jbpm.pvm.internal.wire.binding.SpringTransactionInterceptorBinding" />
 
 </wire-bindings>




More information about the jbpm-commits mailing list