001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.vfs.servers;
020:
021: import java.util.*;
022:
023: import org.openharmonise.vfs.servers.*;
024:
025: /**
026: * Holds a list of all the servers that Content Manager is connected to.
027: *
028: * @author Matthew Large
029: * @version $Revision: 1.1 $
030: *
031: */
032: public class ServerList {
033:
034: /**
035: * Instance, following singleton pattern.
036: */
037: private static ServerList m_instance = null;
038:
039: /**
040: * Map of hostname to {@link Server} objects.
041: */
042: private HashMap m_aServers = new HashMap();
043:
044: /**
045: * Harmonise server.
046: */
047: private Server m_HarmoniseServer = null;
048:
049: /**
050: *
051: */
052: private ServerList() {
053: super ();
054: }
055:
056: /**
057: * Returns the instance, following singleton patter.
058: *
059: * @return The instance
060: */
061: public static ServerList getInstance() {
062: if (m_instance == null) {
063: m_instance = new ServerList();
064: }
065: return m_instance;
066: }
067:
068: /**
069: * Add the Harmonise server.
070: *
071: * @param server Harmonise server
072: */
073: public void addHarmoniseServer(Server server) {
074: if (server.getURI().getHost() != null
075: && server.getURI().getHost().equals("localhost")) {
076: this .m_aServers.put("mutley.simulacramedia.com", server);
077: } else if (server.getURI().getHost() == null) {
078: this .m_aServers.put("LOCALFILESYSTEM", server);
079: }
080: this .m_aServers.put(server.getURI().getHost(), server);
081: this .m_HarmoniseServer = server;
082: }
083:
084: /**
085: * Returns the Harmonise server.
086: *
087: * @return Harmonise server
088: */
089: public Server getHarmoniseServer() {
090: return this .m_HarmoniseServer;
091: }
092:
093: /**
094: * Adds a server.
095: *
096: * @param server Server to add
097: */
098: public void addServer(Server server) {
099: if (server.getURI().getHost() != null
100: && server.getURI().getHost().equals("localhost")) {
101: this .m_aServers.put("mutley.simulacramedia.com", server);
102: } else if (server.getURI().getHost() == null) {
103: this .m_aServers.put("LOCALFILESYSTEM", server);
104: }
105: this .m_aServers.put(server.getURI().getHost(), server);
106: }
107:
108: /**
109: * Removes a server.
110: *
111: * @param sHost Hostname of server to remove
112: */
113: public void removeServer(String sHost) {
114: this .m_aServers.remove(sHost);
115: }
116:
117: /**
118: * Returns a server.
119: *
120: * @param sHost Hostname of server to return
121: * @return Server
122: */
123: public Server getServer(String sHost) {
124:
125: return (Server) this .m_aServers.get(sHost);
126: }
127:
128: /**
129: * Returns a list of all the servers.
130: *
131: * @return List of {@link Server} objects
132: */
133: public List getServers() {
134: return new ArrayList(this.m_aServers.values());
135: }
136:
137: }
|