1 /******************************************************************************* 2 * Copyright (c) 2007, 2014 Massimiliano Ziccardi 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 *******************************************************************************/ 16 package it.jnrpe.plugins; 17 18 import java.util.ArrayList; 19 import java.util.List; 20 21 /** 22 * This object represent a plugin definition. It is used to describe to JNRPE 23 * which parameters a plugin supports 24 * 25 * @author Massimiliano Ziccardi 26 */ 27 public final class PluginDefinition { 28 /** 29 * The name of the plugin (as parsed from the XML file). 30 */ 31 private final String name; 32 /** 33 * The Class of the plugin. 34 */ 35 private final Class<? extends IPluginInterface> pluginClass; 36 37 /** 38 * The plugin instance. 39 */ 40 private final IPluginInterface pluginInterface; 41 42 /** 43 * The plugin description (as parsed from the XML file). 44 */ 45 private final String description; 46 47 /** 48 * All the options this plugin supports (as parsed from the XML file). 49 */ 50 private List<PluginOption> pluginOptionsList = 51 new ArrayList<PluginOption>(); 52 53 /** 54 * Initializes the plugin definition specifying the Class object that 55 * represent the plugin. This constructor is used, for example, by JNRPE 56 * server where all the plugins are described in an XML file and are loaded 57 * with potentially different class loaders. 58 * 59 * @param pluginName 60 * The plugin name 61 * @param pluginDescription 62 * The plugin description 63 * @param pluginClazz 64 * The plugin Class object 65 */ 66 public PluginDefinition(final String pluginName, 67 final String pluginDescription, 68 final Class<? extends IPluginInterface> pluginClazz) { 69 this.name = pluginName; 70 this.pluginClass = pluginClazz; 71 this.description = pluginDescription; 72 this.pluginInterface = null; 73 } 74 75 /** 76 * Initializes the plugin definition specifying a plugin instance. This is. 77 * useful when you embed JNRPE: with this constructor you can pass a <i>pre. 78 * inizialized/configured</i> instance. 79 * 80 * @param pluginName 81 * The plugin name 82 * @param pluginDescription 83 * The plugin description 84 * @param pluginInstance 85 * The plugin instance 86 */ 87 public PluginDefinition(final String pluginName, 88 final String pluginDescription, 89 final IPluginInterface pluginInstance) { 90 this.name = pluginName; 91 this.pluginClass = null; 92 this.description = pluginDescription; 93 this.pluginInterface = pluginInstance; 94 } 95 96 /** 97 * Adds a new option to the plugin. 98 * 99 * @param option 100 * The option 101 * @return this 102 */ 103 public PluginDefinition addOption(final PluginOption option) { 104 pluginOptionsList.add(option); 105 return this; 106 } 107 108 /** 109 * Returns the plugin name. 110 * 111 * @return the plugin name. 112 */ 113 public String getName() { 114 return name; 115 } 116 117 /** 118 * Returns all the plugin options. 119 * 120 * @return a List of all the plugin option 121 */ 122 public List<PluginOption> getOptions() { 123 return pluginOptionsList; 124 } 125 126 /** 127 * Returns the plugin description. 128 * 129 * @return The plugin description 130 */ 131 public String getDescription() { 132 return description; 133 } 134 135 /** 136 * Returns the plugin class, if specified. 137 * 138 * @return the plugin class. <code>null</code> if not specified. 139 */ 140 Class<? extends IPluginInterface> getPluginClass() { 141 return pluginClass; 142 } 143 144 /** 145 * Returns the plugin instance, if present. 146 * 147 * @return the plugin interface.<code>null</code> if not specified. 148 */ 149 IPluginInterface getPluginInterface() { 150 return pluginInterface; 151 } 152 }