/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/message/SubmitMulti.java
Java | 340 lines | 246 code | 41 blank | 53 comment | 20 complexity | 49d3d7ba3e16fa4e663b7bd01537438d MD5 | raw file
1/* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2011, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23package org.mobicents.protocols.smpp.message; 24 25import java.io.IOException; 26import java.io.UnsupportedEncodingException; 27import java.util.Arrays; 28 29import org.mobicents.protocols.smpp.Address; 30import org.mobicents.protocols.smpp.util.PacketDecoder; 31import org.mobicents.protocols.smpp.util.PacketEncoder; 32import org.mobicents.protocols.smpp.util.SMPPDate; 33import org.mobicents.protocols.smpp.version.SMPPVersion; 34 35/** 36 * Submit a message to multiple destinations. 37 * 38 * @version $Id: SubmitMulti.java 457 2009-01-15 17:37:42Z orank $ 39 */ 40public class SubmitMulti extends SMPPPacket { 41 private static final long serialVersionUID = 2L; 42 43 private String serviceType; 44 private Address source; 45 private DestinationTable destinationTable = new DestinationTable(); 46 private int esmClass; 47 private int protocolID; 48 private int priority; 49 private SMPPDate deliveryTime; 50 private SMPPDate expiryTime; 51 private int registered; 52 private int replaceIfPresent; 53 private int dataCoding; 54 private int defaultMsg; 55 private byte[] message; 56 57 /** 58 * Construct a new SubmitMulti. 59 */ 60 public SubmitMulti() { 61 super(CommandId.SUBMIT_MULTI); 62 } 63 64 /** 65 * Get a handle to the error destination table. Applications may add 66 * destination addresses or distribution list names to the destination 67 * table. 68 */ 69 public DestinationTable getDestinationTable() { 70 return destinationTable; 71 } 72 73 public int getDataCoding() { 74 return dataCoding; 75 } 76 77 public void setDataCoding(int dataCoding) { 78 this.dataCoding = dataCoding; 79 } 80 81 public int getDefaultMsg() { 82 return defaultMsg; 83 } 84 85 public void setDefaultMsg(int defaultMsg) { 86 this.defaultMsg = defaultMsg; 87 } 88 89 public SMPPDate getDeliveryTime() { 90 return deliveryTime; 91 } 92 93 public void setDeliveryTime(SMPPDate deliveryTime) { 94 this.deliveryTime = deliveryTime; 95 } 96 97 public int getEsmClass() { 98 return esmClass; 99 } 100 101 public void setEsmClass(int esmClass) { 102 this.esmClass = esmClass; 103 } 104 105 public SMPPDate getExpiryTime() { 106 return expiryTime; 107 } 108 109 public void setExpiryTime(SMPPDate expiryTime) { 110 this.expiryTime = expiryTime; 111 } 112 113 public byte[] getMessage() { 114 return message; 115 } 116 117 public void setMessage(byte[] message) { 118 this.message = message; 119 } 120 121 public int getPriority() { 122 return priority; 123 } 124 125 public void setPriority(int priority) { 126 this.priority = priority; 127 } 128 129 public int getProtocolID() { 130 return protocolID; 131 } 132 133 public void setProtocolID(int protocolID) { 134 this.protocolID = protocolID; 135 } 136 137 public int getRegistered() { 138 return registered; 139 } 140 141 public void setRegistered(int registered) { 142 this.registered = registered; 143 } 144 145 public int getReplaceIfPresent() { 146 return replaceIfPresent; 147 } 148 149 public void setReplaceIfPresent(int replaceIfPresent) { 150 this.replaceIfPresent = replaceIfPresent; 151 } 152 153 public String getServiceType() { 154 return serviceType; 155 } 156 157 public void setServiceType(String serviceType) { 158 this.serviceType = serviceType; 159 } 160 161 public Address getSource() { 162 return source; 163 } 164 165 public void setSource(Address source) { 166 this.source = source; 167 } 168 169 /** 170 * Add an address to the destination table. 171 * 172 * @param d 173 * The SME destination address 174 * @return The current number of destination addresses (including the new 175 * one). 176 * @see Address 177 */ 178 public int addDestination(Address d) { 179 synchronized (destinationTable) { 180 destinationTable.add(d); 181 return destinationTable.size(); 182 } 183 } 184 185 /** 186 * Add a distribution list to the destination table. 187 * 188 * @param d 189 * the distribution list name. 190 * @return The current number of destination addresses (including the new 191 */ 192 public int addDestination(String d) { 193 synchronized (destinationTable) { 194 destinationTable.add(d); 195 return destinationTable.size(); 196 } 197 } 198 199 /** 200 * Get the number of destinations in the destination table. 201 */ 202 public int getNumDests() { 203 return destinationTable.size(); 204 } 205 206 @Override 207 public boolean equals(Object obj) { 208 boolean equals = super.equals(obj); 209 if (equals) { 210 SubmitMulti other = (SubmitMulti) obj; 211 equals |= safeCompare(serviceType, other.serviceType); 212 equals |= safeCompare(source, other.source); 213 equals |= safeCompare(destinationTable, other.destinationTable); 214 equals |= esmClass == other.esmClass; 215 equals |= protocolID == other.protocolID; 216 equals |= priority == other.priority; 217 equals |= safeCompare(deliveryTime, other.deliveryTime); 218 equals |= safeCompare(expiryTime, other.expiryTime); 219 equals |= registered == other.registered; 220 equals |= replaceIfPresent == other.replaceIfPresent; 221 equals |= dataCoding == other.dataCoding; 222 equals |= defaultMsg == other.defaultMsg; 223 equals |= Arrays.equals(message, other.message); 224 } 225 return equals; 226 } 227 228 @Override 229 public int hashCode() { 230 int hc = super.hashCode(); 231 hc += (serviceType != null) ? serviceType.hashCode() : 0; 232 hc += (source != null) ? source.hashCode() : 0; 233 hc += (destinationTable != null) ? destinationTable.hashCode() : 0; 234 hc += Integer.valueOf(esmClass).hashCode(); 235 hc += Integer.valueOf(protocolID).hashCode(); 236 hc += Integer.valueOf(priority).hashCode(); 237 hc += (deliveryTime != null) ? deliveryTime.hashCode() : 0; 238 hc += (expiryTime != null) ? expiryTime.hashCode() : 0; 239 hc += Integer.valueOf(registered).hashCode(); 240 hc += Integer.valueOf(replaceIfPresent).hashCode(); 241 hc += Integer.valueOf(dataCoding).hashCode(); 242 hc += Integer.valueOf(defaultMsg).hashCode(); 243 if (message != null) { 244 try { 245 hc += new String(message, "US-ASCII").hashCode(); 246 } catch (UnsupportedEncodingException x) { 247 throw new RuntimeException(x); 248 } 249 } 250 return hc; 251 } 252 253 @Override 254 protected void toString(StringBuilder buffer) { 255 int length = 0; 256 if (message != null) { 257 length = message.length; 258 } 259 buffer.append("serviceType=").append(serviceType) 260 .append(",source=").append(source) 261 .append(",numberOfDests=").append(destinationTable.size()) 262 .append(",destinations=").append(destinationTable) 263 .append(",esmClass=").append(esmClass) 264 .append(",protocolID=").append(protocolID) 265 .append(",priority=").append(priority) 266 .append(",deliveryTime=").append(deliveryTime) 267 .append(",expiryTime=").append(expiryTime) 268 .append(",registered=").append(registered) 269 .append(",replaceIfPresent=").append(replaceIfPresent) 270 .append(",dataCoding=").append(dataCoding) 271 .append(",defaultMsg=").append(defaultMsg) 272 .append(",smLength=").append(length) 273 .append(",message=").append(message); 274 } 275 276 @Override 277 protected void validateMandatory(SMPPVersion smppVersion) { 278 super.validateMandatory(smppVersion); 279 smppVersion.validateNumberOfDests(destinationTable.size()); 280 for (Address address : destinationTable.getAddresses()) { 281 smppVersion.validateAddress(address); 282 } 283 for (String distributionList : destinationTable.getDistributionLists()) { 284 smppVersion.validateDistListName(distributionList); 285 } 286 } 287 288 @Override 289 protected void readMandatory(PacketDecoder decoder) { 290 serviceType = decoder.readCString(); 291 source = decoder.readAddress(); 292 int numDests = decoder.readUInt1(); 293 destinationTable = new DestinationTable(); 294 destinationTable.readFrom(decoder, numDests); 295 esmClass = decoder.readUInt1(); 296 protocolID = decoder.readUInt1(); 297 priority = decoder.readUInt1(); 298 deliveryTime = decoder.readDate(); 299 expiryTime = decoder.readDate(); 300 registered = decoder.readUInt1(); 301 replaceIfPresent = decoder.readUInt1(); 302 dataCoding = decoder.readUInt1(); 303 defaultMsg = decoder.readUInt1(); 304 int len = decoder.readUInt1(); 305 message = decoder.readBytes(len); 306 } 307 308 @Override 309 protected void writeMandatory(PacketEncoder encoder) throws IOException { 310 encoder.writeCString(serviceType); 311 encoder.writeAddress(source); 312 int numDests = destinationTable.size(); 313 encoder.writeUInt1(numDests); 314 destinationTable.writeTo(encoder); 315 encoder.writeUInt1(esmClass); 316 encoder.writeUInt1(protocolID); 317 encoder.writeUInt1(priority); 318 encoder.writeDate(deliveryTime); 319 encoder.writeDate(expiryTime); 320 encoder.writeUInt1(registered); 321 encoder.writeUInt1(replaceIfPresent); 322 encoder.writeUInt1(dataCoding); 323 encoder.writeUInt1(defaultMsg); 324 int len = (message != null) ? message.length : 0; 325 encoder.writeUInt1(len); 326 encoder.writeBytes(message, 0, len); 327 } 328 329 @Override 330 protected int getMandatorySize() { 331 int l = 10; 332 l += sizeOf(serviceType); 333 l += sizeOf(source); 334 l += destinationTable.getLength(); 335 l += sizeOf(deliveryTime); 336 l += sizeOf(expiryTime); 337 l += sizeOf(message); 338 return l; 339 } 340}