1 22 package org.objectweb.petals.jbi.messaging; 23 24 import java.io.IOException ; 25 import java.io.ObjectInputStream ; 26 import java.io.ObjectOutputStream ; 27 import java.io.Serializable ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 import java.util.Set ; 31 32 import javax.activation.DataHandler ; 33 import javax.jbi.messaging.MessagingException; 34 import javax.jbi.messaging.NormalizedMessage; 35 import javax.security.auth.Subject ; 36 import javax.xml.transform.Source ; 37 38 45 public class NormalizedMessageImpl implements NormalizedMessage, Serializable { 46 47 50 private static final long serialVersionUID = 1L; 51 52 55 protected transient Map <String , DataHandler > attachments; 56 57 60 protected transient Source content; 61 62 65 protected Map <String , Object > properties; 66 67 70 protected Subject subject; 71 72 protected MessageExchangeSerializer messageExchangeSerializer; 73 74 78 public NormalizedMessageImpl() { 79 super(); 80 81 content = null; 82 properties = new HashMap <String , Object >(); 83 attachments = new HashMap <String , DataHandler >(); 84 85 messageExchangeSerializer = MessageExchangeSerializer.instance(); 86 } 87 88 93 94 97 public void addAttachment(String id, DataHandler attachment) 98 throws MessagingException { 99 attachments.put(id, attachment); 100 } 101 102 105 public DataHandler getAttachment(String id) { 106 return (DataHandler ) attachments.get(id); 107 } 108 109 112 public Set getAttachmentNames() { 113 return attachments.keySet(); 114 } 115 116 119 public Source getContent() { 120 return content; 121 } 122 123 126 public Object getProperty(String name) { 127 return properties.get(name); 128 } 129 130 133 public Set getPropertyNames() { 134 return properties.keySet(); 135 } 136 137 140 public Subject getSecuritySubject() { 141 return subject; 142 } 143 144 147 public void removeAttachment(String id) throws MessagingException { 148 Object att = attachments.remove(id); 149 150 if (att == null) { 151 throw new MessagingException(id + " attachment does not exist."); 152 } 153 } 154 155 158 public void setContent(Source content) throws MessagingException { 159 this.content = content; 160 } 161 162 165 public void setProperty(String name, Object value) { 166 if (value == null) { 167 properties.remove(name); 169 170 } else { 171 properties.put(name, value); 173 } 174 } 175 176 179 public void setSecuritySubject(Subject securitySubject) { 180 this.subject = securitySubject; 181 } 182 183 186 protected void readObjectDelegate(ObjectInputStream s) throws IOException { 187 try { 188 s.defaultReadObject(); 189 190 if (s.available() > 0) { 191 attachments = messageExchangeSerializer 192 .deserializeAttachments(s); 193 content = messageExchangeSerializer.deserializeContent(s); 194 } 195 } catch (ClassNotFoundException e) { 196 throw new IOException (e.getClass() + ":" + e.getMessage()); 197 } 198 } 199 200 210 protected void writeObjectDelegate(ObjectOutputStream s) throws IOException { 211 s.defaultWriteObject(); 212 try { 213 messageExchangeSerializer.serializeAttachments(attachments, s); 214 messageExchangeSerializer.serializeContent(content, s); 215 } catch (Exception e) { 216 throw new IOException (e.getMessage()); 217 } 218 } 219 220 226 private void readObject(ObjectInputStream s) throws IOException { 227 readObjectDelegate(s); 228 } 229 230 236 private void writeObject(ObjectOutputStream s) throws IOException { 237 writeObjectDelegate(s); 238 } 239 } 240 | Popular Tags |