PageRenderTime 33ms CodeModel.GetById 15ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 219 lines | 162 code | 31 blank | 26 comment | 10 complexity | 9677103822f910a891608d7fc113b64f 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.message.tlv.TLVTable;
 29import org.mobicents.protocols.smpp.message.tlv.Tag;
 30import org.mobicents.protocols.smpp.util.PacketDecoder;
 31import org.mobicents.protocols.smpp.util.PacketEncoder;
 32import org.mobicents.protocols.smpp.util.SMPPDate;
 33import org.mobicents.protocols.smpp.version.SMPPVersion;
 34
 35/**
 36 * Submit a broadcast message to the SMSC.
 37 * @version $Id: BroadcastSM.java 457 2009-01-15 17:37:42Z orank $
 38 * @since 0.4.0
 39 */
 40public class BroadcastSM extends SMPPPacket {
 41    private static final long serialVersionUID = 2L;
 42    
 43    private String serviceType;
 44    private Address source;
 45    private String messageId;
 46    private int priority;
 47    private SMPPDate deliveryTime;
 48    private SMPPDate expiryTime;
 49    private int replaceIfPresent;
 50    private int dataCoding;
 51    private int defaultMsg;
 52    
 53    public BroadcastSM() {
 54        super (CommandId.BROADCAST_SM);
 55    }
 56
 57    public int getDataCoding() {
 58        return dataCoding;
 59    }
 60
 61    public void setDataCoding(int dataCoding) {
 62        this.dataCoding = dataCoding;
 63    }
 64
 65    public int getDefaultMsg() {
 66        return defaultMsg;
 67    }
 68
 69    public void setDefaultMsg(int defaultMsg) {
 70        this.defaultMsg = defaultMsg;
 71    }
 72
 73    public SMPPDate getDeliveryTime() {
 74        return deliveryTime;
 75    }
 76
 77    public void setDeliveryTime(SMPPDate deliveryTime) {
 78        this.deliveryTime = deliveryTime;
 79    }
 80
 81    public SMPPDate getExpiryTime() {
 82        return expiryTime;
 83    }
 84
 85    public void setExpiryTime(SMPPDate expiryTime) {
 86        this.expiryTime = expiryTime;
 87    }
 88
 89    public String getMessageId() {
 90        return messageId;
 91    }
 92
 93    public void setMessageId(String messageId) {
 94        this.messageId = messageId;
 95    }
 96
 97    public int getPriority() {
 98        return priority;
 99    }
100
101    public void setPriority(int priority) {
102        this.priority = priority;
103    }
104
105    public int getReplaceIfPresent() {
106        return replaceIfPresent;
107    }
108
109    public void setReplaceIfPresent(int replaceIfPresent) {
110        this.replaceIfPresent = replaceIfPresent;
111    }
112
113    public String getServiceType() {
114        return serviceType;
115    }
116
117    public void setServiceType(String serviceType) {
118        this.serviceType = serviceType;
119    }
120
121    public Address getSource() {
122        return source;
123    }
124
125    public void setSource(Address source) {
126        this.source = source;
127    }
128
129    @Override
130    public boolean equals(Object obj) {
131        boolean equals = super.equals(obj);
132        if (equals) {
133            BroadcastSM other = (BroadcastSM) obj;
134            equals |= safeCompare(serviceType, other.serviceType);
135            equals |= safeCompare(source, other.source);
136            equals |= safeCompare(messageId, other.messageId);
137            equals |= priority == other.priority;
138            equals |= safeCompare(deliveryTime, other.deliveryTime);
139            equals |= safeCompare(expiryTime, other.expiryTime);
140            equals |= replaceIfPresent == other.replaceIfPresent;
141            equals |= dataCoding == other.dataCoding;
142            equals |= defaultMsg == other.defaultMsg;
143        }
144        return equals;
145    }
146    
147    @Override
148    public int hashCode() {
149        int hc = super.hashCode();
150        hc += (serviceType != null) ? serviceType.hashCode() : 13;
151        hc += (source != null) ? source.hashCode() : 13;
152        hc += (messageId != null) ? messageId.hashCode() : 13;
153        hc += Integer.valueOf(priority).hashCode();
154        hc += (deliveryTime != null) ? deliveryTime.hashCode() : 13;
155        hc += (expiryTime != null) ? expiryTime.hashCode() : 13;
156        hc += Integer.valueOf(replaceIfPresent).hashCode();
157        hc += Integer.valueOf(dataCoding).hashCode();
158        hc += Integer.valueOf(defaultMsg).hashCode();
159        return hc;
160    }
161    
162    @Override
163    protected void readMandatory(PacketDecoder decoder) {
164        serviceType = decoder.readCString();
165        source = decoder.readAddress();
166        messageId = decoder.readCString();
167        priority = decoder.readUInt1();
168        deliveryTime = decoder.readDate();
169        expiryTime = decoder.readDate();
170        replaceIfPresent = decoder.readUInt1();
171        dataCoding = decoder.readUInt1();
172        defaultMsg = decoder.readUInt1();
173    }
174    
175    @Override
176    protected void writeMandatory(PacketEncoder encoder) throws IOException {
177        encoder.writeCString(serviceType);
178        encoder.writeAddress(source);
179        encoder.writeCString(messageId);
180        encoder.writeUInt1(priority);
181        encoder.writeDate(deliveryTime);
182        encoder.writeDate(expiryTime);
183        encoder.writeUInt1(replaceIfPresent);
184        encoder.writeUInt1(dataCoding);
185        encoder.writeUInt1(defaultMsg);
186    }
187    
188    @Override
189    protected int getMandatorySize() {
190        int length = 6;
191        length += sizeOf(serviceType);
192        length += sizeOf(source);
193        length += sizeOf(messageId);
194        length += sizeOf(deliveryTime);
195        length += sizeOf(expiryTime);
196        return length;
197    }
198    
199    @Override
200    protected void validateMandatory(SMPPVersion smppVersion) {
201        smppVersion.validateServiceType(serviceType);
202        smppVersion.validateAddress(source);
203        smppVersion.validateMessageId(messageId);
204        smppVersion.validatePriorityFlag(priority);
205        smppVersion.validateReplaceIfPresent(replaceIfPresent);
206        smppVersion.validateDataCoding(dataCoding);
207        smppVersion.validateDefaultMsg(defaultMsg);
208    }
209    
210    protected boolean validateTLVTable(SMPPVersion version) {
211        boolean valid = true;
212        TLVTable tlvTable = getTLVTable();
213        valid &= tlvTable.containsKey(Tag.BROADCAST_AREA_IDENTIFIER);
214        valid &= tlvTable.containsKey(Tag.BROADCAST_CONTENT_TYPE);
215        valid &= tlvTable.containsKey(Tag.BROADCAST_REP_NUM);
216        valid &= tlvTable.containsKey(Tag.BROADCAST_FREQUENCY_INTERVAL);
217        return valid;
218    }
219}