From 3360705577c8bb82d31e593cc5890aebeca063c1 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 05 Sep 2007 22:57:40 +0000
Subject: [PATCH] Improvements to the server-side constraint violation APIs. Now there are just two server-side constraint enforcement call-backs: isUsable and isDeleteAllowed. The first is invoked whenever a managed object is decoded (except in the case where it's about to be deleted). The second is invoked whenever a managed object is about to be deleted. With this change we will now detect constraint violations during server initialization, not just when config change/add/delete events occur.
---
opends/src/server/org/opends/server/admin/server/ServerManagedObject.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/admin/server/ServerManagedObject.java b/opends/src/server/org/opends/server/admin/server/ServerManagedObject.java
index 0c527d8..c18c976 100644
--- a/opends/src/server/org/opends/server/admin/server/ServerManagedObject.java
+++ b/opends/src/server/org/opends/server/admin/server/ServerManagedObject.java
@@ -29,9 +29,12 @@
+import static org.opends.messages.AdminMessages.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.util.StaticUtils.*;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
@@ -40,6 +43,7 @@
import org.opends.messages.AdminMessages;
import org.opends.messages.Message;
import org.opends.server.admin.Configuration;
+import org.opends.server.admin.Constraint;
import org.opends.server.admin.InstantiableRelationDefinition;
import org.opends.server.admin.ManagedObjectDefinition;
import org.opends.server.admin.ManagedObjectPath;
@@ -536,6 +540,25 @@
ConfigChangeListener adaptor = new ConfigChangeListenerAdaptor<S>(path,
listener);
configEntry.registerChangeListener(adaptor);
+
+ // Change listener registration usually signifies that a managed
+ // object has been accepted and added to the server configuration
+ // either during initialization post-add.
+
+ // FIXME: we should prevent multiple invocations in the case where
+ // multiple change listeners are registered for the same object.
+ for (Constraint constraint : definition.getAllConstraints()) {
+ for (ServerConstraintHandler handler : constraint
+ .getServerConstraintHandlers()) {
+ try {
+ handler.performPostAdd(this);
+ } catch (ConfigException e) {
+ if (debugEnabled()) {
+ TRACER.debugCaught(DebugLogLevel.ERROR, e);
+ }
+ }
+ }
+ }
}
@@ -601,6 +624,41 @@
/**
+ * Determines whether or not this managed object can be used by the
+ * server.
+ *
+ * @throws ConstraintViolationException
+ * If one or more constraints determined that this managed
+ * object cannot be used by the server.
+ */
+ void ensureIsUsable() throws ConstraintViolationException {
+ // Enforce any constraints.
+ boolean isUsable = true;
+ List<Message> reasons = new LinkedList<Message>();
+ for (Constraint constraint : definition.getAllConstraints()) {
+ for (ServerConstraintHandler handler : constraint
+ .getServerConstraintHandlers()) {
+ try {
+ if (!handler.isUsable(this, reasons)) {
+ isUsable = false;
+ }
+ } catch (ConfigException e) {
+ Message message = ERR_SERVER_CONSTRAINT_EXCEPTION.get(e
+ .getMessageObject());
+ reasons.add(message);
+ isUsable = false;
+ }
+ }
+ }
+
+ if (!isUsable) {
+ throw new ConstraintViolationException(this, reasons);
+ }
+ }
+
+
+
+ /**
* Update the config entry associated with this server managed
* object. This is only intended to be used by change listener call
* backs in order to update the managed object with the correct
--
Gitblit v1.10.0