Coverage Report - org.mule.providers.bpm.jbpm.actions.ValidateMessageType
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidateMessageType
0%
0/13
0%
0/3
6
 
 1  
 /*
 2  
  * $Id: ValidateMessageType.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.bpm.jbpm.actions;
 12  
 
 13  
 import org.mule.util.ClassUtils;
 14  
 
 15  
 import org.jbpm.JbpmException;
 16  
 import org.jbpm.graph.exe.ExecutionContext;
 17  
 
 18  
 /**
 19  
  * Throws an exception if the incoming message's class is not as expected.
 20  
  * 
 21  
  *  <action class="org.mule.providers.bpm.jbpm.actions.ValidateMessageType">
 22  
  *     <expectedType>com.mycompany.MyClass</expectedType> 
 23  
  *  </action>
 24  
  *  
 25  
  * @param expectedType the expected class type
 26  
  * @param strict if true, the class must match exactly, otherwise it can be a subclass
 27  
  * @throws JbpmException 
 28  
  */
 29  0
 public class ValidateMessageType extends IntegrationActionHandler
 30  
 {
 31  
 
 32  
     private static final long serialVersionUID = 1L;
 33  
 
 34  
     protected String expectedType;
 35  0
     protected boolean strict = false;
 36  
 
 37  
     public void execute(ExecutionContext executionContext) throws Exception
 38  
     {
 39  0
         super.execute(executionContext);
 40  0
         Object message = getIncomingMessage();
 41  0
         if (message == null)
 42  
         {
 43  0
             throw new JbpmException("Incoming message is null.");
 44  
         }
 45  
 
 46  0
         Class expectedClass = ClassUtils.loadClass(expectedType, this.getClass());
 47  
         boolean match;
 48  0
         if (strict)
 49  
         {
 50  0
             match = message.getClass().equals(expectedClass);
 51  
         }
 52  
         else
 53  
         {
 54  0
             match = expectedClass.isAssignableFrom(message.getClass());
 55  
         }
 56  0
         if (match == false)
 57  
         {
 58  0
             throw new JbpmException("Incoming message type is " + message.getClass() + ", expected type is "
 59  
                             + expectedType);
 60  
         }
 61  0
     }
 62  
 }