From 07541fa5b77a51759b23eac2308255651eb5cd93 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 06 Sep 2007 00:26:13 +0000
Subject: [PATCH] Add partial support for performing server-side referential integrity. This change adds a constraint which prevents configuration of dangling references. A subsequent change will add a constraint which will prevent removal of referenced components.
---
opends/src/server/org/opends/server/admin/AggregationPropertyDefinition.java | 120 +++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 99 insertions(+), 21 deletions(-)
diff --git a/opends/src/server/org/opends/server/admin/AggregationPropertyDefinition.java b/opends/src/server/org/opends/server/admin/AggregationPropertyDefinition.java
index 56bbccc..35f235f 100644
--- a/opends/src/server/org/opends/server/admin/AggregationPropertyDefinition.java
+++ b/opends/src/server/org/opends/server/admin/AggregationPropertyDefinition.java
@@ -28,10 +28,20 @@
+import static org.opends.messages.AdminMessages.*;
import static org.opends.server.util.Validator.*;
+import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
+import java.util.SortedSet;
+import org.opends.messages.Message;
+import org.opends.server.admin.client.ClientConstraintHandler;
+import org.opends.server.admin.server.ServerConstraintHandler;
+import org.opends.server.admin.server.ServerManagedObject;
+import org.opends.server.admin.server.ServerManagementContext;
+import org.opends.server.config.ConfigException;
import org.opends.server.types.DN;
@@ -78,7 +88,7 @@
*/
public final class AggregationPropertyDefinition
<C extends ConfigurationClient, S extends Configuration>
- extends PropertyDefinition<String> {
+ extends PropertyDefinition<String> implements Constraint {
/**
* An interface for incrementally constructing aggregation property
@@ -95,6 +105,9 @@
<C extends ConfigurationClient, S extends Configuration>
extends AbstractBuilder<String, AggregationPropertyDefinition<C, S>> {
+ // The type of referenced managed objects.
+ private AbstractManagedObjectDefinition<?, ?> cd = null;
+
// The name of the managed object which is the parent of the
// aggregated managed objects.
private ManagedObjectPath<?, ?> p = null;
@@ -103,9 +116,6 @@
// contains the aggregated managed objects.
private String rdName = null;
- // The type of referenced managed objects.
- private AbstractManagedObjectDefinition<?, ?> cd = null;
-
// The optional name of a boolean "enabled" property in this
// managed object. When this property is true, the enabled
// property in the aggregated managed object must also be true.
@@ -127,6 +137,23 @@
/**
+ * Sets the definition of the type of referenced managed objects.
+ * <p>
+ * This must be defined before the property definition can be
+ * built.
+ *
+ * @param d
+ * The definition of the type of referenced managed
+ * objects.
+ */
+ public final void setManagedObjectDefinition(
+ AbstractManagedObjectDefinition<C, S> d) {
+ this.cd = d;
+ }
+
+
+
+ /**
* Sets the name of the managed object which is the parent of the
* aggregated managed objects.
* <p>
@@ -161,23 +188,6 @@
/**
- * Sets the definition of the type of referenced managed objects.
- * <p>
- * This must be defined before the property definition can be
- * built.
- *
- * @param d
- * The definition of the type of referenced managed
- * objects.
- */
- public final void setManagedObjectDefinition(
- AbstractManagedObjectDefinition<C, S> d) {
- this.cd = d;
- }
-
-
-
- /**
* Sets the optional boolean "enabled" property in this managed
* object. When this property is true, the enabled property in the
* aggregated managed object must also be true.
@@ -275,6 +285,54 @@
/**
+ * The server-side constraint handler implementation.
+ */
+ private static class ServerHandler
+ <C extends ConfigurationClient, S extends Configuration>
+ extends ServerConstraintHandler {
+
+ // The associated property definition.
+ private final AggregationPropertyDefinition<C, S> pd;
+
+
+
+ // Creates a new server-side constraint handler.
+ private ServerHandler(AggregationPropertyDefinition<C, S> pd) {
+ this.pd = pd;
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isUsable(ServerManagedObject<?> managedObject,
+ Collection<Message> unacceptableReasons) throws ConfigException {
+ SortedSet<String> names = managedObject.getPropertyValues(pd);
+ ServerManagementContext context = ServerManagementContext.getInstance();
+ boolean isUsable = true;
+
+ for (String name : names) {
+ ManagedObjectPath<C, S> path = pd.getChildPath(name);
+ if (!context.managedObjectExists(path)) {
+ Message msg = ERR_SERVER_REFINT_DANGLING_REFERENCE.get(name, pd
+ .getName(), managedObject.getManagedObjectDefinition()
+ .getUserFriendlyName(), managedObject.getDN().toString(), pd
+ .getRelationDefinition().getUserFriendlyName(), path.toDN()
+ .toString());
+ unacceptableReasons.add(msg);
+ isUsable = false;
+ }
+ }
+
+ return isUsable;
+ }
+ }
+
+
+
+ /**
* Creates an aggregation property definition builder.
*
* @param <C>
@@ -405,6 +463,16 @@
/**
+ * {@inheritDoc}
+ */
+ public Collection<ClientConstraintHandler> getClientConstraintHandlers() {
+ // TODO: not yet implemented.
+ return Collections.emptyList();
+ }
+
+
+
+ /**
* Gets the name of the managed object which is the parent of the
* aggregated managed objects.
*
@@ -431,6 +499,16 @@
/**
+ * {@inheritDoc}
+ */
+ public Collection<ServerConstraintHandler> getServerConstraintHandlers() {
+ ServerConstraintHandler handler = new ServerHandler<C, S>(this);
+ return Collections.singleton(handler);
+ }
+
+
+
+ /**
* Gets the optional boolean "enabled" property in this managed
* object. When this property is true, the enabled property in the
* aggregated managed object must also be true.
--
Gitblit v1.10.0