1 10 11 package org.mule.providers.gs; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 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 pojo, UMOMessage msg) 29 { 30 if (pojo instanceof Entry) 31 { 32 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 [] fieldNames = new String [newFieldCount]; 41 String [] fieldTypes = new String [newFieldCount]; 42 Object [] fieldValues = new Object [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 (msg.getCorrelationSequence()); 71 fieldValues[fieldCount + 2] = new Integer (msg.getCorrelationGroupSize()); 72 fieldValues[fieldCount + 3] = msg.getReplyTo(); 73 fieldValues[fieldCount + 4] = msg.getUniqueId(); 74 75 Map props = new HashMap (); 76 for (Iterator propNames = msg.getPropertyNames().iterator(); propNames.hasNext();) 77 { 78 String propName = (String )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 toPojo(Entry entry) 101 { 102 return converter.toPojo(entry); 103 } 104 105 } 106 | Popular Tags |