1 package org
.argeo
.util
.directory
.ldap
;
3 import javax
.naming
.directory
.Attributes
;
4 import javax
.naming
.ldap
.LdapName
;
6 public abstract class AbstractLdapEntry
implements LdapEntry
{
7 private final AbstractLdapDirectory directory
;
9 private final LdapName dn
;
11 private Attributes publishedAttributes
;
13 protected AbstractLdapEntry(AbstractLdapDirectory userAdmin
, LdapName dn
, Attributes attributes
) {
14 this.directory
= userAdmin
;
16 this.publishedAttributes
= attributes
;
20 public LdapName
getDn() {
24 public synchronized Attributes
getAttributes() {
25 return isEditing() ?
getModifiedAttributes() : publishedAttributes
;
28 /** Should only be called from working copy thread. */
29 protected synchronized Attributes
getModifiedAttributes() {
30 assert getWc() != null;
31 return getWc().getModifiedData().get(getDn());
34 protected synchronized boolean isEditing() {
35 return getWc() != null && getModifiedAttributes() != null;
38 private synchronized LdapEntryWorkingCopy
getWc() {
39 return directory
.getWorkingCopy();
42 protected synchronized void startEditing() {
44 // throw new IllegalStateException("Cannot edit frozen view");
45 if (directory
.isReadOnly())
46 throw new IllegalStateException("User directory is read-only");
47 assert getModifiedAttributes() == null;
48 getWc().startEditing(this);
49 // modifiedAttributes = (Attributes) publishedAttributes.clone();
52 public synchronized void publishAttributes(Attributes modifiedAttributes
) {
53 publishedAttributes
= modifiedAttributes
;
56 protected AbstractLdapDirectory
getDirectory() {
61 public int hashCode() {
66 public boolean equals(Object obj
) {
69 if (obj
instanceof LdapEntry
) {
70 LdapEntry that
= (LdapEntry
) obj
;
71 return this.dn
.equals(that
.getDn());
77 public String
toString() {