1 24 25 package org.objectweb.dream.message; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import org.objectweb.dream.util.MultipleIterator; 32 33 36 public class ExtensibleMessageNCImpl extends ExtensibleMessageImpl 37 implements 38 ExtensibleMessageNC, 39 MessageTypeNC 40 { 41 42 Map subMessageMap = new HashMap (); 43 Message[] allSubMessagesArray = null; 44 MessageType[] allSubMessageTypesArray = null; 45 46 50 53 public ExtensibleMessageNCImpl() 54 { 55 } 56 57 63 public ExtensibleMessageNCImpl(short messageManagerId) 64 { 65 super(messageManagerId); 66 } 67 68 72 75 public Message getSubMessage(String name) 76 { 77 return (Message) subMessageMap.get(name); 78 } 79 80 83 public String [] getSubMessageNames() 84 { 85 return (String []) subMessageMap.keySet().toArray(EMPTY_STRING_ARRAY); 86 } 87 88 91 public Iterator getSubMessageNamesIterator() 92 { 93 return subMessageMap.keySet().iterator(); 94 } 95 96 100 public void addSubMessage(String name, Message message) 101 throws MessageAlreadyExistException 102 { 103 subMessageMap.put(name, message); 104 subMessagesArray = null; 105 subMessageTypesArray = null; 106 allSubMessagesArray = null; 107 allSubMessageTypesArray = null; 108 } 109 110 113 public Message removeSubMessage(String name) 114 { 115 Message removed = (Message) subMessageMap.remove(name); 116 if (removed != null) 117 { 118 subMessagesArray = null; 119 subMessageTypesArray = null; 120 allSubMessagesArray = null; 121 allSubMessageTypesArray = null; 122 } 123 return removed; 124 } 125 126 129 public Iterator getUnnamedSubMessageIterator() 130 { 131 return super.getSubMessageIterator(); 132 } 133 134 137 public Message[] getUnnamedSubMessages() 138 { 139 return super.getSubMessages(); 140 } 141 142 146 149 public MessageType getSubMessageType(String name) 150 { 151 Message msg = getSubMessage(name); 152 if (msg == null) 153 { 154 return null; 155 } 156 return msg.getMessageType(); 157 } 158 159 162 public MessageType[] getUnnamedSubMessageTypes() 163 { 164 return super.getSubMessageTypes(); 165 } 166 167 170 public Iterator getUnnamedSubMessageTypesIterator() 171 { 172 return super.getSubMessageTypesIterator(); 173 } 174 175 179 182 public Iterator getSubMessageIterator() 183 { 184 return new MultipleIterator(new Iterator []{ 185 subMessageMap.values().iterator(), super.getSubMessageIterator()}); 186 } 187 188 191 public Message[] getSubMessages() 192 { 193 if (allSubMessagesArray == null) 194 { 195 if (subMessages.isEmpty() && subMessageMap.isEmpty()) 196 { 197 allSubMessagesArray = EMPTY_MESSAGE_ARRAY; 198 } 199 else 200 { 201 allSubMessagesArray = new Message[subMessages.size() 202 + subMessageMap.size()]; 203 subMessages.toArray(allSubMessagesArray); 204 Iterator iter = subMessageMap.values().iterator(); 205 int i = subMessages.size(); 206 while (iter.hasNext()) 207 { 208 allSubMessagesArray[i] = (Message) iter.next(); 209 i++; 210 } 211 } 212 } 213 return allSubMessagesArray; 214 } 215 216 219 public MessageType[] getSubMessageTypes() 220 { 221 if (allSubMessageTypesArray == null) 222 { 223 if (subMessages.isEmpty() && subMessageMap.isEmpty()) 224 { 225 allSubMessageTypesArray = EMPTY_MESSAGE_TYPE_ARRAY; 226 } 227 else 228 { 229 allSubMessageTypesArray = new MessageType[subMessages.size()]; 230 Iterator iter = getSubMessageIterator(); 231 int i = 0; 232 while (iter.hasNext()) 233 { 234 Message message = (Message) iter.next(); 235 allSubMessageTypesArray[i] = message.getMessageType(); 236 i++; 237 } 238 } 239 } 240 return allSubMessageTypesArray; 241 } 242 243 246 public void recycle() 247 { 248 super.recycle(); 249 if (!subMessageMap.isEmpty()) 250 { 251 subMessageMap.clear(); 252 } 253 allSubMessagesArray = null; 254 allSubMessageTypesArray = null; 255 } 256 257 } | Popular Tags |