PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 156 lines | 97 code | 22 blank | 37 comment | 5 complexity | 9884839557ed74d195dd49671df3ce23 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;
 26
 27import org.mobicents.protocols.smpp.util.PacketDecoder;
 28import org.mobicents.protocols.smpp.util.PacketEncoder;
 29import org.mobicents.protocols.smpp.util.SMPPDate;
 30import org.mobicents.protocols.smpp.version.SMPPVersion;
 31
 32/**
 33 * SMSC response to a QuerySM request. Contains the current state of a short
 34 * message at the SMSC.
 35 * 
 36 * @version $Id: QuerySMResp.java 457 2009-01-15 17:37:42Z orank $
 37 */
 38public class QuerySMResp extends SMPPPacket {
 39    private static final long serialVersionUID = 2L;
 40    
 41    private String messageId;
 42    private SMPPDate finalDate;
 43    private MessageState messageState = MessageState.UNKNOWN;
 44    private int errorCode;
 45    
 46    /**
 47     * Construct a new QuerySMResp.
 48     */
 49    public QuerySMResp() {
 50        super(CommandId.QUERY_SM_RESP);
 51    }
 52
 53    /**
 54     * Create a new QuerySMResp packet in response to a BindReceiver. This
 55     * constructor will set the sequence number to it's expected value.
 56     * 
 57     * @param request
 58     *            The Request packet the response is to
 59     */
 60    public QuerySMResp(SMPPPacket request) {
 61        super(request);
 62    }
 63    
 64    public int getErrorCode() {
 65        return errorCode;
 66    }
 67
 68    public void setErrorCode(int errorCode) {
 69        this.errorCode = errorCode;
 70    }
 71
 72    public SMPPDate getFinalDate() {
 73        return finalDate;
 74    }
 75
 76    public void setFinalDate(SMPPDate finalDate) {
 77        this.finalDate = finalDate;
 78    }
 79
 80    public String getMessageId() {
 81        return messageId;
 82    }
 83
 84    public void setMessageId(String messageId) {
 85        this.messageId = messageId;
 86    }
 87
 88    public MessageState getMessageState() {
 89        return messageState;
 90    }
 91
 92    public void setMessageState(MessageState messageState) {
 93        this.messageState = messageState;
 94    }
 95
 96    @Override
 97    public boolean equals(Object obj) {
 98        boolean equals = super.equals(obj);
 99        if (equals) {
100            QuerySMResp other = (QuerySMResp) obj;
101            equals |= safeCompare(messageId, other.messageId);
102            equals |= safeCompare(finalDate, other.finalDate);
103            equals |= messageState == other.messageState;
104            equals |= errorCode == other.errorCode;
105        }
106        return equals;
107    }
108    
109    @Override
110    public int hashCode() {
111        int hc = super.hashCode();
112        hc += (messageId != null) ? messageId.hashCode() : 0;
113        hc += (finalDate != null) ? finalDate.hashCode() : 0;
114        hc += Integer.valueOf(messageState.getValue()).hashCode();
115        hc += Integer.valueOf(errorCode).hashCode();
116        return hc;
117    }
118
119    @Override
120    protected void toString(StringBuilder buffer) {
121        buffer.append("messageId=").append(messageId)
122        .append(",finalDate=").append(finalDate)
123        .append(",messageState=").append(messageState)
124        .append(",errorCode=").append(errorCode);
125    }
126
127    @Override
128    protected void validateMandatory(SMPPVersion smppVersion) {
129        smppVersion.validateMessageId(messageId);
130        smppVersion.validateErrorCode(errorCode);
131    }
132    
133    @Override
134    protected void readMandatory(PacketDecoder decoder) {
135        messageId = decoder.readCString();
136        finalDate = decoder.readDate();
137        messageState = MessageState.getMessageState(decoder.readUInt1());
138        errorCode = decoder.readUInt1();
139    }
140
141    @Override
142    protected void writeMandatory(PacketEncoder encoder) throws IOException {
143        encoder.writeCString(messageId);
144        encoder.writeDate(finalDate);
145        encoder.writeUInt1(messageState.getValue());
146        encoder.writeUInt1(errorCode);
147    }
148    
149    @Override
150    protected int getMandatorySize() {
151        int length = 3;
152        length += sizeOf(messageId);
153        length += sizeOf(finalDate);
154        return length;
155    }
156}