~ubuntu-branches/ubuntu/utopic/389-admin-console/utopic

« back to all changes in this revision

Viewing changes to src/com/netscape/management/admserv/panel/CGIAggregateDataModel.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2011-10-12 11:05:09 UTC
  • Revision ID: package-import@ubuntu.com-20111012110509-ybd1jr5xeat2ug1i
Tags: upstream-1.1.8
ImportĀ upstreamĀ versionĀ 1.1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc.  Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; version 2
 
9
 * of the License.
 
10
 * 
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 * 
 
20
 * END COPYRIGHT BLOCK **/
 
21
package com.netscape.management.admserv.panel;
 
22
 
 
23
import java.util.*;
 
24
import java.net.*;
 
25
import com.netscape.management.client.util.*;
 
26
import com.netscape.management.admserv.config.*;
 
27
import com.netscape.management.client.console.ConsoleInfo;
 
28
import com.netscape.management.admserv.panel.*;
 
29
 
 
30
/**
 
31
  *
 
32
  * @version 0.1 01/15/98
 
33
  * @author miodrag@netscape.com
 
34
  */
 
35
 
 
36
 
 
37
/**
 
38
 * A config data model that is an aggregate of multiple cgi data models.
 
39
 * It is intended for panels that need to work with multiple CGIs.
 
40
 */
 
41
public class CGIAggregateDataModel implements IConfigDataModel {
 
42
    private static String _clazz = "CGIAggregateDataModel";
 
43
    protected Hashtable _CGIs;
 
44
    protected String _modelName;
 
45
    protected ConsoleInfo _consoleInfo;
 
46
 
 
47
    public CGIAggregateDataModel(ConsoleInfo consoleInfo) {
 
48
        _CGIs = new Hashtable();
 
49
        _consoleInfo = consoleInfo;
 
50
    }
 
51
 
 
52
    public void add(String prefix, CGIDataModel cgi) {
 
53
        _CGIs.put(prefix, cgi);
 
54
    }
 
55
 
 
56
    public void remove(String prefix) {
 
57
        _CGIs.remove(prefix);
 
58
    }
 
59
 
 
60
 
 
61
    public void setDialogParent (java.awt.Component comp) {
 
62
        for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
 
63
            CGIDataModel cgi = (CGIDataModel) e.nextElement();
 
64
            cgi.setDialogParent(comp);
 
65
        }
 
66
    }
 
67
 
 
68
    public IConfigDataModel getCGI(String prefix) {
 
69
        return (IConfigDataModel)_CGIs.get(prefix);
 
70
    }
 
71
 
 
72
    protected String getAttrPrefix (String attrName) {
 
73
        int dot = attrName.indexOf('.');
 
74
        if (dot > 0) {
 
75
            return attrName.substring(0, dot);
 
76
        } else {
 
77
            Debug.println("dot not found in " + attrName);
 
78
            return null;
 
79
        }
 
80
    }
 
81
 
 
82
    public String getAttribute(String attr) {
 
83
        //Debug.println("ATTR=" + attr + " PREFIX=" + getAttrPrefix(attr));
 
84
        IConfigDataModel cgi =
 
85
                (IConfigDataModel)_CGIs.get(getAttrPrefix(attr));
 
86
        if (cgi != null) {
 
87
            return cgi.getAttribute(attr);
 
88
        } else {
 
89
            Debug.println(_clazz +
 
90
                    ".getAttribute() CGI for the attr " + attr + " not in data model");
 
91
            return "";
 
92
        }
 
93
    }
 
94
 
 
95
    public void setAttribute(String attr,
 
96
            String val) throws ValidationException {
 
97
        IConfigDataModel cgi =
 
98
                (IConfigDataModel)_CGIs.get(getAttrPrefix(attr));
 
99
        if (cgi != null) {
 
100
            cgi.setAttribute(attr, val);
 
101
        } else {
 
102
            Debug.println(_clazz +
 
103
                    ".setAttribute() CGI for the attr " + attr + " not in data model");
 
104
        }
 
105
    }
 
106
 
 
107
    public Enumeration getAttributes() {
 
108
        // to do implement AggregateEnumerator
 
109
        return new CGIAggregateEnumerator(_CGIs);
 
110
    }
 
111
 
 
112
    public boolean isLoaded() {
 
113
        for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
 
114
            IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
 
115
            if (!cgi.isLoaded()) {
 
116
                return false;
 
117
            }
 
118
        }
 
119
        return true;
 
120
    }
 
121
 
 
122
    public boolean isModified() {
 
123
        for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
 
124
            IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
 
125
            if (cgi.isModified()) {
 
126
                return true;
 
127
            }
 
128
        }
 
129
        return false;
 
130
    }
 
131
 
 
132
 
 
133
    /**
 
134
      * Load all CGIs
 
135
     */
 
136
    public void load() throws RemoteRequestException {
 
137
        for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
 
138
            IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
 
139
            if (!cgi.isLoaded()) {
 
140
                cgi.load();
 
141
            }
 
142
        }
 
143
    }
 
144
 
 
145
    /**
 
146
      * Save all modified CGIs
 
147
     */
 
148
    public void save() throws RemoteRequestException {
 
149
        for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
 
150
            IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
 
151
            if (cgi.isModified()) {
 
152
                cgi.save();
 
153
            }
 
154
        }
 
155
    }
 
156
 
 
157
    public String getModelName() {
 
158
        return CGIDataModel.getServerName(_consoleInfo);
 
159
    }
 
160
 
 
161
    public ConsoleInfo getConsoleInfo() {
 
162
        return _consoleInfo;
 
163
    }
 
164
 
 
165
}
 
166
 
 
167
 
 
168
/**
 
169
  * An enumerator class for a hashtable of CGIDataModels
 
170
  */
 
171
class CGIAggregateEnumerator implements Enumeration {
 
172
 
 
173
    Hashtable _aggregateTable;
 
174
    Enumeration _aggregateEnum;
 
175
    Enumeration _curEnum;
 
176
 
 
177
    CGIAggregateEnumerator(Hashtable aggregateTable) {
 
178
        _aggregateTable = aggregateTable;
 
179
        _aggregateEnum = _aggregateTable.elements();
 
180
    }
 
181
 
 
182
    public boolean hasMoreElements() {
 
183
        if (_curEnum == null || !_curEnum.hasMoreElements()) {
 
184
            if (!_aggregateEnum.hasMoreElements()) {
 
185
                _curEnum = null;
 
186
                return false;
 
187
            }
 
188
            CGIDataModel curTable =
 
189
                    (CGIDataModel)_aggregateEnum.nextElement();
 
190
            _curEnum = curTable.getAttributes();
 
191
        }
 
192
        return _curEnum.hasMoreElements();
 
193
    }
 
194
 
 
195
    public Object nextElement() {
 
196
        if (_curEnum == null) {
 
197
            throw new NoSuchElementException("AggregateHashtableEnumerator");
 
198
        }
 
199
        return _curEnum.nextElement();
 
200
    }
 
201
}