[jbpm-commits] JBoss JBPM SVN: r2543 - in jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server: dao and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 15 05:42:59 EDT 2008


Author: heiko.braun at jboss.com
Date: 2008-10-15 05:42:59 -0400 (Wed, 15 Oct 2008)
New Revision: 2543

Added:
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOProxy.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/ServiceLocator.java
Removed:
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/ServiceLocator.java
Modified:
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOFactory.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DAOFactory.java
   jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java
Log:
Implement process diagram lookup and added DAOProxy for TX handling

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/JBPM3Management.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -24,8 +24,8 @@
 import org.jboss.bpm.console.client.model.jbpm3.ActiveNodeInfo;
 import org.jboss.bpm.console.client.model.jbpm3.DiagramInfo;
 import org.jboss.bpm.console.server.dao.DAOFactory;
+import org.jboss.bpm.console.server.dao.DiagramDAO;
 import org.jboss.bpm.console.server.dao.ProcessDAO;
-import org.jboss.bpm.console.server.dao.DiagramDAO;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.GET;
@@ -108,7 +108,8 @@
      HttpServletRequest request
    )
    {
-      return getDiagramDAO(request).getActivNodeInfo(id);
+      ActiveNodeInfo activNodeInfo = getDiagramDAO(request).getActivNodeInfo(id);
+      return activNodeInfo;
    }
 
 }

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOFactory.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOFactory.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOFactory.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -24,6 +24,8 @@
 import org.jboss.bpm.console.server.dao.DiagramDAO;
 
 import javax.servlet.ServletContext;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -49,7 +51,7 @@
 
       try
       {
-         return (DAOFactory)Class.forName(daoFactoryClassName).newInstance();         
+         return (DAOFactory)Class.forName(daoFactoryClassName).newInstance();
       }
       catch (Exception e)
       {

Added: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOProxy.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOProxy.java	                        (rev 0)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOProxy.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.dao;
+
+import org.jboss.bpm.console.server.util.ServiceLocator;
+
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+import java.lang.reflect.Method;
+
+/**
+ * Decorates DAO invocations with common system aspects, i.e. transaction demarcation.
+ *
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class DAOProxy implements java.lang.reflect.InvocationHandler
+{
+   private Object obj;
+
+   public static Object newInstance(Object obj) {
+      return java.lang.reflect.Proxy.newProxyInstance(
+        obj.getClass().getClassLoader(),
+        obj.getClass().getInterfaces(),
+        new DAOProxy(obj));
+   }
+
+   private DAOProxy(Object obj) {
+      this.obj = obj;
+   }
+
+   public Object invoke(Object proxy, Method m, Object[] args)
+     throws Throwable
+   {
+      Object result;
+
+      UserTransaction tx = ServiceLocator.getUserTransaction();
+
+      try
+      {
+         // before method invocation
+         tx.begin();
+
+         // field target invocation
+         result = m.invoke(obj, args);
+
+         tx.commit();
+
+      }
+      catch (Exception e)
+      {
+         if(tx!=null)
+         {
+            try
+            {
+               tx.rollback();
+            }
+            catch (SystemException e1) {}
+         }
+
+         throw new RuntimeException("Unexpected invocation exception: " + e.getMessage(), e);
+
+      }
+      finally
+      {
+         // after method invocation
+
+      }
+
+      return result;
+   }
+}
\ No newline at end of file


Property changes on: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/DAOProxy.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3CommandDelegate.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -27,6 +27,7 @@
 import org.jbpm.ejb.LocalCommandService;
 import org.jbpm.ejb.LocalCommandServiceHome;
 import org.jbpm.graph.def.ProcessDefinition;
+import org.jboss.bpm.console.server.util.ServiceLocator;
 
 import javax.ejb.CreateException;
 import java.util.List;

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DAOFactory.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DAOFactory.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DAOFactory.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -24,6 +24,7 @@
 import org.jboss.bpm.console.server.dao.DAOFactory;
 import org.jboss.bpm.console.server.dao.ProcessDAO;
 import org.jboss.bpm.console.server.dao.DiagramDAO;
+import org.jboss.bpm.console.server.dao.DAOProxy;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -33,11 +34,11 @@
 
    public ProcessDAO createProcessDAO()
    {
-      return new JBPM3ProcessDAO();  
+      return (ProcessDAO) DAOProxy.newInstance(new JBPM3ProcessDAO());              
    }
 
    public DiagramDAO createDiagramDAO()
    {
-      return new JBPM3DiagramDAO();  
+      return (DiagramDAO) DAOProxy.newInstance( new JBPM3DiagramDAO() );  
    }
 }

Modified: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/JBPM3DiagramDAO.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -23,9 +23,11 @@
 
 import org.jboss.bpm.console.client.model.jbpm3.ActiveNodeInfo;
 import org.jboss.bpm.console.client.model.jbpm3.DiagramInfo;
+import org.jboss.bpm.console.client.model.jbpm3.DiagramNodeInfo;
 import org.jboss.bpm.console.server.dao.DiagramDAO;
 
 import java.io.InputStream;
+import java.util.List;
 
 /**
  * @author Heiko.Braun <heiko.braun at jboss.com>
@@ -33,7 +35,7 @@
 public class JBPM3DiagramDAO implements DiagramDAO
 {
    private JBPM3CommandDelegate delegate;
-   
+
    private static final String PROCESSIMAGE_FILENAME = "processimage.jpg";
    private static final String GPD_XML_FILENAME = "gpd.xml";
 
@@ -57,7 +59,26 @@
 
    public ActiveNodeInfo getActivNodeInfo(long instanceId)
    {
-      
-      throw new RuntimeException("Not implemented");
+      org.jbpm.graph.exe.ProcessInstance instance = delegate.getActualInstance(instanceId);
+      String currentNodeName = instance.getRootToken().getNode().getName();
+
+      DiagramInfo diagram = getDiagramInfo(instance.getProcessDefinition().getId());
+      List<DiagramNodeInfo> nodes = diagram.getNodeList();
+
+      DiagramNodeInfo activeNode = null;
+      int i = 0;
+      for(DiagramNodeInfo n : nodes)
+      {
+         if(currentNodeName.equals(n.getName()))
+         {
+            activeNode = n;
+            break;
+         }
+      }
+
+      if(null==activeNode)
+         throw new RuntimeException("Failed to retrieve activeNodeInfo for instance " + instanceId);
+
+      return new ActiveNodeInfo(diagram.getWidth(), diagram.getHeight(), activeNode);
    }
 }

Deleted: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/ServiceLocator.java
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/ServiceLocator.java	2008-10-15 07:59:29 UTC (rev 2542)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/ServiceLocator.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.dao.internal;
-
-import javax.ejb.EJBLocalHome;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
-/**
- * @author Heiko.Braun <heiko.braun at jboss.com>
- */
-public class ServiceLocator
-{
-   public static EJBLocalHome getEjbLocalHome(String localHomeJndiName)
-   {
-      EJBLocalHome localHome = null;
-      try
-      {
-         Context ctx = new InitialContext();
-         localHome = (EJBLocalHome) ctx.lookup(localHomeJndiName);
-      }
-      catch (Exception cce)
-      {
-         throw new RuntimeException("Failed load access EJB: " +localHomeJndiName, cce);
-      }
-
-      return localHome;
-   }
-
-}
\ No newline at end of file

Copied: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/ServiceLocator.java (from rev 2538, jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/dao/internal/ServiceLocator.java)
===================================================================
--- jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/ServiceLocator.java	                        (rev 0)
+++ jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/ServiceLocator.java	2008-10-15 09:42:59 UTC (rev 2543)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jboss.bpm.console.server.util;
+
+import javax.ejb.EJBLocalHome;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.UserTransaction;
+import java.util.Properties;
+
+/**
+ * @author Heiko.Braun <heiko.braun at jboss.com>
+ */
+public class ServiceLocator
+{   
+   public static EJBLocalHome getEjbLocalHome(String localHomeJndiName)
+   {
+      EJBLocalHome localHome = null;
+      try
+      {
+         Context ctx = createContext();
+         localHome = (EJBLocalHome) ctx.lookup(localHomeJndiName);
+      }
+      catch (Exception cce)
+      {
+         throw new RuntimeException("Failed load access EJB: " +localHomeJndiName, cce);
+      }
+
+      return localHome;
+   }
+
+   public static UserTransaction getUserTransaction()
+   {
+      UserTransaction tx = null;
+
+      try
+      {
+         Context ctx = createContext();
+         tx = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Failed to create UserTransaction");
+      }
+
+      return tx;
+   }
+
+   private static Context createContext()
+     throws NamingException
+   {
+      InitialContext ctx = new InitialContext();
+      return ctx;
+   }
+}
\ No newline at end of file


Property changes on: jbpm3/trunk/modules/gwt-console/server/src/main/java/org/jboss/bpm/console/server/util/ServiceLocator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jbpm-commits mailing list