PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 156 lines | 98 code | 21 blank | 37 comment | 5 complexity | f5a6b1c868fcb56da288e349b589d165 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 * Cancal message. This SMPP message is used to cancel a previously submitted
 34 * but yet undelivered short message at the SMSC. Relevant inherited fields from
 35 * SMPPPacket: <br>
 36 * <ul>
 37 * serviceType <br>
 38 * messageId <br>
 39 * source <br>
 40 * destination <br>
 41 * </ul>
 42 * 
 43 * @version $Id: CancelSM.java 457 2009-01-15 17:37:42Z orank $
 44 */
 45public class CancelSM extends SMPPPacket {
 46    private static final long serialVersionUID = 2L;
 47
 48    private String serviceType;
 49    private String messageId;
 50    private Address source;
 51    private Address destination;
 52    
 53    /**
 54     * Construct a new CancelSM.
 55     */
 56    public CancelSM() {
 57        super(CommandId.CANCEL_SM);
 58    }
 59
 60    public Address getDestination() {
 61        return destination;
 62    }
 63
 64    public void setDestination(Address destination) {
 65        this.destination = destination;
 66    }
 67
 68    public String getMessageId() {
 69        return messageId;
 70    }
 71
 72    public void setMessageId(String messageId) {
 73        this.messageId = messageId;
 74    }
 75
 76    public String getServiceType() {
 77        return serviceType;
 78    }
 79
 80    public void setServiceType(String serviceType) {
 81        this.serviceType = serviceType;
 82    }
 83
 84    public Address getSource() {
 85        return source;
 86    }
 87
 88    public void setSource(Address source) {
 89        this.source = source;
 90    }
 91
 92    @Override
 93    public boolean equals(Object obj) {
 94        boolean equals = super.equals(obj);
 95        if (equals) {
 96            CancelSM other = (CancelSM) obj;
 97            equals |= safeCompare(serviceType, other.serviceType);
 98            equals |= safeCompare(messageId, other.messageId);
 99            equals |= safeCompare(source, other.source);
100            equals |= safeCompare(destination, other.destination);
101        }
102        return equals;
103    }
104    
105    @Override
106    public int hashCode() {
107        int hc = super.hashCode();
108        hc += (serviceType != null) ? serviceType.hashCode() : 0;
109        hc += (messageId != null) ? messageId.hashCode() : 0;
110        hc += (source != null) ? source.hashCode() : 0;
111        hc += (destination != null) ? destination.hashCode() : 0;
112        return hc;
113    }
114    
115    @Override
116    protected void toString(StringBuilder buffer) {
117        buffer.append("serviceType=").append(serviceType)
118        .append(",messageId=").append(messageId)
119        .append(",source=").append(source)
120        .append(",destination=").append(destination);
121    }
122    
123    @Override
124    protected void validateMandatory(SMPPVersion smppVersion) {
125        smppVersion.validateServiceType(serviceType);
126        smppVersion.validateMessageId(messageId);
127        smppVersion.validateAddress(source);
128        smppVersion.validateAddress(destination);
129    }
130    
131    @Override
132    protected void readMandatory(PacketDecoder decoder) {
133        serviceType = decoder.readCString();
134        messageId = decoder.readCString();
135        source = decoder.readAddress();
136        destination = decoder.readAddress();
137    }
138    
139    @Override
140    protected void writeMandatory(PacketEncoder encoder) throws IOException {
141        encoder.writeCString(serviceType);
142        encoder.writeCString(messageId);
143        encoder.writeAddress(source);
144        encoder.writeAddress(destination);
145    }
146    
147    @Override
148    protected int getMandatorySize() {
149        int length = 2;
150        length += sizeOf(serviceType);
151        length += sizeOf(messageId);
152        length += sizeOf(source);
153        length += sizeOf(destination);
154        return length;
155    }
156}