PageRenderTime 21ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 2ms 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
  1package javax.megaco.association;
  2
  3import java.io.Serializable;
  4
  5import javax.megaco.ExceptionInfoCode;
  6
  7import javax.megaco.ParameterNotSetException;
  8
  9/**
 10 * This class represents the local transport address. This transport address is
 11 * used by the stack to send messages to peer. It can be used to store and
 12 * retrieve the local transport type and the corresponding address. Only one of
 13 * the transport addresses can be set for the local entity. If the transport is
 14 * SCTP, then multiple local IP addresses can be set. If transport is TCP or
 15 * UDP, then only one IPv4/IPv6 address or domain name can be set. In this case
 16 * optional port id can also be specified.
 17 * 
 18 * 
 19 */
 20public class LocalAddr implements Serializable {
 21
 22	private String[] ipAddr = null;
 23	private TransportType tpt_type = null;
 24	private String addrString = null;
 25	private String aal5Addr = null;
 26	private String mtpAddr = null;
 27
 28	private String domainName = null;
 29	private int portId = -1;
 30	private boolean isPortIdPresent = false;
 31
 32	/**
 33	 * Constructs a empty Local Address Identifier reference object. The
 34	 * parameters would be set to this object using get methods defined for this
 35	 * class.
 36	 */
 37	public LocalAddr() {
 38
 39	}
 40
 41	public LocalAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
 42		if (ipAddr == null || tpt_type == null) {
 43			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("IP Address or TransportType cannot be null for LocalAddr");
 44			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
 45			throw invalidArgumentException;
 46		}
 47
 48		// TODO : check for IP valid form
 49
 50		this.ipAddr = ipAddr;
 51		this.tpt_type = tpt_type;
 52	}
 53
 54	public LocalAddr(java.lang.String addrString, TransportType tpt_type) throws IllegalArgumentException {
 55
 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
 62		// TODO : check for validity
 63
 64		this.addrString = addrString;
 65		this.tpt_type = tpt_type;
 66	}
 67
 68	public LocalAddr(java.lang.String aal5Addr) throws IllegalArgumentException {
 69
 70		if (addrString == null) {
 71			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5 AddressString cannot be null for LocalAddr");
 72			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
 73			throw invalidArgumentException;
 74		}
 75
 76		// TODO : check for validity
 77
 78		tpt_type = TransportType.ATM_TPT;
 79		this.aal5Addr = aal5Addr;
 80	}
 81
 82	public void setDomainName(java.lang.String domainName, TransportType tpt_type) throws IllegalArgumentException {
 83		if (domainName == null || tpt_type == null) {
 84			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("domainName  or TransportType cannot be null for LocalAddr");
 85			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
 86			throw invalidArgumentException;
 87		}
 88
 89		// TODO: Set the domainName as per tpt_type
 90		this.domainName = domainName;
 91		this.tpt_type = tpt_type;
 92	}
 93
 94	public void setIpAddr(java.lang.String[] ipAddr, TransportType tpt_type) throws IllegalArgumentException {
 95		if (domainName == null || tpt_type == null) {
 96			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("ipAddr  or TransportType cannot be null for LocalAddr");
 97			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
 98			throw invalidArgumentException;
 99		}
100
101		// TODO: Check for validity
102
103		this.ipAddr = ipAddr;
104		this.tpt_type = tpt_type;
105	}
106
107	public void setPortId(int portId) throws IllegalArgumentException {
108
109		if (portId < 1) {
110			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("portId cannot be less than 1 for LocalAddr");
111			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
112			throw invalidArgumentException;
113		}
114		this.isPortIdPresent = true;
115		this.portId = portId;
116	}
117
118	public void setMtp3Addr(java.lang.String mtpAddr) throws IllegalArgumentException {
119		if (mtpAddr == null) {
120			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("mtpAddr cannot be null for LocalAddr");
121			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
122			throw invalidArgumentException;
123		}
124		this.tpt_type = TransportType.MTP3B_TPT;
125		this.mtpAddr = mtpAddr;
126	}
127
128	public void setAAL5Addr(java.lang.String aal5Addr) throws IllegalArgumentException {
129		if (aal5Addr == null) {
130			IllegalArgumentException invalidArgumentException = new IllegalArgumentException("aal5Addr cannot be null for LocalAddr");
131			//invalidArgumentException.setInfoCode(ExceptionInfoCode.INV_LOCAL_ADDR);
132			throw invalidArgumentException;
133		}
134		// TODO : Validity check?
135		this.aal5Addr = aal5Addr;
136		this.tpt_type = TransportType.ATM_TPT;
137	}
138
139	public java.lang.String getDomainName() {
140		return this.domainName;
141	}
142
143	public java.lang.String[] getIpAddr() {
144		return this.ipAddr;
145	}
146
147	public int getPortId() throws ParameterNotSetException {
148		if (!this.isPortIdPresent) {
149			ParameterNotSetException parameterNotSetException = new ParameterNotSetException("PortId not yet set for LocalAddr");
150			throw parameterNotSetException;
151		}
152		return this.portId;
153	}
154
155	public boolean isPortIdPresent() {
156		return this.isPortIdPresent;
157	}
158
159	public java.lang.String getMtp3Addr() {
160		return this.mtpAddr;
161	}
162
163	public java.lang.String getAAL5Addr() {
164		return this.aal5Addr;
165	}
166
167	public int getTransportType() {
168		return this.tpt_type.getTransportType();
169	}
170
171	@Override
172	public String toString() {
173		// TODO : need to recreate
174		return super.toString();
175	}
176
177}