KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > NetworkServerList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server;
18
19 import java.util.Vector JavaDoc;
20
21 /**
22  * Network Server List Class
23  */

24 public class NetworkServerList
25 {
26     // List of network servers
27

28     private Vector JavaDoc<NetworkServer> m_servers;
29
30     /**
31      * Class constructor
32      */

33     public NetworkServerList()
34     {
35         m_servers = new Vector JavaDoc<NetworkServer>();
36     }
37
38     /**
39      * Return the number of servers in the list
40      *
41      * @return int
42      */

43     public final int numberOfServers()
44     {
45         return m_servers.size();
46     }
47
48     /**
49      * Add a server to the list
50      *
51      * @param server NetworkServer
52      */

53     public final void addServer(NetworkServer server)
54     {
55         m_servers.add(server);
56     }
57
58     /**
59      * Return the specified server
60      *
61      * @param idx int
62      * @return NetworkServer
63      */

64     public final NetworkServer getServer(int idx)
65     {
66
67         // Range check the index
68

69         if (idx < 0 || idx >= m_servers.size())
70             return null;
71         return m_servers.get(idx);
72     }
73
74     /**
75      * Find a server in the list by name
76      *
77      * @param name String
78      * @return NetworkServer
79      */

80     public final NetworkServer findServer(String JavaDoc name)
81     {
82
83         // Search for the required server
84

85         for (int i = 0; i < m_servers.size(); i++)
86         {
87
88             // Get the current server from the list
89

90             NetworkServer server = m_servers.get(i);
91
92             if (server.getProtocolName().equals(name))
93                 return server;
94         }
95
96         // Server not found
97

98         return null;
99     }
100
101     /**
102      * Remove the server at the specified position within the list
103      *
104      * @param idx int
105      * @return NetworkServer
106      */

107     public final NetworkServer removeServer(int idx)
108     {
109
110         // Range check the index
111

112         if (idx < 0 || idx >= m_servers.size())
113             return null;
114
115         // Remove the server from the list
116

117         NetworkServer server = m_servers.get(idx);
118         m_servers.remove(idx);
119         return server;
120     }
121
122     /**
123      * Remove the server with the specified protocol name
124      *
125      * @param proto String
126      * @return NetworkServer
127      */

128     public final NetworkServer removeServer(String JavaDoc proto)
129     {
130
131         // Search for the required server
132

133         for (int i = 0; i < m_servers.size(); i++)
134         {
135
136             // Get the current server from the list
137

138             NetworkServer server = m_servers.get(i);
139
140             if (server.getProtocolName().equals(proto))
141             {
142                 m_servers.remove(i);
143                 return server;
144             }
145         }
146
147         // Server not found
148

149         return null;
150     }
151
152     /**
153      * Remove all servers from the list
154      */

155     public final void removeAll()
156     {
157         m_servers.removeAllElements();
158     }
159 }
160
Popular Tags