/protocols/jain-megaco/megaco-api/src/main/java/javax/megaco/association/RemoteAddr.java

http://mobicents.googlecode.com/ · Java · 236 lines · 105 code · 36 blank · 95 comment · 25 complexity · f99e0879249f7a019b79fe3afdfceb06 MD5 · raw file

  1. package javax.megaco.association;
  2. import java.io.Serializable;
  3. import javax.megaco.ExceptionInfoCode;
  4. /**
  5. * This class represents the remote transport address. This transport address is
  6. * used by the stack to send messages to peer. It can be used to store and
  7. * retrieve the remote transport type and the corresponding address. Only one of
  8. * the transport addresses can be set for the remote entity. If the transport is
  9. * SCTP, then multiple remote IP addresses can be set. If transport is TCP or
  10. * UDP, then only one IPv4/IPv6 address or domain name can be set. In this case
  11. * optional port id can also be specified.
  12. */
  13. public class RemoteAddr implements Serializable {
  14. private String[] ipAddr = null;
  15. private TransportType tpt_type = null;
  16. private String addrString = null;
  17. private String AAL5Addr = null;
  18. private String mtp3Addr = null;
  19. private String domainName = null;
  20. private int portId;
  21. /**
  22. * Constructs a new remote address object identifier.
  23. */
  24. public RemoteAddr() {
  25. }
  26. /**
  27. * Constructs a new remote address with IPv4/ IPv6 addresses. The list of
  28. * address may be specified in case the transport type is M_SCTP_TPT. In
  29. * case of IPv4 or IPv6 address, the transport type must be set to M_UDP_TPT
  30. * or M_TCP_TPT.
  31. *
  32. * @param ipAddr
  33. * @param tpt_type
  34. * @throws IllegalArgumentException
  35. */
  36. public RemoteAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
  37. if (ipAddr == null || tpt_type == null) {
  38. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("IP Address or TransportType cannot be null for LocalAddr");
  39. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  40. throw invalidArgumentException;
  41. }
  42. // TODO : check for IP valid form
  43. this.ipAddr = ipAddr;
  44. this.tpt_type = tpt_type;
  45. }
  46. /**
  47. * Constructs a new remote entity with domain name. The possible values for
  48. * transport type could be M_SCTP_TPT, M_UDP_TPT, M_TCP_TPT, M_MTP3B_TPT,
  49. * and M_ATM_TPT.
  50. *
  51. * @param addrString
  52. * @param tpt_type
  53. * @throws IllegalArgumentException
  54. */
  55. public RemoteAddr(java.lang.String addrString, TransportType tpt_type) throws IllegalArgumentException {
  56. if (addrString == null || tpt_type == null) {
  57. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("AddressString or TransportType cannot be null for LocalAddr");
  58. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  59. throw invalidArgumentException;
  60. }
  61. // TODO : check for validity
  62. this.addrString = addrString;
  63. this.tpt_type = tpt_type;
  64. }
  65. /**
  66. * Constructs a new remote entity with ATM AAL type 5 Address, if the
  67. * signalling is over ATM layer. The transport type in this case is set to
  68. * M_ATM_TPT.
  69. *
  70. * @param aal5Addr
  71. * @throws IllegalArgumentException
  72. */
  73. public RemoteAddr(java.lang.String aal5Addr) throws IllegalArgumentException {
  74. if (addrString == null) {
  75. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5 AddressString cannot be null for LocalAddr");
  76. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  77. throw invalidArgumentException;
  78. }
  79. // TODO : check for validity
  80. tpt_type = TransportType.ATM_TPT;
  81. this.AAL5Addr = aal5Addr;
  82. }
  83. /**
  84. * Sets the domain name for the remote address. The transport type in this
  85. * case can be set to M_SCTP_TPT, M_UDP_TPT, M_TCP_TPT, and M_ATM_TPT. The
  86. * underlying transport in this case would resolve the domain name to actual
  87. * transport address.
  88. *
  89. * @param domainName
  90. * @param tpt_type
  91. * @throws IllegalArgumentException
  92. */
  93. public void setDomainName(java.lang.String domainName, TransportType tpt_type) throws IllegalArgumentException {
  94. if (domainName == null || tpt_type == null) {
  95. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("domainName or TransportType cannot be null for LocalAddr");
  96. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  97. throw invalidArgumentException;
  98. }
  99. if (tpt_type.getTransportType() == TransportType.MTP3B_TPT.getTransportType()) {
  100. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("Transport type can not be set to MTP3B_TPT");
  101. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  102. throw invalidArgumentException;
  103. }
  104. // TODO: Set the domainName as per tpt_type
  105. this.domainName = domainName;
  106. this.tpt_type = tpt_type;
  107. }
  108. /**
  109. * Sets the IPv4/ IPv6 addresses for the remote address. In case the
  110. * transport type is M_SCTP_TPT, the user can specify multiples of IP
  111. * addresses. The other valid values for transport type are M_UDP_TPT and
  112. * M_TCP_TPT.
  113. *
  114. * @param ipAddr
  115. * @param tpt_type
  116. * @throws IllegalArgumentException
  117. */
  118. public void setIpAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
  119. if (domainName == null || tpt_type == null) {
  120. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("ipAddr or TransportType cannot be null for LocalAddr");
  121. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  122. throw invalidArgumentException;
  123. }
  124. // TODO: Check for validity
  125. this.ipAddr = ipAddr;
  126. this.tpt_type = tpt_type;
  127. }
  128. /**
  129. * Sets the remote port identity.
  130. *
  131. * @param portId
  132. * @throws IllegalArgumentException
  133. */
  134. public void setPortId(int portId) throws IllegalArgumentException {
  135. if (portId < 1) {
  136. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("portId cannot be less than 1 for LocalAddr");
  137. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  138. throw invalidArgumentException;
  139. }
  140. this.portId = portId;
  141. }
  142. /**
  143. * Sets the MTP-3 Address for the remote address. This is used if the
  144. * underlying link is over SS7.
  145. *
  146. * @param mtpAddr
  147. * @throws IllegalArgumentException
  148. */
  149. public void setMtp3Addr(java.lang.String mtpAddr) throws IllegalArgumentException {
  150. if (mtpAddr == null) {
  151. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("mtpAddr cannot be null for LocalAddr");
  152. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  153. throw invalidArgumentException;
  154. }
  155. this.tpt_type = TransportType.MTP3B_TPT;
  156. this.addrString = mtpAddr;
  157. }
  158. /**
  159. * Sets the AAL of type 5 address for the remote address when the remote
  160. * transport is over ATM cells.
  161. *
  162. * @param aal5Addr
  163. * @throws IllegalArgumentException
  164. */
  165. public void setAAL5Addr(java.lang.String aal5Addr) throws IllegalArgumentException {
  166. if (aal5Addr == null) {
  167. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5Addr cannot be null for RemoteAddrd");
  168. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  169. throw invalidArgumentException;
  170. }
  171. // ??
  172. this.tpt_type = TransportType.ATM_TPT;
  173. this.AAL5Addr = aal5Addr;
  174. }
  175. public String[] getIpAddr() {
  176. return ipAddr;
  177. }
  178. public int getTransportType() {
  179. return tpt_type.getTransportType();
  180. }
  181. public String getAddrString() {
  182. return addrString;
  183. }
  184. public String getAAL5Addr() {
  185. return AAL5Addr;
  186. }
  187. public String getDomainName() {
  188. return domainName;
  189. }
  190. public int getPortId() {
  191. return portId;
  192. }
  193. public boolean isPortIdPresent() {
  194. // ??
  195. return this.portId > 0;
  196. }
  197. public String getMtp3Addr() {
  198. return mtp3Addr;
  199. }
  200. }