Source code: net/jxta/ext/config/TcpTransportAddress.java
1 /*
2 * Copyright (c) 2001 Sun Microsystems, Inc. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. The end-user documentation included with the redistribution,
18 * if any, must include the following acknowledgment:
19 * "This product includes software developed by the
20 * Sun Microsystems, Inc. for Project JXTA."
21 * Alternately, this acknowledgment may appear in the software itself,
22 * if and wherever such third-party acknowledgments normally appear.
23 *
24 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA"
25 * must not be used to endorse or promote products derived from this
26 * software without prior written permission. For written
27 * permission, please contact Project JXTA at http://www.jxta.org.
28 *
29 * 5. Products derived from this software may not be called "JXTA",
30 * nor may "JXTA" appear in their name, without prior written
31 * permission of Sun.
32 *
33 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
37 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * SUCH DAMAGE.
45 * ====================================================================
46 *
47 * This software consists of voluntary contributions made by many
48 * individuals on behalf of Project JXTA. For more
49 * information on Project JXTA, please see
50 * <http://www.jxta.org/>.
51 *
52 * This license is based on the BSD license adopted by the Apache Foundation.
53 *
54 * $Id: TcpTransportAddress.java,v 1.7 2004/05/18 22:00:48 gonzo Exp $
55 */
56 package net.jxta.ext.config;
57
58 import java.util.ArrayList;
59 import java.util.Collections;
60 import java.util.Iterator;
61 import java.util.List;
62
63 /**
64 * Container for Tcp addresses.
65 *
66 * @author james todd [gonzo at jxta dot org]
67 * @version
68 */
69 public class TcpTransportAddress
70 extends Address
71 implements Cloneable {
72
73 private List multicastAddresses = null;
74
75
76 /**
77 * Constructor for the TcpTransportAddress object
78 */
79 public TcpTransportAddress() {
80 this(null);
81 }
82
83
84 /**
85 * Constructor for the TcpTransportAddress object
86 *
87 * @param ta Description of the Parameter
88 */
89 public TcpTransportAddress(TcpTransportAddress ta) {
90 super(ta);
91
92 setMulticastAddresses(ta != null ? ta.getMulticastAddresses() : null);
93 }
94
95
96 /**
97 * Gets the addresses attribute of the Transport object
98 *
99 * @return The addresses value
100 */
101 public List getMulticastAddresses() {
102 return this.multicastAddresses != null ?
103 this.multicastAddresses : Collections.EMPTY_LIST;
104 }
105
106
107 /**
108 * Sets the address attribute of the Transport object
109 *
110 * @param address The new address value
111 */
112 public void setMulticastAddress(MulticastAddress address) {
113 List r = new ArrayList();
114
115 r.add(address);
116
117 setMulticastAddresses(r);
118 }
119
120
121 /**
122 * Sets the addresses attribute of the Transport object
123 *
124 * @param addresses The new addresses value
125 */
126 public void setMulticastAddresses(List addresses) {
127 if (this.multicastAddresses != null) {
128 this.multicastAddresses.clear();
129 }
130
131 addMulticastAddresses(addresses);
132 }
133
134
135 /**
136 * Adds a feature to the Address attribute of the Transport object
137 *
138 * @param address The feature to be added to the Address attribute
139 */
140 public void addMulticastAddress(MulticastAddress address) {
141 List r = new ArrayList();
142
143 r.add(address);
144
145 addMulticastAddresses(r);
146 }
147
148
149 /**
150 * Adds a feature to the Addresses attribute of the Transport object
151 *
152 * @param addresses The feature to be added to the Addresses attribute
153 */
154 public void addMulticastAddresses(List addresses) {
155 for (Iterator i = addresses != null ?
156 addresses.iterator() : Collections.EMPTY_LIST.iterator();
157 i.hasNext(); ) {
158 MulticastAddress a = (MulticastAddress)i.next();
159
160 if (a != null &&
161 (this.multicastAddresses == null ||
162 !this.multicastAddresses.contains(a))) {
163 if (this.multicastAddresses == null) {
164 this.multicastAddresses = new ArrayList();
165 }
166
167 this.multicastAddresses.add(a);
168 }
169 }
170 }
171
172
173 /**
174 * Description of the Method
175 *
176 * @param address Description of the Parameter
177 * @return Description of the Return Value
178 */
179 public Address removeMulticastAddress(Address address) {
180 Object o = null;
181
182 if (this.multicastAddresses != null) {
183 int i = this.multicastAddresses.indexOf(address);
184
185 if (i > -1) {
186 o = this.multicastAddresses.remove(i);
187
188 if (this.multicastAddresses.size() == 0) {
189 this.multicastAddresses = null;
190 }
191 }
192 }
193
194 return (Address)o;
195 }
196
197
198 /**
199 * Description of the Method
200 */
201 public void clearMulticastAddresses() {
202 if (this.multicastAddresses != null) {
203 this.multicastAddresses.clear();
204
205 this.multicastAddresses = null;
206 }
207 }
208 }
209