ExamplePlugin.java revision 1008
2292N/A/*
2292N/A * CDDL HEADER START
2292N/A *
2292N/A * The contents of this file are subject to the terms of the
2292N/A * Common Development and Distribution License, Version 1.0 only
2292N/A * (the "License"). You may not use this file except in compliance
2292N/A * with the License.
2292N/A *
2292N/A * You can obtain a copy of the license at
2292N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2292N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2292N/A * See the License for the specific language governing permissions
2292N/A * and limitations under the License.
2292N/A *
2292N/A * When distributing Covered Code, include this CDDL HEADER in each
2292N/A * file and include the License file at
2292N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2292N/A * add the following below this CDDL HEADER, with the fields enclosed
2292N/A * by brackets "[]" replaced with your own identifying information:
2292N/A * Portions Copyright [yyyy] [name of copyright owner]
2292N/A *
2292N/A * CDDL HEADER END
2292N/A *
2292N/A *
2292N/A * Portions Copyright 2006-2007 Sun Microsystems, Inc.
2292N/A */
2292N/Apackage com.example.opends;
2292N/A
2292N/A
2292N/A
2292N/Aimport static org.opends.server.loggers.Error.logError;
2292N/A
2292N/Aimport java.util.List;
2292N/Aimport java.util.Set;
2292N/A
2292N/Aimport org.opends.server.admin.server.ConfigurationChangeListener;
2292N/Aimport org.opends.server.api.plugin.DirectoryServerPlugin;
2292N/Aimport org.opends.server.api.plugin.PluginType;
2292N/Aimport org.opends.server.api.plugin.StartupPluginResult;
2292N/Aimport org.opends.server.config.ConfigException;
2292N/Aimport org.opends.server.types.ConfigChangeResult;
2292N/Aimport org.opends.server.types.ErrorLogCategory;
2292N/Aimport org.opends.server.types.ErrorLogSeverity;
2292N/Aimport org.opends.server.types.ResultCode;
2292N/A
2292N/Aimport com.example.opends.server.ExamplePluginCfg;
2292N/A
2292N/A
2292N/A
2292N/A/**
2292N/A * The example plugin implementation class. This plugin will output
2292N/A * the configured message to the error log during server start up.
2292N/A */
2292N/Apublic class ExamplePlugin extends
2292N/A DirectoryServerPlugin<ExamplePluginCfg> implements
2292N/A ConfigurationChangeListener<ExamplePluginCfg> {
2292N/A
2292N/A // The current configuration.
2292N/A private ExamplePluginCfg config;
2292N/A
2292N/A
2292N/A
2292N/A /**
2292N/A * Default constructor.
2292N/A */
2292N/A public ExamplePlugin() {
2292N/A super();
2292N/A }
2292N/A
2292N/A
2292N/A
2292N/A /**
2292N/A * {@inheritDoc}
2292N/A */
2292N/A @Override()
2292N/A public void initializePlugin(Set<PluginType> pluginTypes,
2292N/A ExamplePluginCfg configuration)
2292N/A throws ConfigException {
2292N/A // This plugin may only be used as a server startup plugin.
2292N/A for (PluginType t : pluginTypes) {
2292N/A switch (t) {
2292N/A case STARTUP:
2292N/A // This is fine.
2292N/A break;
2292N/A default:
2292N/A throw new ConfigException(-1, "Invalid plugin type " + t
2292N/A + " for the example plugin.");
2292N/A }
2292N/A }
2292N/A
2292N/A // Register change listeners. These are not really necessary for
2292N/A // this plugin since it is only used during server start-up.
2292N/A configuration.addExampleChangeListener(this);
2292N/A
2292N/A // Save the configuration.
2292N/A this.config = configuration;
2292N/A }
2292N/A
2292N/A
2292N/A
2292N/A /**
2292N/A * {@inheritDoc}
2292N/A */
2292N/A @Override
2292N/A public StartupPluginResult doStartup() {
2292N/A // Log the provided message.
2292N/A logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.NOTICE,
2292N/A "Example plugin message '" + config.getMessage() + "'.", 9999);
2292N/A return StartupPluginResult.SUCCESS;
2292N/A }
2292N/A
2292N/A
2292N/A
2292N/A /**
2292N/A * {@inheritDoc}
2292N/A */
2292N/A public ConfigChangeResult applyConfigurationChange(
2292N/A ExamplePluginCfg config) {
2292N/A // The new configuration has already been validated.
2292N/A
2292N/A // Log a message to say that the configuration has changed. This
2292N/A // isn't necessary, but we'll do it just to show that the change
2292N/A // has taken effect.
2292N/A logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.NOTICE,
2292N/A "Example plugin message has been changed from '"
2292N/A + this.config.getMessage() + "' to '"
2292N/A + config.getMessage() + "'.", 9999);
2292N/A
2292N/A // Update the configuration.
2292N/A this.config = config;
2292N/A
2292N/A // Update was successfull, no restart required.
2292N/A return new ConfigChangeResult(ResultCode.SUCCESS, false);
2292N/A }
2292N/A
2292N/A
2292N/A
2292N/A /**
2292N/A * {@inheritDoc}
2292N/A */
2292N/A public boolean isConfigurationChangeAcceptable(
2292N/A ExamplePluginCfg config, List<String> messages) {
2292N/A // The only thing that can be validated here is the plugin's
2292N/A // message. However, it is always going to be valid, so let's
2292N/A // always return true.
2292N/A return true;
2292N/A }
2292N/A}
2292N/A