KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > gs > GigaSpacesEntryConverter


1 /*
2  * $Id: GigaSpacesEntryConverter.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;
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.umo.UMOMessage;
20
21 import com.gigaspaces.converter.pojo.Pojo2ExternalEntryConverter;
22 import com.j_spaces.core.client.ExternalEntry;
23
24 public class GigaSpacesEntryConverter
25 {
26     private final Pojo2ExternalEntryConverter converter = new Pojo2ExternalEntryConverter();
27
28     public Entry toEntry(Object JavaDoc pojo, UMOMessage msg)
29     {
30         if (pojo instanceof Entry)
31         {
32             // nothing to do
33
return (Entry)pojo;
34         }
35
36         ExternalEntry result = (ExternalEntry)converter.toEntry(pojo);
37
38         int fieldCount = result.m_FieldsNames.length;
39         int newFieldCount = fieldCount + 8;
40         String JavaDoc[] fieldNames = new String JavaDoc[newFieldCount];
41         String JavaDoc[] fieldTypes = new String JavaDoc[newFieldCount];
42         Object JavaDoc[] fieldValues = new Object JavaDoc[newFieldCount];
43         boolean[] indexIndicators = new boolean[newFieldCount];
44
45         System.arraycopy(result.m_FieldsNames, 0, fieldNames, 0, fieldCount);
46         fieldNames[fieldCount] = "__correlationId";
47         fieldNames[fieldCount + 1] = "__correlationSequence";
48         fieldNames[fieldCount + 2] = "__correlationGroupSize";
49         fieldNames[fieldCount + 3] = "__replyTo";
50         fieldNames[fieldCount + 4] = "__messageId";
51         fieldNames[fieldCount + 5] = "__properties";
52         fieldNames[fieldCount + 6] = "__encoding";
53         fieldNames[fieldCount + 7] = "__exceptionPayload";
54
55         System.arraycopy(result.m_FieldsTypes, 0, fieldTypes, 0, fieldCount);
56         fieldTypes[fieldCount] = "java.lang.String";
57         fieldTypes[fieldCount + 1] = "java.lang.Integer";
58         fieldTypes[fieldCount + 2] = "java.lang.Integer";
59         fieldTypes[fieldCount + 3] = "java.lang.Object";
60         fieldTypes[fieldCount + 4] = "java.lang.String";
61         fieldTypes[fieldCount + 5] = "java.util.Map";
62         fieldTypes[fieldCount + 6] = "java.lang.String";
63         fieldTypes[fieldCount + 7] = "org.mule.umo.UMOExceptionPayload";
64
65         System.arraycopy(result.m_FieldsValues, 0, fieldValues, 0, fieldCount);
66
67         if (msg != null)
68         {
69             fieldValues[fieldCount] = msg.getCorrelationId();
70             fieldValues[fieldCount + 1] = new Integer JavaDoc(msg.getCorrelationSequence());
71             fieldValues[fieldCount + 2] = new Integer JavaDoc(msg.getCorrelationGroupSize());
72             fieldValues[fieldCount + 3] = msg.getReplyTo();
73             fieldValues[fieldCount + 4] = msg.getUniqueId();
74
75             Map JavaDoc props = new HashMap JavaDoc();
76             for (Iterator JavaDoc propNames = msg.getPropertyNames().iterator(); propNames.hasNext();)
77             {
78                 String JavaDoc propName = (String JavaDoc)propNames.next();
79                 props.put(propName, msg.getProperty(propName));
80             }
81
82             fieldValues[fieldCount + 5] = props;
83             fieldValues[fieldCount + 6] = msg.getEncoding();
84             fieldValues[fieldCount + 7] = msg.getExceptionPayload();
85         }
86
87         if (result.m_IndexIndicators != null)
88         {
89             System.arraycopy(result.m_IndexIndicators, 0, indexIndicators, 0, fieldCount);
90         }
91
92         result.m_FieldsNames = fieldNames;
93         result.m_FieldsTypes = fieldTypes;
94         result.m_FieldsValues = fieldValues;
95         result.m_IndexIndicators = indexIndicators;
96
97         return result;
98     }
99
100     public Object JavaDoc toPojo(Entry entry)
101     {
102         return converter.toPojo(entry);
103     }
104
105 }
106
Popular Tags