PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://mobicents.googlecode.com/
Java | 127 lines | 75 code | 18 blank | 34 comment | 8 complexity | 4ec8795901826a862679a29fbb321f84 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 * Alert notification. This packet type is sent from the SMSC to an ESME to
 34 * signal that a particular mobile subscriber has become available and a
 35 * delivery pending flag had previously been set for that subscriber by a
 36 * <code>data_sm</code> packet.
 37 * <p>
 38 * Note that there is no response packet to an <code>alert_notification</code>.
 39 * 
 40 * @version $Id: AlertNotification.java 457 2009-01-15 17:37:42Z orank $
 41 */
 42public class AlertNotification extends SMPPPacket implements Cloneable {
 43    private static final long serialVersionUID = 2L;
 44
 45    private Address source;
 46    private Address destination;
 47
 48    /**
 49     * Create a new alert_notification object.
 50     */
 51    public AlertNotification() {
 52        super(CommandId.ALERT_NOTIFICATION);
 53    }
 54
 55    public Address getDestination() {
 56        return destination;
 57    }
 58
 59    public void setDestination(Address destination) {
 60        this.destination = destination;
 61    }
 62
 63    public Address getSource() {
 64        return source;
 65    }
 66
 67    public void setSource(Address source) {
 68        this.source = source;
 69    }
 70
 71    @Override
 72    public boolean equals(Object obj) {
 73        if (this == obj) {
 74            return true;
 75        }
 76        if (null == obj || !(obj instanceof AlertNotification)) {
 77            return false;
 78        }
 79        boolean equals = super.equals(obj);
 80        if (equals) {
 81            AlertNotification other = (AlertNotification) obj;
 82            equals |= safeCompare(source, other.source);
 83            equals |= safeCompare(destination, other.destination);
 84        }
 85        return equals;
 86    }
 87    
 88    @Override
 89    public int hashCode() {
 90        int hc1 = (source != null) ? super.hashCode() : 13;
 91        int hc2 = (destination != null) ? super.hashCode() : 23;
 92        return super.hashCode() + hc1 + hc2;
 93    }
 94    
 95    @Override
 96    protected void toString(StringBuilder buffer) {
 97        buffer.append("source=").append(source)
 98        .append(",destination=").append(destination);
 99    }
100    
101    @Override
102    protected void validateMandatory(SMPPVersion smppVersion) {
103        smppVersion.validateAddress(source);
104        smppVersion.validateAddress(destination);
105    }
106
107    @Override
108    protected void writeMandatory(PacketEncoder encoder) throws IOException {
109        encoder.writeAddress(source);
110        encoder.writeAddress(destination);
111    }
112
113    @Override
114    protected void readMandatory(PacketDecoder decoder) {
115        source = decoder.readAddress();
116        destination = decoder.readAddress();
117    }
118    
119    @Override
120    protected int getMandatorySize() {
121        int length = 0;
122        length += sizeOf(source);
123        length += sizeOf(destination);
124        return length;
125    }
126}
127