Coverage Report - org.mule.module.spring.remoting.ObjectToRemoteInvocationTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectToRemoteInvocationTransformer
50%
14/28
38%
3/8
5.5
 
 1  
 /*
 2  
  * $Id: ObjectToRemoteInvocationTransformer.java 10866 2008-02-18 20:29:34Z dfeist $
 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.module.spring.remoting;
 12  
 
 13  
 import org.mule.api.transformer.TransformerException;
 14  
 import org.mule.transformer.AbstractTransformer;
 15  
 
 16  
 import java.io.ByteArrayInputStream;
 17  
 import java.io.InputStream;
 18  
 import java.io.ObjectInputStream;
 19  
 
 20  
 import org.springframework.remoting.support.RemoteInvocation;
 21  
 
 22  
 public class ObjectToRemoteInvocationTransformer extends AbstractTransformer
 23  
 {
 24  
 
 25  
     public ObjectToRemoteInvocationTransformer()
 26  
     {
 27  4
         super();
 28  4
         this.registerSourceType(RemoteInvocation.class);
 29  4
         this.registerSourceType(byte[].class);
 30  4
         this.registerSourceType(InputStream.class);
 31  4
         this.setReturnClass(RemoteInvocation.class);
 32  4
     }
 33  
 
 34  
     protected Object doTransform(Object src, String encoding) throws TransformerException
 35  
     {
 36  2
         if (src instanceof RemoteInvocation)
 37  
         {
 38  0
             return src;
 39  
         }
 40  
 
 41  2
         Object o = null;
 42  
 
 43  2
         if (src instanceof InputStream)
 44  
         {
 45  
             try
 46  
             {
 47  2
                 o = new ObjectInputStream((InputStream) src).readObject();
 48  
             }
 49  0
             catch (Exception e)
 50  
             {
 51  0
                 throw new TransformerException(this, e);
 52  2
             }
 53  
         }
 54  
         else
 55  
         {
 56  0
             byte[] data = (byte[]) src;
 57  0
             ByteArrayInputStream bais = new ByteArrayInputStream(data);
 58  
             try
 59  
             {
 60  0
                 ObjectInputStream ois = new ObjectInputStream(bais);
 61  0
                 o = ois.readObject();
 62  
             }
 63  0
             catch (Exception e)
 64  
             {
 65  0
                 throw new TransformerException(this, e);
 66  0
             }
 67  
         }
 68  
 
 69  2
         RemoteInvocation ri = (RemoteInvocation) o;
 70  2
         if (logger.isDebugEnabled())
 71  
         {
 72  0
             logger.debug("request to execute " + ri.getMethodName());
 73  0
             for (int i = 0; i < ri.getArguments().length; i++)
 74  
             {
 75  0
                 Object a = ri.getArguments()[i];
 76  0
                 logger.debug("with argument (" + a.toString() + ")");
 77  
             }
 78  
         }
 79  2
         return ri;
 80  
 
 81  
     }
 82  
 
 83  
 }