1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
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
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.
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.
20
* END COPYRIGHT BLOCK **/
21
package com.netscape.management.admserv.panel;
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.*;
32
* @version 0.1 01/15/98
33
* @author miodrag@netscape.com
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.
41
public class CGIAggregateDataModel implements IConfigDataModel {
42
private static String _clazz = "CGIAggregateDataModel";
43
protected Hashtable _CGIs;
44
protected String _modelName;
45
protected ConsoleInfo _consoleInfo;
47
public CGIAggregateDataModel(ConsoleInfo consoleInfo) {
48
_CGIs = new Hashtable();
49
_consoleInfo = consoleInfo;
52
public void add(String prefix, CGIDataModel cgi) {
53
_CGIs.put(prefix, cgi);
56
public void remove(String prefix) {
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);
68
public IConfigDataModel getCGI(String prefix) {
69
return (IConfigDataModel)_CGIs.get(prefix);
72
protected String getAttrPrefix (String attrName) {
73
int dot = attrName.indexOf('.');
75
return attrName.substring(0, dot);
77
Debug.println("dot not found in " + attrName);
82
public String getAttribute(String attr) {
83
//Debug.println("ATTR=" + attr + " PREFIX=" + getAttrPrefix(attr));
84
IConfigDataModel cgi =
85
(IConfigDataModel)_CGIs.get(getAttrPrefix(attr));
87
return cgi.getAttribute(attr);
89
Debug.println(_clazz +
90
".getAttribute() CGI for the attr " + attr + " not in data model");
95
public void setAttribute(String attr,
96
String val) throws ValidationException {
97
IConfigDataModel cgi =
98
(IConfigDataModel)_CGIs.get(getAttrPrefix(attr));
100
cgi.setAttribute(attr, val);
102
Debug.println(_clazz +
103
".setAttribute() CGI for the attr " + attr + " not in data model");
107
public Enumeration getAttributes() {
108
// to do implement AggregateEnumerator
109
return new CGIAggregateEnumerator(_CGIs);
112
public boolean isLoaded() {
113
for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
114
IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
115
if (!cgi.isLoaded()) {
122
public boolean isModified() {
123
for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
124
IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
125
if (cgi.isModified()) {
136
public void load() throws RemoteRequestException {
137
for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
138
IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
139
if (!cgi.isLoaded()) {
146
* Save all modified CGIs
148
public void save() throws RemoteRequestException {
149
for (Enumeration e = _CGIs.elements(); e.hasMoreElements();) {
150
IConfigDataModel cgi = (IConfigDataModel) e.nextElement();
151
if (cgi.isModified()) {
157
public String getModelName() {
158
return CGIDataModel.getServerName(_consoleInfo);
161
public ConsoleInfo getConsoleInfo() {
169
* An enumerator class for a hashtable of CGIDataModels
171
class CGIAggregateEnumerator implements Enumeration {
173
Hashtable _aggregateTable;
174
Enumeration _aggregateEnum;
175
Enumeration _curEnum;
177
CGIAggregateEnumerator(Hashtable aggregateTable) {
178
_aggregateTable = aggregateTable;
179
_aggregateEnum = _aggregateTable.elements();
182
public boolean hasMoreElements() {
183
if (_curEnum == null || !_curEnum.hasMoreElements()) {
184
if (!_aggregateEnum.hasMoreElements()) {
188
CGIDataModel curTable =
189
(CGIDataModel)_aggregateEnum.nextElement();
190
_curEnum = curTable.getAttributes();
192
return _curEnum.hasMoreElements();
195
public Object nextElement() {
196
if (_curEnum == null) {
197
throw new NoSuchElementException("AggregateHashtableEnumerator");
199
return _curEnum.nextElement();