From b97785a371b09a674dbef8029a99a730ee928e8d Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 19 Dec 2007 09:55:26 +0000
Subject: [PATCH] Fix for issue 2446 part #1.
---
opends/src/server/org/opends/server/admin/InstantiableRelationDefinition.java | 101 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 91 insertions(+), 10 deletions(-)
diff --git a/opends/src/server/org/opends/server/admin/InstantiableRelationDefinition.java b/opends/src/server/org/opends/server/admin/InstantiableRelationDefinition.java
index 229ca16..7097e52 100644
--- a/opends/src/server/org/opends/server/admin/InstantiableRelationDefinition.java
+++ b/opends/src/server/org/opends/server/admin/InstantiableRelationDefinition.java
@@ -32,7 +32,11 @@
import static org.opends.server.util.Validator.*;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
@@ -62,16 +66,21 @@
* The type of server managed object configuration that
* this relation definition refers to.
*/
- public static class Builder
+ public static final class Builder
<C extends ConfigurationClient, S extends Configuration>
extends AbstractBuilder<C, S, InstantiableRelationDefinition<C, S>> {
// The optional naming property definition.
- private PropertyDefinition<?> namingPropertyDefinition;
+ private PropertyDefinition<?> namingPropertyDefinition = null;
// The plural name of the relation.
private final String pluralName;
+ // The optional default managed objects associated with this
+ // instantiable relation definition.
+ private final Map<String, DefaultManagedObject<? extends C, ? extends S>>
+ defaultManagedObjects = new HashMap<String,
+ DefaultManagedObject<? extends C, ? extends S>>();
/**
@@ -96,6 +105,22 @@
/**
+ * Adds the named default managed object to this instantiable
+ * relation definition.
+ *
+ * @param name
+ * The name of the default managed object.
+ * @param defaultManagedObject
+ * The default managed object.
+ */
+ public void setDefaultManagedObject(String name,
+ DefaultManagedObject<? extends C, ? extends S> defaultManagedObject) {
+ this.defaultManagedObjects.put(name, defaultManagedObject);
+ }
+
+
+
+ /**
* Sets the naming property for the instantiable relation
* definition.
*
@@ -104,7 +129,7 @@
* which should be used for naming, or <code>null</code>
* if this relation does not use a property for naming.
*/
- public final void setNamingProperty(
+ public void setNamingProperty(
PropertyDefinition<?> namingPropertyDefinition) {
ensureNotNull(namingPropertyDefinition);
this.namingPropertyDefinition = namingPropertyDefinition;
@@ -119,7 +144,7 @@
protected InstantiableRelationDefinition<C, S> buildInstance(
Common<C, S> common) {
return new InstantiableRelationDefinition<C, S>(common, pluralName,
- namingPropertyDefinition);
+ namingPropertyDefinition, defaultManagedObjects);
}
}
@@ -130,14 +155,23 @@
// The plural name of the relation.
private final String pluralName;
+ // The optional default managed objects associated with this
+ // instantiable relation definition.
+ private final Map<String, DefaultManagedObject<? extends C, ? extends S>>
+ defaultManagedObjects;
+
// Private constructor.
private InstantiableRelationDefinition(Common<C, S> common,
- String pluralName, PropertyDefinition<?> namingPropertyDefinition) {
+ String pluralName,
+ PropertyDefinition<?> namingPropertyDefinition,
+ Map<String, DefaultManagedObject<? extends C, ? extends S>>
+ defaultManagedObjects) {
super(common);
this.pluralName = pluralName;
this.namingPropertyDefinition = namingPropertyDefinition;
+ this.defaultManagedObjects = defaultManagedObjects;
}
@@ -153,6 +187,41 @@
/**
+ * Gets the named default managed object associated with this
+ * instantiable relation definition.
+ *
+ * @param name
+ * The name of the default managed object.
+ * @return Returns the named default managed object.
+ * @throws IllegalArgumentException
+ * If there is no default managed object associated with
+ * the provided name.
+ */
+ public DefaultManagedObject<? extends C, ? extends S> getDefaultManagedObject(
+ String name) throws IllegalArgumentException {
+ if (!defaultManagedObjects.containsKey(name)) {
+ throw new IllegalArgumentException(
+ "unrecognized default managed object \"" + name + "\"");
+ }
+ return defaultManagedObjects.get(name);
+ }
+
+
+
+ /**
+ * Gets the names of the default managed objects associated with
+ * this instantiable relation definition.
+ *
+ * @return Returns an unmodifiable set containing the names of the
+ * default managed object.
+ */
+ public Set<String> getDefaultManagedObjectNames() {
+ return Collections.unmodifiableSet(defaultManagedObjects.keySet());
+ }
+
+
+
+ /**
* Get the property of the child managed object definition which
* should be used for naming children.
*
@@ -161,7 +230,7 @@
* <code>null</code> if this relation does not use a
* property for naming.
*/
- public final PropertyDefinition<?> getNamingPropertyDefinition() {
+ public PropertyDefinition<?> getNamingPropertyDefinition() {
return namingPropertyDefinition;
}
@@ -172,7 +241,7 @@
*
* @return Returns the plural name of the relation.
*/
- public final String getPluralName() {
+ public String getPluralName() {
return pluralName;
}
@@ -185,7 +254,7 @@
* @return Returns the user friendly plural name of this relation
* definition in the default locale.
*/
- public final Message getUserFriendlyPluralName() {
+ public Message getUserFriendlyPluralName() {
return getUserFriendlyPluralName(Locale.getDefault());
}
@@ -200,7 +269,7 @@
* @return Returns the user friendly plural name of this relation
* definition in the specified locale.
*/
- public final Message getUserFriendlyPluralName(Locale locale) {
+ public Message getUserFriendlyPluralName(Locale locale) {
String property = "relation." + getName() + ".user-friendly-plural-name";
return ManagedObjectDefinitionI18NResource.getInstance().getMessage(
getParentDefinition(), property, locale);
@@ -212,7 +281,7 @@
* {@inheritDoc}
*/
@Override
- public final void toString(StringBuilder builder) {
+ public void toString(StringBuilder builder) {
builder.append("name=");
builder.append(getName());
builder.append(" type=composition parent=");
@@ -223,4 +292,16 @@
builder.append(getChildDefinition().getName());
builder.append(" minOccurs=0");
}
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void initialize() throws Exception {
+ for (DefaultManagedObject<?, ?> dmo : defaultManagedObjects.values()) {
+ dmo.initialize();
+ }
+ }
}
--
Gitblit v1.10.0