KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > extras > spring > remoting > ObjectToRemoteInvocationTransformer


1 /*
2  * $Id: ObjectToRemoteInvocationTransformer.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.extras.spring.remoting;
12
13 import java.io.ByteArrayInputStream JavaDoc;
14 import java.io.ObjectInputStream JavaDoc;
15
16 import org.mule.transformers.AbstractTransformer;
17 import org.mule.umo.transformer.TransformerException;
18 import org.springframework.remoting.support.RemoteInvocation;
19
20 public class ObjectToRemoteInvocationTransformer extends AbstractTransformer
21 {
22     private static final long serialVersionUID = -7067819657247418549L;
23
24     public ObjectToRemoteInvocationTransformer()
25     {
26         super();
27         this.registerSourceType(RemoteInvocation.class);
28         this.registerSourceType(byte[].class);
29         this.setReturnClass(RemoteInvocation.class);
30     }
31
32     protected Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
33     {
34         if (logger.isDebugEnabled())
35         {
36             logger.debug("HttpToRemoteInvocation.doTransform(" + src + ")");
37         }
38         if (src instanceof RemoteInvocation)
39         {
40             return src;
41         }
42
43         try
44         {
45             byte[] data = (byte[])src;
46             ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(data);
47             ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
48             Object JavaDoc o = ois.readObject();
49             RemoteInvocation ri = (RemoteInvocation)o;
50             if (logger.isDebugEnabled())
51             {
52                 logger.debug("request to execute " + ri.getMethodName());
53                 for (int i = 0; i < ri.getArguments().length; i++)
54                 {
55                     Object JavaDoc a = ri.getArguments()[i];
56                     logger.debug("with argument (" + a.toString() + ")");
57                 }
58             }
59             return ri;
60         }
61         catch (Exception JavaDoc e)
62         {
63             throw new TransformerException(this, e);
64         }
65     }
66 }
67
Popular Tags