PageRenderTime 50ms CodeModel.GetById 23ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/message/QueryMsgDetailsResp.java

http://mobicents.googlecode.com/
Java | 369 lines | 266 code | 44 blank | 59 comment | 19 complexity | b7130e0f83cea3be9247986ce78cefb8 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 * Response to Query message details. Gives all details of a specified message
 37 * at the SMSC.
 38 * 
 39 * @version $Id: QueryMsgDetailsResp.java 457 2009-01-15 17:37:42Z orank $
 40 */
 41public class QueryMsgDetailsResp extends SMPPPacket {
 42    private static final long serialVersionUID = 2L;
 43    
 44    private String serviceType;
 45    private Address source;
 46    private DestinationTable destinationTable = new DestinationTable();
 47    private int protocolID;
 48    private int priority;
 49    private SMPPDate deliveryTime;
 50    private SMPPDate expiryTime;
 51    private int registered;
 52    private int dataCoding;
 53    private byte[] message;
 54    private String messageId;
 55    private SMPPDate finalDate;
 56    private MessageState messageStatus = MessageState.UNKNOWN;
 57    private int errorCode;
 58
 59    /**
 60     * Construct a new QueryMsgDetailsResp.
 61     */
 62    public QueryMsgDetailsResp() {
 63        super(CommandId.QUERY_MSG_DETAILS_RESP);
 64    }
 65
 66    /**
 67     * Create a new QueryMsgDetailsResp packet in response to a BindReceiver.
 68     * This constructor will set the sequence number to it's expected value.
 69     * 
 70     * @param request
 71     *            The Request packet the response is to
 72     */
 73    public QueryMsgDetailsResp(SMPPPacket request) {
 74        super(request);
 75    }
 76    
 77    public int getDataCoding() {
 78        return dataCoding;
 79    }
 80
 81    public void setDataCoding(int dataCoding) {
 82        this.dataCoding = dataCoding;
 83    }
 84
 85    public SMPPDate getDeliveryTime() {
 86        return deliveryTime;
 87    }
 88
 89    public void setDeliveryTime(SMPPDate deliveryTime) {
 90        this.deliveryTime = deliveryTime;
 91    }
 92
 93    public int getErrorCode() {
 94        return errorCode;
 95    }
 96
 97    public void setErrorCode(int errorCode) {
 98        this.errorCode = errorCode;
 99    }
100
101    public SMPPDate getExpiryTime() {
102        return expiryTime;
103    }
104
105    public void setExpiryTime(SMPPDate expiryTime) {
106        this.expiryTime = expiryTime;
107    }
108
109    public SMPPDate getFinalDate() {
110        return finalDate;
111    }
112
113    public void setFinalDate(SMPPDate finalDate) {
114        this.finalDate = finalDate;
115    }
116
117    public byte[] getMessage() {
118        return message;
119    }
120
121    public void setMessage(byte[] message) {
122        this.message = message;
123    }
124
125    public String getMessageId() {
126        return messageId;
127    }
128
129    public void setMessageId(String messageId) {
130        this.messageId = messageId;
131    }
132
133    public MessageState getMessageStatus() {
134        return messageStatus;
135    }
136
137    public void setMessageStatus(MessageState messageStatus) {
138        this.messageStatus = messageStatus;
139    }
140
141    public int getPriority() {
142        return priority;
143    }
144
145    public void setPriority(int priority) {
146        this.priority = priority;
147    }
148
149    public int getProtocolID() {
150        return protocolID;
151    }
152
153    public void setProtocolID(int protocolID) {
154        this.protocolID = protocolID;
155    }
156
157    public int getRegistered() {
158        return registered;
159    }
160
161    public void setRegistered(int registered) {
162        this.registered = registered;
163    }
164
165    public String getServiceType() {
166        return serviceType;
167    }
168
169    public void setServiceType(String serviceType) {
170        this.serviceType = serviceType;
171    }
172
173    public Address getSource() {
174        return source;
175    }
176
177    public void setSource(Address source) {
178        this.source = source;
179    }
180
181    /**
182     * Add an address to the destination table.
183     * 
184     * @param address
185     *            The SME destination address
186     * @return The current number of destination addresses (including the new
187     *         one).
188     * @see Address
189     */
190    public int addDestination(Address address) {
191        synchronized (destinationTable) {
192            destinationTable.add(address);
193            return destinationTable.size();
194        }
195    }
196
197    /**
198     * Add a distribution list to the destination table.
199     * 
200     * @param distributionList
201     *            the distribution list name.
202     * @return The current number of destination addresses (including the new
203     */
204    public int addDestination(String distributionList) {
205        synchronized (destinationTable) {
206            destinationTable.add(distributionList);
207            return destinationTable.size();
208        }
209    }
210
211    /**
212     * Get the current number of destination addresses.
213     */
214    public int getNumDests() {
215        return destinationTable.size();
216    }
217
218    /**
219     * Get a handle to the destination table.
220     */
221    public DestinationTable getDestinationTable() {
222        return destinationTable;
223    }
224
225    @Override
226    public boolean equals(Object obj) {
227        boolean equals = super.equals(obj);
228        if (equals) {
229            QueryMsgDetailsResp other = (QueryMsgDetailsResp) obj;
230            equals |= safeCompare(serviceType, other.serviceType);
231            equals |= safeCompare(source, other.source);
232            equals |= safeCompare(destinationTable, other.destinationTable);
233            equals |= protocolID == other.protocolID;
234            equals |= priority == other.priority;
235            equals |= safeCompare(deliveryTime, other.deliveryTime);
236            equals |= safeCompare(expiryTime, other.expiryTime);
237            equals |= registered == other.registered;
238            equals |= dataCoding == other.dataCoding;
239            equals |= Arrays.equals(message, other.message);
240            equals |= messageId == other.messageId;
241            equals |= safeCompare(finalDate, other.finalDate);
242            equals |= messageStatus == other.messageStatus;
243            equals |= errorCode == other.errorCode;
244        }
245        return equals;
246    }
247    
248    @Override
249    public int hashCode() {
250        int hc = super.hashCode();
251        hc += (serviceType != null) ? serviceType.hashCode() : 0;
252        hc += (source != null) ? source.hashCode() : 0;
253        hc += (destinationTable != null) ? destinationTable.hashCode() : 13;
254        hc += Integer.valueOf(protocolID).hashCode();
255        hc += Integer.valueOf(priority).hashCode();
256        hc += (deliveryTime != null) ? deliveryTime.hashCode() : 0;
257        hc += (expiryTime != null) ? expiryTime.hashCode() : 0;
258        hc += Integer.valueOf(registered).hashCode();
259        hc += Integer.valueOf(dataCoding).hashCode();
260        if (message != null) {
261            try {
262                hc += new String(message, "US-ASCII").hashCode();
263            } catch (UnsupportedEncodingException x) {
264                throw new RuntimeException(x);
265            }
266        }
267        hc += Integer.valueOf(messageId).hashCode();
268        hc += (finalDate != null) ? finalDate.hashCode() : 0;
269        hc += Integer.valueOf(messageStatus.getValue()).hashCode();
270        hc += Integer.valueOf(errorCode).hashCode();
271        return hc;
272    }
273
274    @Override
275    protected void toString(StringBuilder buffer) {
276        buffer.append("serviceType=").append(serviceType)
277        .append(",source=").append(source)
278        .append(",numberOfDests=").append(destinationTable.size())
279        .append(",destinations=").append(destinationTable)
280        .append(",protocolID=").append(protocolID)
281        .append(",priority=").append(priority)
282        .append(",deliveryTime=").append(deliveryTime)
283        .append(",expiryTime=").append(expiryTime)
284        .append(",registered=").append(registered)
285        .append(",dataCoding=").append(dataCoding)
286        .append(",smLength=").append(sizeOf(message))
287        .append(",message=").append(message)
288        .append(",messageId=").append(messageId)
289        .append(",finalDate=").append(finalDate)
290        .append(",messageStatus=").append(messageStatus)
291        .append(",errorCode=").append(errorCode);
292    }
293
294    @Override
295    protected void validateMandatory(SMPPVersion smppVersion) {
296        smppVersion.validateServiceType(serviceType);
297        smppVersion.validateAddress(source);
298        smppVersion.validateNumberOfDests(destinationTable.size());
299        for (Address address : destinationTable.getAddresses()) {
300            smppVersion.validateAddress(address);
301        }
302        for (String distList : destinationTable.getDistributionLists()) {
303            smppVersion.validateDistListName(distList);
304        }
305        smppVersion.validateProtocolID(protocolID);
306        smppVersion.validatePriorityFlag(priority);
307        smppVersion.validateRegisteredDelivery(registered);
308        smppVersion.validateDataCoding(dataCoding);
309        smppVersion.validateMessage(message, 0, sizeOf(message));
310        smppVersion.validateMessageId(messageId);
311        smppVersion.validateErrorCode(errorCode);
312    }
313
314    @Override
315    protected void readMandatory(PacketDecoder decoder) {
316        serviceType = decoder.readCString();
317        source = decoder.readAddress();
318        int tableSize = decoder.readUInt1();
319        destinationTable = new DestinationTable();
320        destinationTable.readFrom(decoder, tableSize);
321        protocolID = decoder.readUInt1();
322        priority = decoder.readUInt1();
323        deliveryTime = decoder.readDate();
324        expiryTime = decoder.readDate();
325        registered = decoder.readUInt1();
326        dataCoding = decoder.readUInt1();
327        int messageLen = decoder.readUInt1();
328        message = decoder.readBytes(messageLen);
329        messageId = decoder.readCString();
330        finalDate = decoder.readDate();
331        messageStatus = MessageState.getMessageState(decoder.readUInt1());
332        errorCode = decoder.readUInt1();
333    }
334    
335    @Override
336    protected void writeMandatory(PacketEncoder encoder) throws IOException {
337        encoder.writeCString(serviceType);
338        encoder.writeAddress(source);
339        encoder.writeUInt1(destinationTable.size());
340        destinationTable.writeTo(encoder);
341        encoder.writeUInt1(protocolID);
342        encoder.writeUInt1(priority);
343        encoder.writeDate(deliveryTime);
344        encoder.writeDate(expiryTime);
345        encoder.writeUInt1(registered);
346        encoder.writeUInt1(dataCoding);
347        int messageLen = (message != null) ? message.length : 0;
348        encoder.writeUInt1(messageLen);
349        encoder.writeBytes(message, 0, messageLen);
350        encoder.writeCString(messageId);
351        encoder.writeDate(finalDate);
352        encoder.writeUInt1(messageStatus.getValue());
353        encoder.writeUInt1(errorCode);
354    }
355    
356    @Override
357    protected int getMandatorySize() {
358        int length = 10;
359        length += sizeOf(serviceType);
360        length += sizeOf(source);
361        length += destinationTable.getLength();
362        length += sizeOf(deliveryTime);
363        length += sizeOf(expiryTime);
364        length += sizeOf(message);
365        length += sizeOf(messageId);
366        length += sizeOf(finalDate);
367        return length;
368    }
369}