From 994aade8f6eee89d18ed76128feb18447f797ce4 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Sun, 02 Sep 2007 16:30:55 +0000
Subject: [PATCH] Minor refactoring of the admin driver API. Remove the hasManagedObject methods and replace them with a single managedObjectExists method. This will be more useful and more simple for dependency call-backs.
---
opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPDriver.java | 69 +++++++----------
opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/AbstractManagedObject.java | 10 +-
opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/Driver.java | 114 ++++++----------------------
opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPManagedObject.java | 9 +
4 files changed, 64 insertions(+), 138 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPDriver.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPDriver.java
index 481e8c0..497f100 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPDriver.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPDriver.java
@@ -119,7 +119,7 @@
AuthorizationException, CommunicationException {
validateRelationDefinition(parent, rd);
- if (!entryExists(parent)) {
+ if (!managedObjectExists(parent)) {
throw new ManagedObjectNotFoundException();
}
@@ -140,7 +140,7 @@
CommunicationException {
validateRelationDefinition(parent, rd);
- if (!entryExists(parent)) {
+ if (!managedObjectExists(parent)) {
throw new ManagedObjectNotFoundException();
}
@@ -158,7 +158,7 @@
ManagedObjectPath<C, S> path) throws DefinitionDecodingException,
ManagedObjectDecodingException, ManagedObjectNotFoundException,
AuthorizationException, CommunicationException {
- if (!entryExists(path)) {
+ if (!managedObjectExists(path)) {
throw new ManagedObjectNotFoundException();
}
@@ -232,7 +232,7 @@
DefinitionDecodingException, AuthorizationException,
ManagedObjectNotFoundException, CommunicationException,
PropertyException {
- if (!entryExists(path)) {
+ if (!managedObjectExists(path)) {
throw new ManagedObjectNotFoundException();
}
@@ -290,26 +290,6 @@
*/
@Override
public <C extends ConfigurationClient, S extends Configuration>
- boolean hasManagedObject(
- ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd)
- throws IllegalArgumentException, ManagedObjectNotFoundException,
- AuthorizationException, CommunicationException {
- validateRelationDefinition(parent, rd);
-
- if (!entryExists(parent)) {
- throw new ManagedObjectNotFoundException();
- }
-
- return entryExists(parent.child(rd));
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public <C extends ConfigurationClient, S extends Configuration>
String[] listManagedObjects(
ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd,
AbstractManagedObjectDefinition<? extends C, ? extends S> d)
@@ -317,7 +297,7 @@
AuthorizationException, CommunicationException {
validateRelationDefinition(parent, rd);
- if (!entryExists(parent)) {
+ if (!managedObjectExists(parent)) {
throw new ManagedObjectNotFoundException();
}
@@ -351,6 +331,29 @@
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean managedObjectExists(ManagedObjectPath<?, ?> path)
+ throws ManagedObjectNotFoundException, AuthorizationException,
+ CommunicationException {
+ if (path.isEmpty()) {
+ return true;
+ }
+
+ ManagedObjectPath<?,?> parent = path.parent();
+ LdapName dn = LDAPNameBuilder.create(parent, profile);
+ if (!entryExists(dn)) {
+ throw new ManagedObjectNotFoundException();
+ }
+
+ dn = LDAPNameBuilder.create(path, profile);
+ return entryExists(dn);
+ }
+
+
+
+ /**
* Adapts a naming exception to an appropriate admin client
* exception.
*
@@ -499,20 +502,6 @@
- // Determines whether the LDAP entry associated with the managed
- // object path exists.
- private boolean entryExists(ManagedObjectPath<?, ?> path)
- throws CommunicationException, AuthorizationException {
- if (path.isEmpty()) {
- return true;
- }
-
- LdapName dn = LDAPNameBuilder.create(path, profile);
- return entryExists(dn);
- }
-
-
-
// Determine the type of managed object associated with the named
// entry.
private <C extends ConfigurationClient, S extends Configuration>
@@ -561,7 +550,7 @@
private boolean removeManagedObject(ManagedObjectPath<?, ?> path)
throws CommunicationException, AuthorizationException,
OperationRejectedException, ManagedObjectNotFoundException {
- if (!entryExists(path)) {
+ if (!managedObjectExists(path)) {
return false;
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPManagedObject.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPManagedObject.java
index fbdf4df..e74232a 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPManagedObject.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/ldap/LDAPManagedObject.java
@@ -45,6 +45,7 @@
import org.opends.server.admin.InstantiableRelationDefinition;
import org.opends.server.admin.ManagedObjectAlreadyExistsException;
import org.opends.server.admin.ManagedObjectDefinition;
+import org.opends.server.admin.ManagedObjectNotFoundException;
import org.opends.server.admin.ManagedObjectPath;
import org.opends.server.admin.PropertyDefinition;
import org.opends.server.admin.PropertyOption;
@@ -133,11 +134,13 @@
// First make sure that the parent managed object still exists.
ManagedObjectPath<?, ?> path = getManagedObjectPath();
ManagedObjectPath<?, ?> parent = path.parent();
- if (!parent.isEmpty()) {
- LdapName dn = LDAPNameBuilder.create(parent, driver.getLDAPProfile());
- if (!driver.entryExists(dn)) {
+
+ try {
+ if (!driver.managedObjectExists(parent)) {
throw new ConcurrentModificationException();
}
+ } catch (ManagedObjectNotFoundException e) {
+ throw new ConcurrentModificationException();
}
// We may need to create the parent "relation" entry if this is a
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/AbstractManagedObject.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/AbstractManagedObject.java
index 5e9c9c2..44480e0 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/AbstractManagedObject.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/AbstractManagedObject.java
@@ -342,7 +342,7 @@
validateRelationDefinition(r);
Driver ctx = getDriver();
try {
- return ctx.hasManagedObject(path, r);
+ return ctx.managedObjectExists(path.child(r));
} catch (ManagedObjectNotFoundException e) {
throw new ConcurrentModificationException();
}
@@ -668,11 +668,9 @@
Driver ctx = getDriver();
try {
- ctx.getManagedObject(path);
- } catch (DefinitionDecodingException e) {
- // Ignore.
- } catch (ManagedObjectDecodingException e) {
- // Ignore.
+ if (!ctx.managedObjectExists(path)) {
+ throw new ConcurrentModificationException();
+ }
} catch (ManagedObjectNotFoundException e) {
throw new ConcurrentModificationException();
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/Driver.java b/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/Driver.java
index d26004d..354f2aa 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/Driver.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/admin/client/spi/Driver.java
@@ -29,8 +29,6 @@
-import static org.opends.server.util.StaticUtils.*;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -509,93 +507,6 @@
/**
- * Determines whether or not the named parent managed object has the
- * named instantiable child managed object.
- *
- * @param <C>
- * The type of client managed object configuration that the
- * relation definition refers to.
- * @param <S>
- * The type of server managed object configuration that the
- * relation definition refers to.
- * @param parent
- * The path of the parent managed object.
- * @param rd
- * The instantiable relation definition.
- * @param name
- * The name of the child managed object.
- * @return Returns <code>true</code> if the named instantiable
- * child managed object exists, <code>false</code>
- * otherwise.
- * @throws IllegalArgumentException
- * If the relation definition is not associated with the
- * parent managed object's definition.
- * @throws ManagedObjectNotFoundException
- * If the parent managed object could not be found.
- * @throws AuthorizationException
- * If the server refuses to make the determination because
- * the client does not have the correct privileges.
- * @throws CommunicationException
- * If the client cannot contact the server due to an
- * underlying communication problem.
- */
- public final <C extends ConfigurationClient, S extends Configuration>
- boolean hasManagedObject(
- ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd,
- String name) throws IllegalArgumentException,
- ManagedObjectNotFoundException, AuthorizationException,
- CommunicationException {
- // FIXME: use naming properties for comparison where available.
- String[] children = listManagedObjects(parent, rd);
- String nname = toLowerCase(name.trim().replaceAll(" +", " "));
- for (String child : children) {
- if (nname.equals(toLowerCase(child.trim().replaceAll(" +", " ")))) {
- return true;
- }
- }
-
- return false;
- }
-
-
-
- /**
- * Determines whether or not the named parent managed object has an
- * optional child managed object.
- *
- * @param <C>
- * The type of client managed object configuration that the
- * relation definition refers to.
- * @param <S>
- * The type of server managed object configuration that the
- * relation definition refers to.
- * @param parent
- * The path of the parent managed object.
- * @param rd
- * The optional relation definition.
- * @return Returns <code>true</code> if the optional child managed
- * object exists, <code>false</code> otherwise.
- * @throws IllegalArgumentException
- * If the relation definition is not associated with the
- * parent managed object's definition.
- * @throws ManagedObjectNotFoundException
- * If the parent managed object could not be found.
- * @throws AuthorizationException
- * If the server refuses to make the determination because
- * the client does not have the correct privileges.
- * @throws CommunicationException
- * If the client cannot contact the server due to an
- * underlying communication problem.
- */
- public abstract <C extends ConfigurationClient, S extends Configuration>
- boolean hasManagedObject(
- ManagedObjectPath<?, ?> parent, OptionalRelationDefinition<C, S> rd)
- throws IllegalArgumentException, ManagedObjectNotFoundException,
- AuthorizationException, CommunicationException;
-
-
-
- /**
* Lists the child managed objects of the named parent managed
* object.
*
@@ -675,6 +586,31 @@
/**
+ * Determines whether or not the named managed object exists.
+ * <p>
+ * Implementations should always return <code>true</code> when the
+ * provided path is empty.
+ *
+ * @param path
+ * The path of the named managed object.
+ * @return Returns <code>true</code> if the named managed object
+ * exists, <code>false</code> otherwise.
+ * @throws ManagedObjectNotFoundException
+ * If the parent managed object could not be found.
+ * @throws AuthorizationException
+ * If the server refuses to make the determination because
+ * the client does not have the correct privileges.
+ * @throws CommunicationException
+ * If the client cannot contact the server due to an
+ * underlying communication problem.
+ */
+ public abstract boolean managedObjectExists(ManagedObjectPath<?, ?> path)
+ throws ManagedObjectNotFoundException, AuthorizationException,
+ CommunicationException;
+
+
+
+ /**
* Gets the default values for the specified property.
*
* @param <PD>
--
Gitblit v1.10.0