PageRenderTime 138ms CodeModel.GetById 128ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 140 lines | 74 code | 18 blank | 48 comment | 7 complexity | b73b48d1670161294a22fb0330ef88b6 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 the last number of messages sent from a certain ESME. Relevant
 34 * inherited fields from SMPPPacket: <br>
 35 * <ul>
 36 * source <br>
 37 * </ul>
 38 * 
 39 * @version $Id: QueryLastMsgs.java 457 2009-01-15 17:37:42Z orank $
 40 */
 41public class QueryLastMsgs extends SMPPPacket {
 42    private static final long serialVersionUID = 2L;
 43    
 44    /**
 45     * The source address for which to query messages. The last <code>
 46     * msgCount</code> messages originating from this source address will
 47     * be retrieved.
 48     */
 49    private Address source;
 50
 51    /**
 52     * Number of messages to look up.
 53     */
 54    private int msgCount;
 55
 56    /**
 57     * Construct a new QueryLastMsgs.
 58     */
 59    public QueryLastMsgs() {
 60        super(CommandId.QUERY_LAST_MSGS);
 61    }
 62
 63    public Address getSource() {
 64        return source;
 65    }
 66
 67    public void setSource(Address source) {
 68        this.source = source;
 69    }
 70
 71    public int getMsgCount() {
 72        return msgCount;
 73    }
 74
 75    /**
 76     * Set the number of messages to query. <code>msgCount</code> must be
 77     * between 1 and 100 inclusive. Attempts to set a value less than 1 will
 78     * force the value to 1. Attempts to set a value greater than 100 will
 79     * force the value to 100.
 80     * @param msgCount The number of messages to query from the SMSC.
 81     */
 82    public void setMsgCount(int msgCount) {
 83        if (msgCount < 1) {
 84            this.msgCount = 1;
 85        } else if (msgCount > 100) {
 86            this.msgCount = 100;
 87        } else {
 88            this.msgCount = msgCount;
 89        }
 90    }
 91
 92    @Override
 93    public boolean equals(Object obj) {
 94        boolean equals = super.equals(obj);
 95        if (equals) {
 96            QueryLastMsgs other = (QueryLastMsgs) obj;
 97            equals |= safeCompare(source, other.source);
 98            equals |= msgCount == other.msgCount;
 99        }
100        return equals;
101    }
102    
103    @Override
104    public int hashCode() {
105        int hc = super.hashCode();
106        hc += (source != null) ? source.hashCode() : 0;
107        hc += Integer.valueOf(msgCount).hashCode();
108        return hc;
109    }
110
111    @Override
112    protected void toString(StringBuilder buffer) {
113        buffer.append("source=").append(source)
114        .append("msgCount=").append(msgCount);
115    }
116
117    @Override
118    protected void validateMandatory(SMPPVersion smppVersion) {
119        smppVersion.validateAddress(source);
120    }
121    
122    @Override
123    protected void readMandatory(PacketDecoder decoder) {
124        source = decoder.readAddress();
125        msgCount = decoder.readUInt1();
126    }
127    
128    @Override
129    protected void writeMandatory(PacketEncoder encoder) throws IOException {
130        encoder.writeAddress(source);
131        encoder.writeUInt1(msgCount);
132    }
133    
134    @Override
135    protected int getMandatorySize() {
136        int length = 1;
137        length += sizeOf(source);
138        return length;
139    }
140}