ExamplePlugin.java revision 2086
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 *
1008N/A * Portions Copyright 2006-2007 Sun Microsystems, Inc.
1008N/A */
1008N/Apackage com.example.opends;
1008N/A
1008N/A
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.admin.server.ConfigurationChangeListener;
1008N/Aimport org.opends.server.api.plugin.DirectoryServerPlugin;
1008N/Aimport org.opends.server.api.plugin.PluginType;
1008N/Aimport org.opends.server.api.plugin.StartupPluginResult;
1008N/Aimport org.opends.server.config.ConfigException;
1008N/Aimport org.opends.server.types.ConfigChangeResult;
2086N/A
2086N/A
1008N/Aimport org.opends.server.types.ResultCode;
2086N/Aimport org.opends.server.messages.Message;
1008N/A
1008N/Aimport com.example.opends.server.ExamplePluginCfg;
1008N/A
1008N/A
1008N/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
1008N/A DirectoryServerPlugin<ExamplePluginCfg> implements
1008N/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
1008N/A /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override()
1008N/A public void initializePlugin(Set<PluginType> pluginTypes,
1008N/A ExamplePluginCfg configuration)
1008N/A throws ConfigException {
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:
1008N/A throw new ConfigException(-1, "Invalid plugin type " + t
1008N/A + " for the example plugin.");
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 /**
1008N/A * {@inheritDoc}
1008N/A */
1008N/A @Override
1008N/A public StartupPluginResult doStartup() {
1008N/A // Log the provided message.
1008N/A logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.NOTICE,
1008N/A "Example plugin message '" + config.getMessage() + "'.", 9999);
1008N/A return StartupPluginResult.SUCCESS;
1008N/A }
1008N/A
1008N/A
1008N/A
1008N/A /**
1008N/A * {@inheritDoc}
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.
1008N/A logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.NOTICE,
1008N/A "Example plugin message has been changed from '"
1008N/A + this.config.getMessage() + "' to '"
1008N/A + config.getMessage() + "'.", 9999);
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 /**
1008N/A * {@inheritDoc}
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}