1008N/A/*
1008N/A * CDDL HEADER START
1008N/A *
1008N/A * The contents of this file are subject to the terms of the
1008N/A * Common Development and Distribution License, Version 1.0 only
1008N/A * (the "License"). You may not use this file except in compliance
1008N/A * with the License.
1008N/A *
1008N/A * You can obtain a copy of the license at
1008N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
1008N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1008N/A * See the License for the specific language governing permissions
1008N/A * and limitations under the License.
1008N/A *
1008N/A * When distributing Covered Code, include this CDDL HEADER in each
1008N/A * file and include the License file at
1008N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1008N/A * add the following below this CDDL HEADER, with the fields enclosed
1008N/A * by brackets "[]" replaced with your own identifying information:
1008N/A * Portions Copyright [yyyy] [name of copyright owner]
1008N/A *
1008N/A * CDDL HEADER END
1008N/A *
1008N/A *
3233N/A * Copyright 2006-2008 Sun Microsystems, Inc.
1008N/A */
1008N/Apackage com.example.opends;
1008N/A
1280N/Aimport static org.opends.server.loggers.ErrorLogger.logError;
1008N/A
1008N/Aimport java.util.List;
1008N/Aimport java.util.Set;
1008N/A
1008N/Aimport org.opends.server.api.plugin.PluginType;
3646N/Aimport org.opends.server.api.plugin.PluginResult;
2617N/Aimport org.opends.server.api.plugin.DirectoryServerPlugin;
1008N/Aimport org.opends.server.config.ConfigException;
1008N/Aimport org.opends.server.types.ConfigChangeResult;
2086N/A
1008N/Aimport org.opends.server.types.ResultCode;
2617N/Aimport org.opends.server.types.InitializationException;
2617N/Aimport org.opends.server.admin.server.ConfigurationChangeListener;
2617N/Aimport org.opends.messages.Message;
2617N/Aimport org.opends.messages.Category;
2617N/Aimport org.opends.messages.Severity;
1008N/A
1008N/Aimport com.example.opends.server.ExamplePluginCfg;
1008N/A
3646N/Aimport static com.example.opends.messages.ExamplePluginMessages.*;
3646N/A
1008N/A/**
1008N/A * The example plugin implementation class. This plugin will output
1008N/A * the configured message to the error log during server start up.
1008N/A */
1008N/Apublic class ExamplePlugin extends
2617N/A DirectoryServerPlugin<ExamplePluginCfg> implements
2617N/A ConfigurationChangeListener<ExamplePluginCfg> {
1008N/A
1008N/A // The current configuration.
1008N/A private ExamplePluginCfg config;
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * Default constructor.
1008N/A */
1008N/A public ExamplePlugin() {
1008N/A super();
1008N/A }
1008N/A
1008N/A
1008N/A /**
2617N/A * Performs any initialization necessary for this plugin. This will
2617N/A * be called as soon as the plugin has been loaded and before it is
2617N/A * registered with the server.
2617N/A *
2617N/A * @param pluginTypes The set of plugin types that indicate the
2617N/A * ways in which this plugin will be invoked.
2617N/A * @param configuration The configuration for this plugin.
2617N/A *
2617N/A * @throws ConfigException If the provided entry does not contain
2617N/A * a valid configuration for this plugin.
2617N/A *
2617N/A * @throws InitializationException If a problem occurs while
2617N/A * initializing the plugin that is
2617N/A * not related to the server
2617N/A * configuration.
1008N/A */
1008N/A @Override()
1008N/A public void initializePlugin(Set<PluginType> pluginTypes,
1008N/A ExamplePluginCfg configuration)
2617N/A throws ConfigException, InitializationException {
1008N/A // This plugin may only be used as a server startup plugin.
1008N/A for (PluginType t : pluginTypes) {
1008N/A switch (t) {
1008N/A case STARTUP:
1008N/A // This is fine.
1008N/A break;
1008N/A default:
3646N/A Message message = ERR_INITIALIZE_PLUGIN.get(String.valueOf(t));
3646N/A throw new ConfigException(message);
1008N/A }
1008N/A }
1008N/A
1008N/A // Register change listeners. These are not really necessary for
1008N/A // this plugin since it is only used during server start-up.
1008N/A configuration.addExampleChangeListener(this);
1008N/A
1008N/A // Save the configuration.
1008N/A this.config = configuration;
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
2617N/A * Performs any processing that should be done when the Directory
2617N/A * Server is in the process of starting. This method will be called
2617N/A * after virtually all other initialization has been performed but
2617N/A * before the connection handlers are started.
2617N/A *
2617N/A * @return The result of the startup plugin processing.
1008N/A */
1008N/A @Override
3646N/A public PluginResult.Startup doStartup() {
1008N/A // Log the provided message.
3646N/A Message message = NOTE_DO_STARTUP.get(String.valueOf(config.getMessage()));
3646N/A logError(message);
3646N/A return PluginResult.Startup.continueStartup();
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
2617N/A * Applies the configuration changes to this change listener.
2617N/A *
2617N/A * @param config
2617N/A * The new configuration containing the changes.
2617N/A * @return Returns information about the result of changing the
2617N/A * configuration.
1008N/A */
1008N/A public ConfigChangeResult applyConfigurationChange(
1008N/A ExamplePluginCfg config) {
1008N/A // The new configuration has already been validated.
1008N/A
1008N/A // Log a message to say that the configuration has changed. This
1008N/A // isn't necessary, but we'll do it just to show that the change
1008N/A // has taken effect.
3646N/A Message message = NOTE_APPLY_CONFIGURATION_CHANGE.get(
3646N/A String.valueOf(this.config.getMessage()),
3646N/A String.valueOf(config.getMessage()));
3646N/A logError(message);
1008N/A
1008N/A // Update the configuration.
1008N/A this.config = config;
1008N/A
1008N/A // Update was successfull, no restart required.
1008N/A return new ConfigChangeResult(ResultCode.SUCCESS, false);
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
2617N/A * Indicates whether the proposed change to the configuration is
2617N/A * acceptable to this change listener.
2617N/A *
2617N/A * @param config
2617N/A * The new configuration containing the changes.
2617N/A * @param messages
2617N/A * A list that can be used to hold messages about why the
2617N/A * provided configuration is not acceptable.
2617N/A * @return Returns <code>true</code> if the proposed change is
2617N/A * acceptable, or <code>false</code> if it is not.
1008N/A */
1008N/A public boolean isConfigurationChangeAcceptable(
2086N/A ExamplePluginCfg config, List<Message> messages) {
1008N/A // The only thing that can be validated here is the plugin's
1008N/A // message. However, it is always going to be valid, so let's
1008N/A // always return true.
1008N/A return true;
1008N/A }
1008N/A}