KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > transformers > simple > ByteArrayToSerializable


1 /*
2  * $Id: ByteArrayToSerializable.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.transformers.simple;
12
13 import org.apache.commons.lang.SerializationUtils;
14 import org.mule.config.i18n.Message;
15 import org.mule.config.i18n.Messages;
16 import org.mule.transformers.AbstractTransformer;
17 import org.mule.umo.transformer.TransformerException;
18
19 import java.io.InputStream JavaDoc;
20
21 /**
22  * <code>ByteArrayToSerializable</code> converts a serialized object to its object
23  * representation
24  */

25 public class ByteArrayToSerializable extends AbstractTransformer
26 {
27     /**
28      * Serial version
29      */

30     private static final long serialVersionUID = 5305641786345530597L;
31
32     public ByteArrayToSerializable()
33     {
34         registerSourceType(byte[].class);
35         registerSourceType(InputStream JavaDoc.class);
36     }
37
38     public Object JavaDoc doTransform(Object JavaDoc src, String JavaDoc encoding) throws TransformerException
39     {
40         try
41         {
42             if (src instanceof byte[])
43             {
44                 return SerializationUtils.deserialize((byte[])src);
45             }
46             else
47             {
48                 return SerializationUtils.deserialize((InputStream JavaDoc)src);
49
50             }
51         }
52         catch (Exception JavaDoc e)
53         {
54             throw new TransformerException(new Message(Messages.TRANSFORM_FAILED_FROM_X_TO_X, "byte[]",
55                 "Object"), this, e);
56         }
57     }
58
59 }
60
Popular Tags