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 modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* END COPYRIGHT BLOCK **/
19
/* ConfigEntry.java - class that implements a standalone
23
package com.netscape.admin.dirserv.panel;
25
import netscape.ldap.*;
28
public class ConfigEntry {
29
public ConfigEntry (String dn, LDAPConnection ldc){
34
public void addAttribute (String attrName, DSEntry dsEntry){
35
_attrTable.put (attrName, dsEntry);
38
public void setAddAttributes (/*LDAPAttributeSet*/LDAPAttribute[] attrSet){
42
public void read () throws LDAPException{
50
LDAPEntry entry = null;
52
/* get the list of attributes we are interested in */
53
size = _attrTable.size ();
56
/* ONREPL print warning */
60
attrs = new String [size];
62
keys = _attrTable.keys ();
64
while (keys.hasMoreElements()) {
65
attrs [i] = (String)keys.nextElement();
71
entry = _ldc.read (_configDN, attrs);
72
} catch (LDAPException lde){
73
if (lde.getLDAPResultCode() != lde.NO_SUCH_OBJECT)
79
/* update correspondent form fields */
80
keys = _attrTable.keys ();
81
while (keys.hasMoreElements()) {
82
name = (String)keys.nextElement ();
83
dsEntry = (DSEntry)_attrTable.get (name);
85
lda = entry.getAttribute (name);
86
dsEntry.remoteToLocal(lda.getStringValues());
89
dsEntry.remoteToLocal("");
95
public void write () throws LDAPException{
96
/* we are adding new entry */
97
if (_configEntry == null)
98
_configEntry = addEntry ();
103
public void delete () throws LDAPException{
105
_ldc.delete (_configDN);
108
private LDAPEntry addEntry () throws LDAPException{
111
LDAPAttributeSet attrs;
119
if (_addAttrs != null)
120
attrs = new LDAPAttributeSet (_addAttrs);
122
attrs = new LDAPAttributeSet ();
124
keys = _attrTable.keys ();
125
while (keys.hasMoreElements ()){
126
name = (String)(keys.nextElement ());
127
dsEntry = (DSEntry)_attrTable.get (name);
129
values = dsEntry.localToRemote ();
130
attr = new LDAPAttribute (name, values);
134
entry = new LDAPEntry (_configDN, attrs);
138
}catch (LDAPException lde){
139
entry = null; /* help garbage collection */
143
/* reset DSEntries */
144
entries = _attrTable.elements ();
145
while (entries.hasMoreElements ()){
146
dsEntry = (DSEntry)entries.nextElement ();
154
private void modifyEntry () throws LDAPException{
155
LDAPModificationSet mods;
163
mods = new LDAPModificationSet ();
165
keys = _attrTable.keys ();
166
while (keys.hasMoreElements ()){
167
name = (String)(keys.nextElement ());
168
dsEntry = (DSEntry)_attrTable.get (name);
170
if (dsEntry.getDirty()){
171
values = dsEntry.localToRemote ();
172
attr = new LDAPAttribute (name, values);
173
mods.add(LDAPModification.REPLACE, attr);
178
_ldc.modify (_configDN, mods);
179
}catch (LDAPException lde){
183
/* reset DSEntries */
184
entries = _attrTable.elements ();
185
while (entries.hasMoreElements ()){
186
dsEntry = (DSEntry)entries.nextElement ();
192
private LDAPEntry _configEntry = null;
193
private String _configDN;
194
private LDAPConnection _ldc;
195
/* attributes that should be part of the entry when it added as
196
opposed to modified, like object class
198
private /*LDAPAttributeSet*/ LDAPAttribute[] _addAttrs = null;
199
private Hashtable _attrTable = new Hashtable();