01: // ServerListModel.java
02: // $Id: ServerListModel.java,v 1.8 2000/08/16 21:37:31 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1998.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigadmin.gui.slist;
07:
08: import java.util.Hashtable;
09:
10: import org.w3c.jigadmin.RemoteResourceWrapper;
11:
12: import org.w3c.jigsaw.admin.RemoteAccessException;
13: import org.w3c.jigsaw.admin.RemoteResource;
14:
15: import org.w3c.tools.sorter.Sorter;
16:
17: /**
18: * The default ServerList model.
19: * @version $Revision: 1.8 $
20: * @author Benoît Mahé (bmahe@w3.org)
21: */
22: public class ServerListModel implements ServerListModelInterface {
23:
24: RemoteResourceWrapper root = null;
25:
26: String servers[] = null;
27:
28: Hashtable serversrrw = null;
29:
30: /**
31: * Returns a array of the server names.
32: * @return an array of String
33: */
34: public String[] getServers() {
35: return servers;
36: }
37:
38: /**
39: * Get the server with the given name.
40: * @param name the server name
41: * @return The RemoteResourceWrapper of the server.
42: */
43: public RemoteResourceWrapper getServer(String name) {
44: return (RemoteResourceWrapper) serversrrw.get(name);
45: }
46:
47: /**
48: * Build the ServerListModel.
49: * @exception RemoteAccessException if a remote error occurs.
50: */
51: protected void build() throws RemoteAccessException {
52: RemoteResource rr = root.getResource();
53: boolean ic = false;
54:
55: try {
56: ic = rr.isContainer();
57: } catch (Exception ex) {
58: ex.printStackTrace();
59: }
60: String names[] = rr.enumerateResourceIdentifiers();
61: Sorter.sortStringArray(names, true);
62: //remove control and realms nodes
63: servers = new String[names.length - 1];
64: serversrrw = new Hashtable(servers.length);
65: int j = 0;
66: servers[j++] = ADMIN_SERVER_NAME;
67: serversrrw.put(ADMIN_SERVER_NAME, root);
68: for (int i = 0; i < names.length; i++) {
69: if ((!names[i].equals("control"))
70: && (!names[i].equals("realms"))) {
71: servers[j++] = names[i];
72: RemoteResourceWrapper server = root
73: .getChildResource(names[i]);
74: serversrrw.put(names[i], server);
75: }
76: }
77: }
78:
79: /**
80: * Constructor.
81: * @param root the root RemoteResourceWrapper.
82: * @exception RemoteAccessException if a remote error occurs.
83: */
84: public ServerListModel(RemoteResourceWrapper root)
85: throws RemoteAccessException {
86: this.root = root;
87: build();
88: }
89:
90: }
|