PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 155 lines | 88 code | 19 blank | 48 comment | 8 complexity | 1cf22cbb42e7a00c94a181158cfea4a7 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.Address;
 28import org.mobicents.protocols.smpp.util.PacketDecoder;
 29import org.mobicents.protocols.smpp.util.PacketEncoder;
 30import org.mobicents.protocols.smpp.version.SMPPVersion;
 31
 32/**
 33 * Query Message details. Get all information about an existing message at the
 34 * SMSC.
 35 * 
 36 * @version $Id: QueryMsgDetails.java 457 2009-01-15 17:37:42Z orank $
 37 */
 38public class QueryMsgDetails extends SMPPPacket {
 39    private static final long serialVersionUID = 2L;
 40    
 41    /**
 42     * Original message ID of the required message.
 43     */
 44    private String messageId;
 45    /**
 46     * Source address of the message.
 47     */
 48    private Address source;
 49    /**
 50     * Length of the message text required.
 51     */
 52    private int smLength;
 53
 54    /**
 55     * Construct a new QueryMsgDetails.
 56     */
 57    public QueryMsgDetails() {
 58        super(CommandId.QUERY_MSG_DETAILS);
 59    }
 60    
 61    public String getMessageId() {
 62        return messageId;
 63    }
 64
 65    public void setMessageId(String messageId) {
 66        this.messageId = messageId;
 67    }
 68
 69    public Address getSource() {
 70        return source;
 71    }
 72
 73    public void setSource(Address source) {
 74        this.source = source;
 75    }
 76
 77    /**
 78     * Set the number of bytes of the original message required. Minimum request
 79     * length is 0, maximum is 160. If the length is outside these bounds, it
 80     * will be set to the min or max.
 81     * 
 82     * @param len
 83     *            The number of bytes required.
 84     */
 85    public void setSmLength(int len) {
 86        if (len < 0) {
 87            smLength = 0;
 88        } else if (len > 160) {
 89            smLength = 160;
 90        } else {
 91            smLength = len;
 92        }
 93    }
 94
 95    /** Get the number of bytes of the original message being requested. */
 96    public int getSmLength() {
 97        return smLength;
 98    }
 99
100    @Override
101    public boolean equals(Object obj) {
102        boolean equals = super.equals(obj);
103        if (equals) {
104            QueryMsgDetails other = (QueryMsgDetails) obj;
105            equals |= safeCompare(messageId, other.messageId);
106            equals |= safeCompare(source, other.source);
107            equals |= smLength == other.smLength;
108        }
109        return equals;
110    }
111    
112    @Override
113    public int hashCode() {
114        int hc = super.hashCode();
115        hc += (messageId != null) ? messageId.hashCode() : 0;
116        hc += (source != null) ? source.hashCode() : 0;
117        hc += Integer.valueOf(smLength).hashCode();
118        return hc;
119    }
120
121    @Override
122    protected void toString(StringBuilder buffer) {
123        buffer.append("messageId=").append(messageId)
124        .append(",source=").append(source)
125        .append(",smLength=").append(smLength);
126    }
127
128    @Override
129    protected void validateMandatory(SMPPVersion smppVersion) {
130        smppVersion.validateMessageId(messageId);
131        smppVersion.validateAddress(source);
132    }
133    
134    @Override
135    protected void readMandatory(PacketDecoder decoder) {
136        messageId = decoder.readCString();
137        source = decoder.readAddress();
138        smLength = decoder.readUInt1();
139    }
140    
141    @Override
142    protected void writeMandatory(PacketEncoder encoder) throws IOException {
143        encoder.writeCString(messageId);
144        encoder.writeAddress(source);
145        encoder.writeUInt1(smLength);
146    }
147    
148    @Override
149    protected int getMandatorySize() {
150        int length = 2;
151        length += sizeOf(messageId);
152        length += sizeOf(source);
153        return length;
154    }
155}