KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > gs > transformers > UMOMessageToJavaSpaceEntry


1 /*
2  * $Id: UMOMessageToJavaSpaceEntry.java 3807 2006-11-06 13:13:36Z holger $
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.providers.gs.transformers;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import net.jini.core.entry.Entry;
18
19 import org.mule.providers.gs.JiniMessage;
20 import org.mule.transformers.AbstractEventAwareTransformer;
21 import org.mule.umo.UMOEventContext;
22 import org.mule.umo.UMOMessage;
23 import org.mule.umo.transformer.TransformerException;
24
25 /**
26  * Convers an outbound event ot a JavaSpace entry that can be written to the space.
27  *
28  * @see net.jini.core.entry.Entry
29  */

30 public class UMOMessageToJavaSpaceEntry extends AbstractEventAwareTransformer
31 {
32     /**
33      * Serial version
34      */

35     private static final long serialVersionUID = -6852740125237850362L;
36
37     public UMOMessageToJavaSpaceEntry()
38     {
39         setReturnClass(Entry.class);
40     }
41
42     public Object JavaDoc transform(Object JavaDoc src, String JavaDoc encoding, UMOEventContext context) throws TransformerException
43     {
44         if (src instanceof Entry)
45         {
46             return src;
47         }
48         else
49         {
50             String JavaDoc destination = context.getEndpointURI().toString();
51             UMOMessage muleMessage = context.getMessage();
52
53             JiniMessage msg = new JiniMessage(destination, src);
54             msg.setMessageId(muleMessage.getUniqueId());
55             msg.setCorrelationId(muleMessage.getCorrelationId());
56             msg.setCorrelationGroupSize(new Integer JavaDoc(muleMessage.getCorrelationGroupSize()));
57             msg.setCorrelationSequence(new Integer JavaDoc(muleMessage.getCorrelationSequence()));
58             msg.setReplyTo(muleMessage.getReplyTo());
59             msg.setEncoding(muleMessage.getEncoding());
60             msg.setExceptionPayload(muleMessage.getExceptionPayload());
61
62             Map JavaDoc props = new HashMap JavaDoc();
63             for (Iterator JavaDoc iterator = muleMessage.getPropertyNames().iterator(); iterator.hasNext();)
64             {
65                 String JavaDoc key = (String JavaDoc)iterator.next();
66                 props.put(key, muleMessage.getProperty(key));
67             }
68
69             msg.setProperties(props);
70             return msg;
71         }
72     }
73
74 }
75
Popular Tags