KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ObjectToRemoteInvocationResultTransformer.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.ObjectOutputStream JavaDoc;
14
15 import org.apache.commons.io.output.ByteArrayOutputStream;
16 import org.mule.transformers.AbstractTransformer;
17 import org.mule.umo.transformer.TransformerException;
18 import org.springframework.remoting.support.RemoteInvocationResult;
19
20 public class ObjectToRemoteInvocationResultTransformer extends AbstractTransformer
21 {
22     private static final long serialVersionUID = -7067819657247418549L;
23
24     public ObjectToRemoteInvocationResultTransformer()
25     {
26         super();
27         setReturnClass(byte[].class);
28     }
29
30     protected Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
31     {
32         try
33         {
34             if (logger.isDebugEnabled())
35             {
36                 logger.debug("ObjectToRemoteInvocationResult.doTransform(" + src + ")");
37             }
38
39             RemoteInvocationResult rval;
40
41             if (src instanceof RemoteInvocationResult)
42             {
43                 rval = (RemoteInvocationResult)src;
44             }
45             else
46             {
47                 rval = new RemoteInvocationResult(src);
48             }
49
50             ByteArrayOutputStream baos = new ByteArrayOutputStream();
51             ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
52             oos.writeObject(rval);
53             oos.close();
54             return baos.toByteArray();
55         }
56         catch (Exception JavaDoc e)
57         {
58             throw new TransformerException(this, e);
59         }
60     }
61 }
62
Popular Tags