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