From a063874ec549cf3d4a7ac371991983c6ab1360f0 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 30 May 2007 18:47:25 +0000
Subject: [PATCH] Minor code cleanup (fixed some comments, added a couple of missing default constructors, and removed example client classes).
---
/dev/null | 326 ----------------------------------------------
opends/src/server/org/opends/server/admin/client/ldap/LDAPConnection.java | 4
opends/src/server/org/opends/server/admin/server/ConfigExceptionFactory.java | 2
opends/src/server/org/opends/server/admin/client/ldap/JNDIDirContextAdaptor.java | 4
opends/src/server/org/opends/server/admin/client/ManagementContext.java | 11 +
opends/src/server/org/opends/server/admin/server/ServerManagementContext.java | 25 ++-
6 files changed, 30 insertions(+), 342 deletions(-)
diff --git a/opends/src/server/org/opends/server/admin/client/ExampleClient.java b/opends/src/server/org/opends/server/admin/client/ExampleClient.java
deleted file mode 100644
index 67c9055..0000000
--- a/opends/src/server/org/opends/server/admin/client/ExampleClient.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2006-2007 Sun Microsystems, Inc.
- */
-
-package org.opends.server.admin.client;
-
-
-
-import static org.opends.server.loggers.ErrorLogger.*;
-import static org.opends.server.util.ServerConstants.*;
-
-import java.io.File;
-
-import org.opends.server.admin.AttributeTypePropertyDefinition;
-import org.opends.server.admin.ClassLoaderProvider;
-import org.opends.server.admin.ClassPropertyDefinition;
-import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
-import org.opends.server.admin.client.ldap.LDAPConnection;
-import org.opends.server.admin.client.ldap.LDAPManagementContext;
-import org.opends.server.admin.std.client.ConnectionHandlerCfgClient;
-import org.opends.server.admin.std.client.GlobalCfgClient;
-import org.opends.server.admin.std.client.LDAPConnectionHandlerCfgClient;
-import org.opends.server.admin.std.client.RootCfgClient;
-import org.opends.server.config.ConfigException;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.extensions.ConfigFileHandler;
-import org.opends.server.types.InitializationException;
-
-
-
-/**
- * Sample client code.
- * <p>
- * FIXME: should the configuration client managed object interfaces
- * expose a commit() method?
- * <p>
- * FIXME: should the commit() method take a context parameter or
- * should it be stored inside the managed object.
- * <p>
- * FIXME: should managed objects store their name internally?
- */
-public final class ExampleClient {
-
- /**
- * Private constructor.
- */
- private ExampleClient() {
- // No implementation required.
- }
-
-
-
- /**
- * Boot strap config and schema.
- *
- * @throws InitializationException
- * If the directory server infrastructure could not be
- * initialized.
- * @throws ConfigException
- * If a configuration problem was encountered.
- */
- private void initialize() throws InitializationException,
- ConfigException {
- // Make sure a new instance is created.
- //
- // This is effectively a no-op at the moment, but may do lazy
- // initialization at some point.
- DirectoryServer.getInstance();
-
- // Initialize minimal features such as key syntaxes.
- DirectoryServer.bootstrapClient();
-
- // Many things are dependent on JMX to register an alert
- // generator.
- DirectoryServer.initializeJMX();
-
- removeAllErrorLogPublishers();
-
- // Initialize the configuration.
- File instanceRoot = new File("build/package/OpenDS-0.1");
- File configResourceDirectory = new File(instanceRoot, "config");
- System.setProperty(PROPERTY_SERVER_ROOT, instanceRoot
- .getAbsolutePath());
- File configFile = new File(configResourceDirectory, "config.ldif");
-
- DirectoryServer directoryServer = DirectoryServer.getInstance();
-
- // Bootstrap definition classes.
- ClassLoaderProvider.getInstance().enable();
-
- directoryServer.initializeConfiguration(ConfigFileHandler.class
- .getName(), configFile.getAbsolutePath());
-
- // Initialize and load the schema files.
- DirectoryServer.getInstance().initializeSchema();
-
- // Switch off class name validation in client.
- ClassPropertyDefinition.setAllowClassValidation(false);
-
- // Switch off attribute type name validation in client.
- AttributeTypePropertyDefinition.setCheckSchema(false);
- }
-
-
-
- /**
- * Perform the client operations.
- */
- private void run() throws Exception {
- LDAPConnection connection = JNDIDirContextAdaptor.simpleBind("localhost",
- 1389, "cn=directory manager", "password");
- ManagementContext ctx = LDAPManagementContext.createFromContext(connection);
-
- RootCfgClient root = ctx.getRootConfiguration();
-
- // Modify global server property.
- GlobalCfgClient server = root.getGlobalConfiguration();
- System.out.println("Server check-schema is "
- + server.isCheckSchema());
- System.out.println("Changing to false and re-reading...");
- server.setCheckSchema(false);
- server.commit();
-
- server = root.getGlobalConfiguration();
- System.out.println("Server check-schema is "
- + server.isCheckSchema());
- System.out.println("Changing to true and re-reading...");
- server.setCheckSchema(true);
- server.commit();
-
- server = root.getGlobalConfiguration();
- System.out.println("Server check-schema is "
- + server.isCheckSchema());
-
- // List connection handlers.
- System.out.println("Listing connection handlers...");
- String[] names = root.listConnectionHandlers();
- for (String name : names) {
- ConnectionHandlerCfgClient handler = root
- .getConnectionHandler(name);
-
- System.out.println("Got type=" + handler.definition().getName()
- + ", name=" + name);
- System.out.println("Connection handler is-enabled is "
- + handler.isEnabled());
-
- if (handler instanceof LDAPConnectionHandlerCfgClient) {
- LDAPConnectionHandlerCfgClient lhandler =
- (LDAPConnectionHandlerCfgClient) handler;
- System.out.println("LDAP Connection handler listen-port is "
- + lhandler.getListenPort());
- }
- }
- }
-
-
-
- /**
- * Sample client application.
- *
- * @param args
- * CLI arguments.
- * @throws Exception
- * If a problem occurred.
- */
- public static void main(String[] args) throws Exception {
- ExampleClient client = new ExampleClient();
-
- client.initialize();
- client.run();
- }
-
-}
diff --git a/opends/src/server/org/opends/server/admin/client/ExampleIntrospection.java b/opends/src/server/org/opends/server/admin/client/ExampleIntrospection.java
deleted file mode 100644
index d9dd8fa..0000000
--- a/opends/src/server/org/opends/server/admin/client/ExampleIntrospection.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- * Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- * Portions Copyright 2007 Sun Microsystems, Inc.
- */
-package org.opends.server.admin.client;
-
-
-
-import static org.opends.server.loggers.ErrorLogger.*;
-import static org.opends.server.util.ServerConstants.PROPERTY_SERVER_ROOT;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.opends.server.admin.AbstractManagedObjectDefinition;
-import org.opends.server.admin.AggregationRelationDefinition;
-import org.opends.server.admin.AttributeTypePropertyDefinition;
-import org.opends.server.admin.ClassLoaderProvider;
-import org.opends.server.admin.ClassPropertyDefinition;
-import org.opends.server.admin.InstantiableRelationDefinition;
-import org.opends.server.admin.ManagedObjectDefinition;
-import org.opends.server.admin.OptionalRelationDefinition;
-import org.opends.server.admin.RelationDefinition;
-import org.opends.server.admin.RelationDefinitionVisitor;
-import org.opends.server.admin.SingletonRelationDefinition;
-import org.opends.server.admin.std.meta.RootCfgDefn;
-import org.opends.server.config.ConfigException;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.extensions.ConfigFileHandler;
-import org.opends.server.types.InitializationException;
-
-
-
-/**
- * An example application which uses introspection to output a list of
- * potential CLI sub-commands.
- */
-public final class ExampleIntrospection implements
- RelationDefinitionVisitor<Void, String> {
-
- /**
- * Main application.
- *
- * @param args
- * The command line arguments.
- * @throws ConfigException
- * If there was a configuration problem.
- * @throws InitializationException
- * If there was an initialization problem.
- */
- public static void main(String[] args)
- throws InitializationException, ConfigException {
- ExampleIntrospection app = new ExampleIntrospection();
-
- app.processRootConfiguration();
- }
-
-
-
- // Private constructor.
- private ExampleIntrospection() throws InitializationException,
- ConfigException {
- // Make sure a new instance is created.
- //
- // This is effectively a no-op at the moment, but may do lazy
- // initialization at some point.
- DirectoryServer.getInstance();
-
- // Initialize minimal features such as key syntaxes.
- DirectoryServer.bootstrapClient();
-
- // Many things are dependent on JMX to register an alert
- // generator.
- DirectoryServer.initializeJMX();
-
- removeAllErrorLogPublishers();
-
- // Initialize the configuration.
- File instanceRoot = new File("build/package/OpenDS-0.1");
- File configResourceDirectory = new File(instanceRoot, "config");
- System.setProperty(PROPERTY_SERVER_ROOT, instanceRoot
- .getAbsolutePath());
- File configFile = new File(configResourceDirectory, "config.ldif");
-
- DirectoryServer directoryServer = DirectoryServer.getInstance();
-
- // Bootstrap definition classes.
- ClassLoaderProvider.getInstance().enable();
-
- directoryServer.initializeConfiguration(ConfigFileHandler.class
- .getName(), configFile.getAbsolutePath());
-
- // Initialize and load the schema files.
- DirectoryServer.getInstance().initializeSchema();
-
- // Switch off class name validation in client.
- ClassPropertyDefinition.setAllowClassValidation(false);
-
- // Switch off attribute type name validation in client.
- AttributeTypePropertyDefinition.setCheckSchema(false);
- }
-
-
-
- /**
- * Process the root configuration definition.
- */
- public void processRootConfiguration() {
- RootCfgDefn d = RootCfgDefn.getInstance();
-
- String operands = "";
- for (RelationDefinition<?, ?> r : d.getAllRelationDefinitions()) {
- r.accept(this, operands);
- }
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Void visitAggregation(AggregationRelationDefinition<?, ?> d,
- String p) {
- System.err.println("Found aggregation \"" + d.getName()
- + "\": aggregations are not supported yet");
-
- return null;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Void visitInstantiable(
- InstantiableRelationDefinition<?, ?> d, String p) {
- String operands = p + " NAME";
-
- List<ManagedObjectDefinition<?, ?>> types = getSubTypes(d);
- String typesOption = getSubTypesOption(d, types);
-
- System.out.println("create-" + d.getName() + typesOption
- + operands + " [PROP:VALUE ...]");
- System.out.println("delete-" + d.getName() + operands);
- System.out.println("list-" + d.getPluralName() + p);
- System.out.println("get-" + d.getName() + "-prop" + operands
- + " [PROP ...]");
- System.out.println("set-" + d.getName() + "-prop" + operands
- + " [PROP[+|-]:VALUE ...]");
-
- System.out.println();
-
- // Process relations associated with the referenced definition and
- // its sub-types.
- processRelationDefinition(d, operands);
-
- return null;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Void visitOptional(OptionalRelationDefinition<?, ?> d,
- String p) {
- String name = d.getName();
-
- List<ManagedObjectDefinition<?, ?>> types = getSubTypes(d);
- String typesOption = getSubTypesOption(d, types);
-
- System.out.println("create-" + name + typesOption + p
- + " [PROP:VALUE ...]");
- System.out.println("delete-" + name + p);
- System.out.println("has-" + name + p);
- System.out.println("get-" + name + "-prop" + p + " [PROP ...]");
- System.out.println("set-" + name + "-prop" + p
- + " [PROP[+|-]:VALUE ...]");
-
- System.out.println();
-
- // Process relations associated with the referenced definition and
- // its sub-types.
- processRelationDefinition(d, p);
-
- return null;
- }
-
-
-
- /**
- * {@inheritDoc}
- */
- public Void visitSingleton(SingletonRelationDefinition<?, ?> d,
- String p) {
- String name = d.getName();
-
- System.out.println("get-" + name + "-prop" + p + " [PROP ...]");
- System.out.println("set-" + name + "-prop" + p
- + " [PROP[+|-]:VALUE ...]");
-
- System.out.println();
-
- return null;
- }
-
-
-
- // Get all the possible types that can be associated with a
- // relation.
- private List<ManagedObjectDefinition<?, ?>> getSubTypes(
- RelationDefinition<?, ?> d) {
- List<ManagedObjectDefinition<?, ?>> types =
- new LinkedList<ManagedObjectDefinition<?, ?>>();
- AbstractManagedObjectDefinition<?, ?> ad = d.getChildDefinition();
-
- getSubTypesHelp(ad, types);
-
- return types;
- }
-
-
-
- // Get sub-types helper method.
- private void getSubTypesHelp(
- AbstractManagedObjectDefinition<?, ?> ad,
- List<ManagedObjectDefinition<?, ?>> types) {
- // Add this definition if it is not abstract.
- if (ad instanceof ManagedObjectDefinition<?, ?>) {
- ManagedObjectDefinition<?, ?> d = (ManagedObjectDefinition<?, ?>) ad;
- types.add(d);
- }
-
- // Repeat for children.
- for (AbstractManagedObjectDefinition<?, ?> d : ad.getChildren()) {
- getSubTypesHelp(d, types);
- }
- }
-
-
-
- // Convert a list of sub-types to a "-t" option usage.
- private String getSubTypesOption(RelationDefinition<?, ?> r,
- List<ManagedObjectDefinition<?, ?>> types) {
- AbstractManagedObjectDefinition<?, ?> cd = r.getChildDefinition();
- String base = "";
- if (cd instanceof AbstractManagedObjectDefinition<?, ?>) {
- base = cd.getName();
- }
-
- StringBuilder builder = new StringBuilder();
- builder.append(" -t ");
-
- Iterator<ManagedObjectDefinition<?, ?>> i = types.iterator();
- String suffix = "-" + base;
- while (i.hasNext()) {
- ManagedObjectDefinition<?, ?> d = i.next();
-
- String name = d.getName();
- if (name.equals(cd.getName())) {
- // When the base type is itself instantiable use "generic".
- name = "generic";
- } else if (name.endsWith(suffix)) {
- name = name.substring(0, name.length() - suffix.length());
- }
-
- builder.append(name);
- if (i.hasNext()) {
- builder.append('|');
- }
- }
-
- return builder.toString();
- }
-
-
-
- // Process the relations associated with the managed objects
- // referenced from the specified relation.
- private void processRelationDefinition(RelationDefinition<?, ?> d,
- String operands) {
- AbstractManagedObjectDefinition<?, ?> ad = d.getChildDefinition();
- processManagedObjectDefinition(null, ad, operands);
- }
-
-
-
- // Process the relations of a child managed object definition.
- private void processManagedObjectDefinition(
- AbstractManagedObjectDefinition<?, ?> parent,
- AbstractManagedObjectDefinition<?, ?> child, String operands) {
- for (RelationDefinition<?, ?> r : child.getRelationDefinitions()) {
- r.accept(this, operands);
- }
-
- // Process sub-types.
- for (AbstractManagedObjectDefinition<?, ?> d : child
- .getChildren()) {
- processManagedObjectDefinition(child, d, operands);
- }
- }
-}
diff --git a/opends/src/server/org/opends/server/admin/client/ManagementContext.java b/opends/src/server/org/opends/server/admin/client/ManagementContext.java
index fe93523..f454869 100644
--- a/opends/src/server/org/opends/server/admin/client/ManagementContext.java
+++ b/opends/src/server/org/opends/server/admin/client/ManagementContext.java
@@ -39,6 +39,15 @@
public abstract class ManagementContext {
/**
+ * Creates a new management context.
+ */
+ protected ManagementContext() {
+ // No implementation required.
+ }
+
+
+
+ /**
* Get the root configuration managed object associated with this
* management context.
*
@@ -46,7 +55,7 @@
* with this management context.
*/
public abstract ManagedObject<RootCfgClient>
- getRootConfigurationManagedObject();
+ getRootConfigurationManagedObject();
diff --git a/opends/src/server/org/opends/server/admin/client/ldap/JNDIDirContextAdaptor.java b/opends/src/server/org/opends/server/admin/client/ldap/JNDIDirContextAdaptor.java
index 1200623..9443bdf 100644
--- a/opends/src/server/org/opends/server/admin/client/ldap/JNDIDirContextAdaptor.java
+++ b/opends/src/server/org/opends/server/admin/client/ldap/JNDIDirContextAdaptor.java
@@ -54,8 +54,8 @@
/**
- * An LDAP connection JNDI connection adaptor. This maps LDAP requests
- * onto an underlying JNDI connection context.
+ * An LDAP connection adaptor which maps LDAP requests onto an
+ * underlying JNDI connection context.
*/
public final class JNDIDirContextAdaptor extends LDAPConnection {
diff --git a/opends/src/server/org/opends/server/admin/client/ldap/LDAPConnection.java b/opends/src/server/org/opends/server/admin/client/ldap/LDAPConnection.java
index 8e2adc2..7c34d15 100644
--- a/opends/src/server/org/opends/server/admin/client/ldap/LDAPConnection.java
+++ b/opends/src/server/org/opends/server/admin/client/ldap/LDAPConnection.java
@@ -37,8 +37,8 @@
/**
- * A client connection which is used to perform JNDI-based LDAP
- * operations.
+ * An LDAP connection adaptor interface which is used to perform LDAP
+ * client operations.
* <p>
* This interface is provided in order to make it easier to keep track
* of which JNDI DirContext methods we require and also to facilitate
diff --git a/opends/src/server/org/opends/server/admin/server/ConfigExceptionFactory.java b/opends/src/server/org/opends/server/admin/server/ConfigExceptionFactory.java
index d9a0e7c..c8ab7ed 100644
--- a/opends/src/server/org/opends/server/admin/server/ConfigExceptionFactory.java
+++ b/opends/src/server/org/opends/server/admin/server/ConfigExceptionFactory.java
@@ -41,7 +41,7 @@
/**
* A utility class for converting admin exceptions to config exceptions.
*/
-public final class ConfigExceptionFactory {
+final class ConfigExceptionFactory {
// The singleton instance.
private static final ConfigExceptionFactory INSTANCE =
diff --git a/opends/src/server/org/opends/server/admin/server/ServerManagementContext.java b/opends/src/server/org/opends/server/admin/server/ServerManagementContext.java
index ee0d9d5..2741bb9 100644
--- a/opends/src/server/org/opends/server/admin/server/ServerManagementContext.java
+++ b/opends/src/server/org/opends/server/admin/server/ServerManagementContext.java
@@ -55,16 +55,9 @@
- /**
- * Get the root configuration server managed object associated with
- * this management context.
- *
- * @return Returns the root configuration server managed object
- * associated with this management context.
- */
- public ServerManagedObject<RootCfg>
- getRootConfigurationManagedObject() {
- return ServerManagedObject.getRootManagedObject();
+ // Private constructor.
+ private ServerManagementContext() {
+ // No implementation required.
}
@@ -80,4 +73,16 @@
return getRootConfigurationManagedObject().getConfiguration();
}
+
+
+ /**
+ * Get the root configuration server managed object associated with
+ * this management context.
+ *
+ * @return Returns the root configuration server managed object
+ * associated with this management context.
+ */
+ public ServerManagedObject<RootCfg> getRootConfigurationManagedObject() {
+ return ServerManagedObject.getRootManagedObject();
+ }
}
--
Gitblit v1.10.0