PageRenderTime 53ms CodeModel.GetById 37ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

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