| | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.forgerock.opendj.config.AbsoluteInheritedDefaultBehaviorProvider; |
| | | import org.forgerock.opendj.config.AbstractManagedObjectDefinition; |
| | | import org.forgerock.opendj.config.AliasDefaultBehaviorProvider; |
| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.forgerock.opendj.util.StaticUtils; |
| | | |
| | | /** |
| | | * An adaptor class which converts {@link ConfigChangeListener} call-backs to |
| | |
| | | * The type of property. |
| | | */ |
| | | private static final class Visitor<T> implements DefaultBehaviorProviderVisitor<T, Void, ManagedObjectPath<?, ?>> { |
| | | |
| | | /** |
| | | * Finds the dependencies associated with the provided property |
| | | * definition. |
| | |
| | | this.dependencies = dependencies; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Void visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) { |
| | | ManagedObjectPath<?, ?> next = d.getManagedObjectPath(); |
| | | dependencies.add(DNBuilder.create(next)); |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Void visitAlias(AliasDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) { |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Void visitDefined(DefinedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) { |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Void visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) { |
| | | ManagedObjectPath<?, ?> next = d.getManagedObjectPath(p); |
| | | dependencies.add(DNBuilder.create(next)); |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Void visitUndefined(UndefinedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) { |
| | | return null; |
| | | } |
| | |
| | | /** Cached managed object between accept/apply call-backs. */ |
| | | private ServerManagedObject<? extends S> cachedManagedObject; |
| | | |
| | | /** |
| | | * The delete listener which is used to remove this listener and any |
| | | * dependencies. |
| | | */ |
| | | /** The delete listener which is used to remove this listener and any dependencies. */ |
| | | private final ConfigDeleteListener cleanerListener; |
| | | |
| | | /** The names of entries that this change listener depends on. */ |
| | | private final Set<DN> dependencies; |
| | | |
| | | /** |
| | | * The listener used to notify this listener when dependency entries are |
| | | * modified. |
| | | */ |
| | | /** The listener used to notify this listener when dependency entries are modified. */ |
| | | private final ConfigChangeListener dependencyListener; |
| | | |
| | | /** The DN associated with this listener. */ |
| | |
| | | this.dependencies = new HashSet<>(); |
| | | this.dependencyListener = new ConfigChangeListener() { |
| | | |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(Entry configEntry) { |
| | | Entry dependentConfigEntry = getConfigEntry(dn); |
| | | if (dependentConfigEntry != null) { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean configChangeIsAcceptable(Entry configEntry, LocalizableMessageBuilder unacceptableReason) { |
| | | Entry dependentConfigEntry = getConfigEntry(dn); |
| | | if (dependentConfigEntry != null) { |
| | |
| | | } |
| | | } |
| | | |
| | | // Register a delete listener against the parent which will |
| | | // finalize this change listener when the monitored configuration |
| | | // entry is removed. |
| | | // Register a delete listener against the parent which will finalize |
| | | // this change listener when the monitored configuration entry is removed |
| | | this.cleanerListener = new ConfigDeleteListener() { |
| | | |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationDelete(Entry configEntry) { |
| | | // Perform finalization if the deleted entry is the monitored |
| | | // entry. |
| | |
| | | return new ConfigChangeResult(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean configDeleteIsAcceptable(Entry configEntry, LocalizableMessageBuilder unacceptableReason) { |
| | | // Always acceptable. |
| | | return true; |
| | | } |
| | | |
| | | }; |
| | | |
| | | DN parent = dn.parent(); |
| | | if (parent != null) { |
| | | if (parent != null && !parent.isRootDN()) { |
| | | Entry configEntry = getConfigEntry(dn.parent()); |
| | | if (configEntry != null) { |
| | | configRepository.registerDeleteListener(configEntry.getName(), cleanerListener); |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(Entry configEntry) { |
| | | // Looking at the ConfigFileHandler implementation reveals |
| | | // that this ConfigEntry will actually be a different object to |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean configChangeIsAcceptable(Entry configEntry, LocalizableMessageBuilder unacceptableReason) { |
| | | return configChangeIsAcceptable(configEntry, unacceptableReason, configEntry); |
| | | } |
| | |
| | | if (parentConfigEntry != null) { |
| | | configRepository.deregisterDeleteListener(parentConfigEntry.getName(), cleanerListener); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | return listener; |
| | | } |
| | | |
| | | /** |
| | | * Returns the named configuration entry or null if it could not be |
| | | * retrieved. |
| | | */ |
| | | /** Returns the named configuration entry or null if it could not be retrieved. */ |
| | | private Entry getConfigEntry(DN dn) { |
| | | try { |
| | | if (configRepository.hasEntry(dn)) { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |