[jboss-cvs] jboss-seam/src/main/org/jboss/seam/bpm ...

Gavin King gavin.king at jboss.com
Wed Jun 20 01:34:31 EDT 2007


  User: gavin   
  Date: 07/06/20 01:34:31

  Modified:    src/main/org/jboss/seam/bpm       Jbpm.java
  Added:       src/main/org/jboss/seam/bpm       PageflowParser.java
                        SeamFunctionMapper.java
                        SeamUserCodeInterceptor.java
                        SeamVariableResolver.java jbpm.pageflow.cfg.xml
  Log:
  reorg pageflow stuff
  make some things package-private
  
  Revision  Changes    Path
  1.3       +22 -6     jboss-seam/src/main/org/jboss/seam/bpm/Jbpm.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Jbpm.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/bpm/Jbpm.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- Jbpm.java	19 Jun 2007 20:08:12 -0000	1.2
  +++ Jbpm.java	20 Jun 2007 05:34:31 -0000	1.3
  @@ -26,12 +26,8 @@
   import org.jboss.seam.annotations.Startup;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.core.Init;
  -import org.jboss.seam.jbpm.SeamFunctionMapper;
  -import org.jboss.seam.jbpm.SeamUserCodeInterceptor;
  -import org.jboss.seam.jbpm.SeamVariableResolver;
   import org.jboss.seam.log.LogProvider;
   import org.jboss.seam.log.Logging;
  -import org.jboss.seam.pageflow.PageflowHelper;
   import org.jboss.seam.util.Naming;
   import org.jboss.seam.util.Resources;
   import org.jbpm.JbpmConfiguration;
  @@ -155,7 +151,7 @@
         {
            throw new IllegalArgumentException("pageflow resource not found: " + resourceName);
         }
  -      return PageflowHelper.parseInputSource( new InputSource(resource) );
  +      return Jbpm.parseInputSource( new InputSource(resource) );
      }
      
      public ProcessDefinition getProcessDefinitionFromResource(String resourceName) 
  @@ -206,7 +202,7 @@
       */
      public ProcessDefinition getPageflowDefinitionFromXml(String pageflowDefinition)
      {
  -      return PageflowHelper.parseInputSource( new InputSource( new ReaderInputStream( new StringReader(pageflowDefinition) ) ) );
  +      return Jbpm.parseInputSource( new InputSource( new ReaderInputStream( new StringReader(pageflowDefinition) ) ) );
      }
      
      /**
  @@ -292,6 +288,26 @@
         this.jbpmConfigurationJndiName = jbpmConfigurationJndiName;
      }
      
  +   public static JbpmConfiguration pageflowConfiguration = JbpmConfiguration.parseResource("org/jboss/seam/pageflow/jbpm.pageflow.cfg.xml");
  +
  +   public static JbpmContext createPageflowContext() 
  +   {
  +      return pageflowConfiguration.createJbpmContext();
  +   }
  +
  +   public static ProcessDefinition parseInputSource(InputSource inputSource) 
  +   {
  +      JbpmContext jbpmContext = createPageflowContext();
  +      try 
  +      {
  +         return new PageflowParser(inputSource).readProcessDefinition();
  +      } 
  +      finally 
  +      {
  +         jbpmContext.close();
  +      }
  +   }
  +
      private static final DbSubProcessResolver DB_SUB_PROCESS_RESOLVER = new DbSubProcessResolver();
      class SeamSubProcessResolver implements SubProcessResolver
      {
  
  
  
  1.1      date: 2007/06/20 05:34:31;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/bpm/PageflowParser.java
  
  Index: PageflowParser.java
  ===================================================================
  package org.jboss.seam.bpm;
  
  import java.io.Reader;
  
  import org.dom4j.Element;
  import org.jbpm.graph.def.Node;
  import org.jbpm.graph.def.NodeCollection;
  import org.jbpm.jpdl.xml.JpdlXmlReader;
  import org.jbpm.jpdl.xml.ProblemListener;
  import org.xml.sax.InputSource;
  
  /**
   * A jPDL parser for Seam pageflow definitions
   * 
   * @author Tom Baeyens
   *
   */
  class PageflowParser extends JpdlXmlReader 
  {
  
    private static final long serialVersionUID = 1L;
  
    public PageflowParser(InputSource inputSource, ProblemListener problemListener) 
    {
       super(inputSource, problemListener);
    }
  
    public PageflowParser(InputSource inputSource) 
    {
       super(inputSource);
    }
  
    public PageflowParser(Reader reader) 
    {
       super(reader);
    }
    
    @Override
    public void readNodes(Element nodeCollectionElement, NodeCollection nodeCollection) 
    {
       super.readNodes(nodeCollectionElement, nodeCollection);
      
       if ( "pageflow-definition".equals( nodeCollectionElement.getName() ) ) 
       {
          String startPageName = nodeCollectionElement.attributeValue("start-page");
          if (startPageName==null) 
          {
             Element startPageElement = nodeCollectionElement.element("start-page");
             if (startPageElement!=null) 
             {
                startPageName = startPageElement.attributeValue("name");
             }
          }
          if (startPageName!=null) 
          {
             Node startPage = getProcessDefinition().getNode(startPageName);
             if (startPage!=null) 
             {
                getProcessDefinition().setStartState(startPage);
             }
          }
       }
    }
    
  }
  
  
  
  1.1      date: 2007/06/20 05:34:31;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/bpm/SeamFunctionMapper.java
  
  Index: SeamFunctionMapper.java
  ===================================================================
  package org.jboss.seam.bpm;
  
  import java.lang.reflect.Method;
  
  import org.jbpm.jpdl.el.FunctionMapper;
  
  /**
   * Wrapper for SeamFunctionMapper that works with JBPM.
   * 
   * @author Shane Bryzak
   */
  class SeamFunctionMapper implements FunctionMapper
  {
     private org.jboss.seam.el.SeamFunctionMapper mapper;
     
     public SeamFunctionMapper()
     {
        mapper = new org.jboss.seam.el.SeamFunctionMapper();
     }
     
     public Method resolveFunction(String prefix, String localName)
     {
        return mapper.resolveFunction(prefix, localName);
     }
  }
  
  
  
  1.1      date: 2007/06/20 05:34:31;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/bpm/SeamUserCodeInterceptor.java
  
  Index: SeamUserCodeInterceptor.java
  ===================================================================
  package org.jboss.seam.bpm;
  
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.Lifecycle;
  import org.jbpm.context.exe.ContextInstance;
  import org.jbpm.graph.def.Action;
  import org.jbpm.graph.exe.ExecutionContext;
  import org.jbpm.graph.exe.Token;
  import org.jbpm.instantiation.UserCodeInterceptor;
  import org.jbpm.taskmgmt.def.AssignmentHandler;
  import org.jbpm.taskmgmt.def.TaskControllerHandler;
  import org.jbpm.taskmgmt.exe.Assignable;
  import org.jbpm.taskmgmt.exe.TaskInstance;
  
  /**
   * Intercepts calls to user code coming from jBPM, sets up
   * Seam contexts and associates the process and task instances
   * with the contexts.
   * 
   * @author Gavin King
   *
   */
  class SeamUserCodeInterceptor implements UserCodeInterceptor
  {
     abstract static class ContextualCall
     {
        abstract void process() throws Exception;
        
        void run() throws Exception
        {
           if ( Contexts.isEventContextActive() || Contexts.isApplicationContextActive() ) //not sure about the second bit (only needed at init time!)
           {
              process();
           }
           else
           {
              Lifecycle.beginCall();
              try
              {
                 process();
              }
              finally
              {
                 Lifecycle.endCall();
              }
           }
        }
        
        void runAndWrap()
        {
           try
           {
              run();
           }
           catch (RuntimeException re)
           {
              throw re;
           }
           catch (Exception e)
           {
              throw new RuntimeException(e);
           }
        }
     }
  
     public void executeAction(final Action action, final ExecutionContext context) throws Exception
     {
        if ( isPageflow(context) )
        {
           action.execute(context);
        }
        else
        {
           new ContextualCall()
           {
              @Override
              void process() throws Exception
              {
                 initProcessAndTask(context);
                 action.execute(context);
              }
           }.run();
        }
     }
  
     private boolean isPageflow(final ExecutionContext context)
     {
        return Contexts.isConversationContextActive() && 
              Jbpm.instance().isPageflowProcessDefinition( context.getProcessDefinition().getName() );
     }
  
     public void executeAssignment(final AssignmentHandler handler, final Assignable assignable, 
              final ExecutionContext context)
              throws Exception
     {
        new ContextualCall()
        {
           @Override
           void process() throws Exception
           {
              initProcessAndTask(context);
              handler.assign(assignable, context);
           }
        }.run();
     }
  
     public void executeTaskControllerInitialization(final TaskControllerHandler handler, final TaskInstance task,
              final ContextInstance context, final Token token)
     {
        new ContextualCall()
        {
           @Override
           void process() throws Exception
           {
              initProcessAndTask(task);
              handler.initializeTaskVariables(task, context, token);
           }
        }.runAndWrap();
     }
  
     public void executeTaskControllerSubmission(final TaskControllerHandler handler, final TaskInstance task,
              final ContextInstance context, final Token token)
     {
        new ContextualCall()
        {
           @Override
           void process() throws Exception
           {
              initProcessAndTask(task);
              handler.submitTaskVariables(task, context, token);
           }
        }.runAndWrap();
     }
  
     private static void initProcessAndTask(ExecutionContext context)
     {
        BusinessProcess businessProcess = BusinessProcess.instance();
        businessProcess.setProcessId( context.getProcessInstance().getId() );
        TaskInstance taskInstance = context.getTaskInstance();
        if (taskInstance!=null)
        {
           businessProcess.setTaskId( taskInstance.getId() );
        }
     }
  
     private static void initProcessAndTask(TaskInstance task)
     {
        BusinessProcess businessProcess = BusinessProcess.instance();
        businessProcess.setProcessId( task.getProcessInstance().getId() );
        businessProcess.setTaskId( task.getId() );
     }
  
  }
  
  
  
  1.1      date: 2007/06/20 05:34:31;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/bpm/SeamVariableResolver.java
  
  Index: SeamVariableResolver.java
  ===================================================================
  package org.jboss.seam.bpm;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.core.Init;
  import org.jbpm.jpdl.el.ELException;
  import org.jbpm.jpdl.el.VariableResolver;
  import org.jbpm.jpdl.el.impl.JbpmVariableResolver;
  
  /**
   * Resolves Seam variables for jBPM.
   * 
   * @author Gavin King
   *
   */
  class SeamVariableResolver implements VariableResolver 
  {
     
     private VariableResolver jbpmVariableResolver = new JbpmVariableResolver();
  
  	public Object resolveVariable(String name) throws ELException 
     {
  	   name = name.replace('$', '.');
  	   Object instance = Component.getInstance(name, true);
        if (instance==null)
        {
           instance = jbpmVariableResolver.resolveVariable(name);
           if (instance==null)
           {
              return Init.instance().getRootNamespace().getChild(name);
           }
           else
           {
              return instance;
           }
        }
        else
        {
           return instance;
        }
  	}
  
  }
  
  
  
  1.1      date: 2007/06/20 05:34:31;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/bpm/jbpm.pageflow.cfg.xml
  
  Index: jbpm.pageflow.cfg.xml
  ===================================================================
  <pageflow-configuration>
    <jbpm-context />
  </pageflow-configuration>
  
  
  



More information about the jboss-cvs-commits mailing list