PageRenderTime 15ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://mobicents.googlecode.com/
Java | 177 lines | 109 code | 37 blank | 31 comment | 24 complexity | d5c46b58167ae0c09da2667450ca14be MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. package javax.megaco.association;
  2. import java.io.Serializable;
  3. import javax.megaco.ExceptionInfoCode;
  4. import javax.megaco.ParameterNotSetException;
  5. /**
  6. * This class represents the local transport address. This transport address is
  7. * used by the stack to send messages to peer. It can be used to store and
  8. * retrieve the local transport type and the corresponding address. Only one of
  9. * the transport addresses can be set for the local entity. If the transport is
  10. * SCTP, then multiple local IP addresses can be set. If transport is TCP or
  11. * UDP, then only one IPv4/IPv6 address or domain name can be set. In this case
  12. * optional port id can also be specified.
  13. *
  14. *
  15. */
  16. public class LocalAddr implements Serializable {
  17. private String[] ipAddr = null;
  18. private TransportType tpt_type = null;
  19. private String addrString = null;
  20. private String aal5Addr = null;
  21. private String mtpAddr = null;
  22. private String domainName = null;
  23. private int portId = -1;
  24. private boolean isPortIdPresent = false;
  25. /**
  26. * Constructs a empty Local Address Identifier reference object. The
  27. * parameters would be set to this object using get methods defined for this
  28. * class.
  29. */
  30. public LocalAddr() {
  31. }
  32. public LocalAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
  33. if (ipAddr == null || tpt_type == null) {
  34. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("IP Address or TransportType cannot be null for LocalAddr");
  35. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  36. throw invalidArgumentException;
  37. }
  38. // TODO : check for IP valid form
  39. this.ipAddr = ipAddr;
  40. this.tpt_type = tpt_type;
  41. }
  42. public LocalAddr(java.lang.String addrString, TransportType tpt_type) throws IllegalArgumentException {
  43. if (addrString == null || tpt_type == null) {
  44. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("AddressString or TransportType cannot be null for LocalAddr");
  45. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  46. throw invalidArgumentException;
  47. }
  48. // TODO : check for validity
  49. this.addrString = addrString;
  50. this.tpt_type = tpt_type;
  51. }
  52. public LocalAddr(java.lang.String aal5Addr) throws IllegalArgumentException {
  53. if (addrString == null) {
  54. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5 AddressString cannot be null for LocalAddr");
  55. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  56. throw invalidArgumentException;
  57. }
  58. // TODO : check for validity
  59. tpt_type = TransportType.ATM_TPT;
  60. this.aal5Addr = aal5Addr;
  61. }
  62. public void setDomainName(java.lang.String domainName, TransportType tpt_type) throws IllegalArgumentException {
  63. if (domainName == null || tpt_type == null) {
  64. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("domainName or TransportType cannot be null for LocalAddr");
  65. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  66. throw invalidArgumentException;
  67. }
  68. // TODO: Set the domainName as per tpt_type
  69. this.domainName = domainName;
  70. this.tpt_type = tpt_type;
  71. }
  72. public void setIpAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
  73. if (domainName == null || tpt_type == null) {
  74. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("ipAddr or TransportType cannot be null for LocalAddr");
  75. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  76. throw invalidArgumentException;
  77. }
  78. // TODO: Check for validity
  79. this.ipAddr = ipAddr;
  80. this.tpt_type = tpt_type;
  81. }
  82. public void setPortId(int portId) throws IllegalArgumentException {
  83. if (portId < 1) {
  84. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("portId cannot be less than 1 for LocalAddr");
  85. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  86. throw invalidArgumentException;
  87. }
  88. this.isPortIdPresent = true;
  89. this.portId = portId;
  90. }
  91. public void setMtp3Addr(java.lang.String mtpAddr) throws IllegalArgumentException {
  92. if (mtpAddr == null) {
  93. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("mtpAddr cannot be null for LocalAddr");
  94. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  95. throw invalidArgumentException;
  96. }
  97. this.tpt_type = TransportType.MTP3B_TPT;
  98. this.mtpAddr = mtpAddr;
  99. }
  100. public void setAAL5Addr(java.lang.String aal5Addr) throws IllegalArgumentException {
  101. if (aal5Addr == null) {
  102. IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5Addr cannot be null for LocalAddr");
  103. //invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
  104. throw invalidArgumentException;
  105. }
  106. // TODO : Validity check?
  107. this.aal5Addr = aal5Addr;
  108. this.tpt_type = TransportType.ATM_TPT;
  109. }
  110. public java.lang.String getDomainName() {
  111. return this.domainName;
  112. }
  113. public java.lang.String[] getIpAddr() {
  114. return this.ipAddr;
  115. }
  116. public int getPortId() throws ParameterNotSetException {
  117. if (!this.isPortIdPresent) {
  118. ParameterNotSetException parameterNotSetException = new ParameterNotSetException("PortId not yet set for LocalAddr");
  119. throw parameterNotSetException;
  120. }
  121. return this.portId;
  122. }
  123. public boolean isPortIdPresent() {
  124. return this.isPortIdPresent;
  125. }
  126. public java.lang.String getMtp3Addr() {
  127. return this.mtpAddr;
  128. }
  129. public java.lang.String getAAL5Addr() {
  130. return this.aal5Addr;
  131. }
  132. public int getTransportType() {
  133. return this.tpt_type.getTransportType();
  134. }
  135. @Override
  136. public String toString() {
  137. // TODO : need to recreate
  138. return super.toString();
  139. }
  140. }