Coverage Report - org.mule.expression.transformers.AbstractExpressionTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractExpressionTransformer
0%
0/23
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: AbstractExpressionTransformer.java 19250 2010-08-30 16:53:14Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  
 package org.mule.expression.transformers;
 11  
 
 12  
 import org.mule.api.lifecycle.InitialisationException;
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.transformer.AbstractMessageTransformer;
 15  
 import org.mule.transformer.types.DataTypeFactory;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.Iterator;
 19  
 import java.util.List;
 20  
 
 21  
 /**
 22  
  * This transformer will evaluate one or more expressions on the current message and return the
 23  
  * results as an Array. If only one expression is defined it will return the object returned from
 24  
  * the expression.
 25  
  * <p/>
 26  
  * You can use expressions to extract
 27  
  * <ul>
 28  
  * <li>headers (single, map or list)</li>
 29  
  * <li>attachments (single, map or list)</li>
 30  
  * <li>payload</li>
 31  
  * <li>xpath</li>
 32  
  * <li>groovy</li>
 33  
  * <li>bean</li>
 34  
  * </ul>
 35  
  * and more.
 36  
  * <p/>
 37  
  * This transformer provides a very powerful way to pull different bits of information from the
 38  
  * message and pass them to the service.
 39  
  */
 40  
 public abstract class AbstractExpressionTransformer extends AbstractMessageTransformer
 41  
 {
 42  
     protected List<ExpressionArgument> arguments;
 43  
 
 44  
     public AbstractExpressionTransformer()
 45  0
     {
 46  
         //No type checking by default
 47  0
         registerSourceType(DataTypeFactory.OBJECT);
 48  0
         setReturnDataType(DataTypeFactory.OBJECT);
 49  0
         arguments = new ArrayList<ExpressionArgument>(4);
 50  0
     }
 51  
 
 52  
     public void addArgument(ExpressionArgument argument)
 53  
     {
 54  0
         arguments.add(argument);
 55  0
     }
 56  
 
 57  
     public boolean removeArgument(ExpressionArgument argument)
 58  
     {
 59  0
         return arguments.remove(argument);
 60  
     }
 61  
 
 62  
     /**
 63  
      * Template method were deriving classes can do any initialisation after the
 64  
      * properties have been set on this transformer
 65  
      *
 66  
      * @throws org.mule.api.lifecycle.InitialisationException
 67  
      *
 68  
      */
 69  
     @Override
 70  
     public void initialise() throws InitialisationException
 71  
     {
 72  0
         if (arguments == null || arguments.size() == 0)
 73  
         {
 74  0
             throw new InitialisationException(CoreMessages.objectIsNull("arguments[]"), this);
 75  
         }
 76  
 
 77  0
         for (Iterator<ExpressionArgument> iterator = arguments.iterator(); iterator.hasNext();)
 78  
         {
 79  0
             ExpressionArgument argument = iterator.next();
 80  0
             argument.setMuleContext(muleContext);
 81  0
             argument.setExpressionEvaluationClassLoader(Thread.currentThread().getContextClassLoader());
 82  
             try
 83  
             {
 84  0
                 argument.validate();
 85  
             }
 86  0
             catch (Exception e)
 87  
             {
 88  0
                 throw new InitialisationException(e, this);
 89  0
             }
 90  0
         }
 91  0
     }
 92  
 
 93  
     public List<ExpressionArgument> getArguments()
 94  
     {
 95  0
         return arguments;
 96  
     }
 97  
 
 98  
     public void setArguments(List<ExpressionArgument> arguments)
 99  
     {
 100  0
         this.arguments = arguments;
 101  0
     }
 102  
 }