Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: ProcessMessageDispatcher.java 12639 2008-09-12 18:46:39Z tcarlson $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.transport.bpm;
 
 
 import java.util.Map;

Initiates or advances a workflow process from an outgoing Mule event.
 
 {
     private ProcessConnector connector;
 
     public ProcessMessageDispatcher(OutboundEndpoint endpoint)
     {
         super(endpoint);
         this. = (ProcessConnector)endpoint.getConnector();
     }

    
Performs a synchronous action on the BPMS.

Returns:
an object representing the new state of the process
 
     public MuleMessage doSend(MuleEvent eventthrows Exception
     {
         Object process = processAction(event);
 
         if (process != null)
         {
             MuleMessage msg = new DefaultMuleMessage(process);
             msg.setProperty(..getBpms().getId(process));
             return msg;
         }
         else
         {
             throw new DispatchException(MessageFactory
                 .createStaticMessage("Synchronous process invocation must return the new process state."),
                 event.getMessage(), event.getEndpoint());
         }
     }

    
Performs an asynchronous action on the BPMS.
 
     public void doDispatch(MuleEvent eventthrows Exception
     {
         processAction(event);
     }
 
     protected Object processAction(MuleEvent eventthrows Exception
     {
         // An object representing the new state of the process
         Object process = null;
 
         // Create a map of process variables based on the message properties.
         Map processVariables = new HashMap();
         if (event != null)
         {
             String propertyName;
             for (Iterator iterator = event.getMessage().getPropertyNames().iterator(); iterator.hasNext();)
             {
                 propertyName = (String)iterator.next();
                 processVariables.put(propertyNameevent.getMessage().getProperty(propertyName));
             }
 
             Object payload = event.transformMessage();
             if (payload != null && !(payload instanceof NullPayload))
             {
                 // Store the message's payload as a process variable.
                 processVariables.put(.payload);
 
                 // Store the endpoint on which the message was received as a process
                 // variable.
                 String originatingEndpoint = event.getMessage().getStringProperty(
                     .null);
                 if (StringUtils.isNotEmpty(originatingEndpoint))
                 {
                    processVariables.put(.,
                        originatingEndpoint);
                }
            }
        }
        // Retrieve the parameters
        Object processType = event.getProperty(./* exhaustiveSearch */
        true);
        processVariables.remove(.);
        // TODO MULE-1220 The processId for BPM is sort of like a session and so we could probably use
        // Mule's SessionHandler interface for managing this.  
        Object processId;
        String processIdField = .getProcessIdField();
        if (StringUtils.isNotEmpty(processIdField))
        {
            processId = event.getProperty(processIdField/* exhaustiveSearch */false);
        }
        // If processId is explicitly set for the message, this overrides the
        // processIdField.
        processId = event.getProperty(./* exhaustiveSearch */true);
        processVariables.remove(.);
        // Default action is "advance"
            .);
        processVariables.remove(.);
        Object transition = event.getMessage().getProperty(.);
        processVariables.remove(.);
        // Decode the URI, for example:
        // bpm://testProcess/4561?action=advance
        String temp;
        temp = event.getEndpoint().getEndpointURI().getHost();
        if (StringUtils.isNotEmpty(temp))
        {
            processType = temp;
        }
        temp = event.getEndpoint().getEndpointURI().getPath();
        if (StringUtils.isNotEmpty(temp))
        {
            // Strip the leading "/" from the path.
            if (temp.startsWith("/"))
            {
                temp = StringUtils.right(temptemp.length() - 1);
            }
            // If there are any remaining "/", we don't know what to do with them.
            if (temp.indexOf("/") != -1)
            {
                throw new IllegalArgumentException("Unexpected format in the path of the URL: " + temp);
            }
            processId = temp;
        }
        // //////////////////////////////////////////////////////////////////////
        // Start a new process.
        if (processId == null || action.equals(.))
        {
            if (processType != null)
            {
                process = .getBpms().startProcess(processTypetransitionprocessVariables);
                if ((process != null) && .isInfoEnabled())
                {
                    .info("New process started, ID = " + .getBpms().getId(process));
                }
            }
            else
            {
                throw new IllegalArgumentException("Process type is missing, cannot start a new process.");
            }
        }
        // Don't advance the process, just update the process variables.
        else if (action.equals(.))
        {
            if (processId != null)
            {
                process = .getBpms().updateProcess(processIdprocessVariables);
                if ((process != null) && .isInfoEnabled())
                {
                    .info("Process variables updated, ID = " + .getBpms().getId(process));
                }
            }
            else
            {
                throw new IllegalArgumentException("Process ID is missing, cannot update process.");
            }
        }
        // Abort the running process (end abnormally).
        else if (action.equals(.))
        {
            if (processId != null)
            {
                .getBpms().abortProcess(processId);
                process = NullPayload.getInstance();
                .info("Process aborted, ID = " + processId);
            }
            else
            {
                throw new IllegalArgumentException("Process ID is missing, cannot abort process.");
            }
        }
        // Advance the already-running process one step.
        else
        {
            if (processId != null)
            {
                process = .getBpms().advanceProcess(processIdtransitionprocessVariables);
                if ((process != null) && .isInfoEnabled())
                {
                    .info("Process advanced, ID = " + .getBpms().getId(process)
                                    + ", new state = " + .getBpms().getState(process));
                }
            }
            else
            {
                throw new IllegalArgumentException("Process ID is missing, cannot advance process.");
            }
        }
        return process;
    }
New to GrepCode? Check out our FAQ X