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

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/gsm/HeaderElement.java

http://mobicents.googlecode.com/
Java | 94 lines | 11 code | 8 blank | 75 comment | 0 complexity | e24eb10231fda54fc1c323fa4e596be6 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.gsm;
24
25import java.nio.ByteBuffer;
26import java.util.List;
27
28/**
29 * An element that can be added to a user data header. Header elements are
30 * stateful objects as they may be output to multiple SMS segments.
31 * Depending on their implementation, they might be outputting the same
32 * information for each segment or different information. Therefore,
33 * before a <tt>HeaderElement</tt> can be used to generate message segments
34 * via {@link UserData#toSegments()} it must be in its initial state. If
35 * a header element has previously been used, returning to its initial
36 * state may be accomplished by invoking its {@link #reset()} method.
37 * @version $Id: HeaderElement.java 484 2010-02-08 16:08:50Z orank $
38 * @see UserData
39 * @see UserDataImpl
40 */
41public interface HeaderElement {
42    /**
43     * Get the total number of octets this header element encodes as
44     * <strong>excluding</strong> the IEI and the IEI-Data-Length fields.
45     * @return The number of octets in this header element's IE-Data, which
46     * may exceed 140 octets.
47     */
48    int getLength();
49    
50    /**
51     * Reset this <tt>HeaderElement</tt> to its initial state. A
52     * <tt>HeaderElement</tt> must be in its initial state before it can
53     * be used to generate SMS segments in a {@link UserData} implementation.
54     */
55    void reset();
56    
57    /**
58     * Determine if this <tt>HeaderElement</tt> has written all its data.
59     * This is an <strong>internal method</strong> that is used by
60     * {@link UserData} implementations.
61     * @return <tt>true</tt> if all of this header element's data has been
62     * written to SMS segments. Elements which always recur in every
63     * SMS segment (such as concatenation) will never return <tt>true</tt>
64     * from this method. 
65     */
66    boolean isComplete();
67
68    /**
69     * Encode this header element to the given ByteBuffer.
70     * @param out The byte buffer to write to.
71     */
72    boolean write(int segmentNum, ByteBuffer buffer);
73
74    /**
75     * This method allows <tt>HeaderElements</tt> to post-process SMS
76     * segments after they have all been created by
77     * {@link UserData#toSegments()}. This is primarily provided for
78     * {@link ConcatenatedSms} so that it can fill in the "total message
79     * segments" field in each segment once the total count is known.
80     * @param segments The generated SMS segments.
81     */
82    void postProcess(List<ByteBuffer> segments);
83    
84    /**
85     * Determine if this header element should be included in the header
86     * of each message in a concatenated message. For example, concatenation
87     * information must appear in every segment. Usually, other header
88     * element implementations will simply return false from here.
89     * @return <tt>true</tt> if this header element will be included in
90     * each message of a concatenated message, <tt>false</tt> if it
91     * only needs to occur in one segment.
92     */
93    boolean isRecurring();
94}