KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > servers > ServerList


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.vfs.servers;
20
21 import java.util.*;
22
23 import org.openharmonise.vfs.servers.*;
24
25
26 /**
27  * Holds a list of all the servers that Content Manager is connected to.
28  *
29  * @author Matthew Large
30  * @version $Revision: 1.1 $
31  *
32  */

33 public class ServerList {
34
35     /**
36      * Instance, following singleton pattern.
37      */

38     private static ServerList m_instance = null;
39
40     /**
41      * Map of hostname to {@link Server} objects.
42      */

43     private HashMap m_aServers = new HashMap();
44     
45     /**
46      * Harmonise server.
47      */

48     private Server m_HarmoniseServer = null;
49
50     /**
51      *
52      */

53     private ServerList() {
54         super();
55     }
56     
57     /**
58      * Returns the instance, following singleton patter.
59      *
60      * @return The instance
61      */

62     public static ServerList getInstance() {
63         if(m_instance==null) {
64             m_instance = new ServerList();
65         }
66         return m_instance;
67     }
68
69     /**
70      * Add the Harmonise server.
71      *
72      * @param server Harmonise server
73      */

74     public void addHarmoniseServer(Server server) {
75         if(server.getURI().getHost()!=null && server.getURI().getHost().equals("localhost")) {
76             this.m_aServers.put("mutley.simulacramedia.com", server);
77         } else if(server.getURI().getHost()==null) {
78             this.m_aServers.put("LOCALFILESYSTEM", server);
79         }
80         this.m_aServers.put(server.getURI().getHost(), server);
81         this.m_HarmoniseServer = server;
82     }
83     
84     /**
85      * Returns the Harmonise server.
86      *
87      * @return Harmonise server
88      */

89     public Server getHarmoniseServer() {
90         return this.m_HarmoniseServer;
91     }
92
93     /**
94      * Adds a server.
95      *
96      * @param server Server to add
97      */

98     public void addServer(Server server) {
99         if(server.getURI().getHost()!=null && server.getURI().getHost().equals("localhost")) {
100             this.m_aServers.put("mutley.simulacramedia.com", server);
101         } else if(server.getURI().getHost()==null) {
102             this.m_aServers.put("LOCALFILESYSTEM", server);
103         }
104         this.m_aServers.put(server.getURI().getHost(), server);
105     }
106     
107     /**
108      * Removes a server.
109      *
110      * @param sHost Hostname of server to remove
111      */

112     public void removeServer(String JavaDoc sHost) {
113         this.m_aServers.remove(sHost);
114     }
115     
116     /**
117      * Returns a server.
118      *
119      * @param sHost Hostname of server to return
120      * @return Server
121      */

122     public Server getServer(String JavaDoc sHost) {
123         
124         return (Server) this.m_aServers.get(sHost);
125     }
126     
127     /**
128      * Returns a list of all the servers.
129      *
130      * @return List of {@link Server} objects
131      */

132     public List getServers() {
133         return new ArrayList(this.m_aServers.values());
134     }
135
136 }
137
Popular Tags