1 10 11 package org.mule.providers.gs; 12 13 import net.jini.core.entry.Entry; 14 15 import org.apache.commons.lang.StringUtils; 16 import org.mule.MuleManager; 17 import org.mule.providers.AbstractMessageAdapter; 18 import org.mule.umo.MessagingException; 19 import org.mule.umo.provider.MessageTypeNotSupportedException; 20 import org.mule.util.UUID; 21 22 27 28 public class JiniMessageAdapter extends AbstractMessageAdapter 29 { 30 33 private static final long serialVersionUID = 3480872474322069206L; 34 35 protected final Entry message; 36 protected final String id; 37 38 public JiniMessageAdapter(Object message) throws MessagingException 39 { 40 if (message == null) 41 { 42 throw new MessageTypeNotSupportedException(message, getClass()); 43 } 44 45 if (message instanceof Entry) 46 { 47 this.message = (Entry)message; 48 } 49 else 50 { 51 this.message = new JiniMessage(null, message); 52 } 53 54 if (this.message instanceof JiniMessage) 55 { 56 JiniMessage jm = (JiniMessage)this.message; 57 58 String msgId = jm.getMessageId(); 60 if (msgId == null) 61 { 62 msgId = UUID.getUUID(); 63 } 64 this.id = msgId; 65 66 this.setCorrelationId(jm.getCorrelationId()); 68 69 Integer value = jm.getCorrelationGroupSize(); 71 this.setCorrelationGroupSize(value != null ? value.intValue() : -1); 72 73 value = jm.getCorrelationSequence(); 75 this.setCorrelationSequence(value != null ? value.intValue() : -1); 76 77 this.setReplyTo(jm.getReplyTo()); 79 80 this.setEncoding(StringUtils.defaultIfEmpty(jm.getEncoding(), MuleManager.getConfiguration() 82 .getEncoding())); 83 84 this.setExceptionPayload(jm.getExceptionPayload()); 86 87 this.addProperties(jm.getProperties()); 89 } 90 else 91 { 92 id = UUID.getUUID(); 93 } 94 } 95 96 104 public String getPayloadAsString(String encoding) throws Exception 105 { 106 if (message instanceof JiniMessage) 107 { 108 Object payload = ((JiniMessage)message).getPayload(); 109 if (payload != null) 110 { 111 return payload.toString(); 112 } 113 else 114 { 115 return null; 116 } 117 } 118 else 119 { 120 return message.toString(); 121 } 122 } 123 124 public byte[] getPayloadAsBytes() throws Exception 125 { 126 Object payload = message; 127 if (message instanceof JiniMessage) 128 { 129 payload = ((JiniMessage)message).getPayload(); 130 } 131 132 return convertToBytes(payload); 133 } 134 135 public Object getPayload() 136 { 137 if (message instanceof JiniMessage) 138 { 139 return ((JiniMessage)message).getPayload(); 140 } 141 else 142 { 143 return message; 144 } 145 } 146 147 public String getUniqueId() 148 { 149 return id; 150 } 151 } 152 | Popular Tags |