/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/message/descriptor/StreamDescriptor.java

http://mobicents.googlecode.com/ · Java · 130 lines · 48 code · 20 blank · 62 comment · 6 complexity · bed928248f859d605945928950bdf566 MD5 · raw file

  1. package javax.megaco.message.descriptor;
  2. import java.io.Serializable;
  3. import javax.megaco.CommandEvent;
  4. import javax.megaco.ParameterNotSetException;
  5. import javax.megaco.message.CommandReq;
  6. import javax.megaco.message.CommandResp;
  7. import javax.megaco.message.Descriptor;
  8. import javax.megaco.message.DescriptorType;
  9. import javax.megaco.pkg.PkgItemParam;
  10. import javax.megaco.pkg.GenericPkg.GenSigComplEvent;
  11. import javax.megaco.pkg.ToneGenPkg.ToneGenParamInd;
  12. import javax.megaco.pkg.ToneGenPkg.ToneGenParamTl;
  13. import javax.megaco.pkg.ToneGenPkg.ToneGenPlayToneSignal;
  14. /**
  15. * The class extends JAIN MEGACO Descriptor. This class describes the stream
  16. * descriptor. The SDP information set within the local and remote descriptor
  17. * for this class is outside the scope of JAIN MEGACO. It is defined in
  18. * javax.sdp.
  19. */
  20. public class StreamDescriptor extends Descriptor implements Serializable {
  21. private MediaStreamParam mediaStreamParam = null;
  22. private Integer streamId = null;
  23. /**
  24. * Constructs a Stream Descriptor object. This extends the Descriptor class.
  25. * It defines the Stream descriptor of the Megaco which contains the stream
  26. * id and stream parameter. Multiple of these can be set in the media
  27. * descriptor.
  28. */
  29. public StreamDescriptor() {
  30. super();
  31. super.descriptorId = DescriptorType.M_STREAM_DESC;
  32. }
  33. /**
  34. * This method cannot be overridden by the derived class. This method
  35. * returns that the descriptor identifier is of type descriptor Stream. This
  36. * method overrides the corresponding method of the base class Descriptor.
  37. *
  38. * @return descriptorId - Returns an integer value that identifies this
  39. * stream object as the type of stream descriptor. It returns that
  40. * it is Stream Descriptor i.e., M_STREAM_DESC.
  41. */
  42. public int getDescriptorId() {
  43. return super.descriptorId;
  44. }
  45. /**
  46. * This method gets the Stream parameter for the stream descriptor. This can
  47. * be used to get the local descriptor, remote descriptor and the local
  48. * control descriptor.
  49. *
  50. * @return Returns the object reference of type stream parameter.
  51. */
  52. public final MediaStreamParam getMediaStreamParam() {
  53. return this.mediaStreamParam;
  54. }
  55. /**
  56. * This method sets the stream parameter.
  57. *
  58. * @param streamParam
  59. * - Sets the stream parameter consisiting of atleast one of
  60. * local descriptor, local control and remote descriptor.
  61. * @throws IllegalArgumentException
  62. * if the parameters set for the stream parameter are such that
  63. * the Stream Descriptor cannot be encoded.
  64. */
  65. public final void setMediaStreamParam(MediaStreamParam streamParam) throws IllegalArgumentException {
  66. // FIXME: add error checks
  67. if (streamParam == null) {
  68. throw new IllegalArgumentException("MediaStreamParam must not be null");
  69. }
  70. this.mediaStreamParam = streamParam;
  71. }
  72. /**
  73. * The method can be used to get stream id in the stream descriptor. This
  74. * method should be invoked after verifying that the port number is present
  75. * using method isStreamIdPresent().
  76. *
  77. * @return streamId - The integer value of the stream id shall be returned.
  78. * @throws javax.megaco.ParameterNotSetException
  79. * - Thrown if streamId has not been set.
  80. */
  81. public int getStreamId() throws javax.megaco.ParameterNotSetException {
  82. if (this.streamId == null) {
  83. throw new ParameterNotSetException();
  84. }
  85. return this.streamId.intValue();
  86. }
  87. /**
  88. * The method can be used to set stream id in the stream descriptor.
  89. *
  90. * @param streamId
  91. * - The integer value of the stream id shall be set.
  92. * @throws IllegalArgumentException
  93. * - Thrown if streamId is set with an invalid value.
  94. */
  95. public void setStreamId(int streamId) throws IllegalArgumentException {
  96. if (streamId <= 0) {
  97. throw new IllegalArgumentException("StreanId must not be less or equal to zero");
  98. }
  99. this.streamId = new Integer(streamId);
  100. }
  101. /**
  102. * This method is used for checking if the Stream Id is present for this
  103. * descriptor or not.
  104. *
  105. * @return
  106. */
  107. public boolean isStreamIdPresent() {
  108. return this.streamId != null;
  109. }
  110. }