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.server; 17 18 import it.jnrpe.commands.CommandDefinition; 19 import it.jnrpe.commands.CommandRepository; 20 import it.jnrpe.server.CommandsSection.Command; 21 22 import java.io.File; 23 24 /** 25 * Base class for all the JNRPE configuration classes (INI, XML, etc.). 26 * 27 * @author Massimiliano Ziccardi 28 */ 29 public abstract class JNRPEConfiguration { 30 31 /** 32 * The jnrpe configuration command section. 33 */ 34 private CommandsSection commandSection = new CommandsSection(); 35 36 /** 37 * The jnrpe configuration server section. 38 */ 39 private ServerSection serverSection = new ServerSection(); 40 41 /** 42 * All the concrete configuration classes must load the configuration file 43 * inside this method. 44 * 45 * @param f 46 * The configuration file 47 * 48 * @throws ConfigurationException 49 * on any configuration error. 50 */ 51 public abstract void load(File f) throws ConfigurationException; 52 53 /** 54 * Returns the command section of the configuration file. 55 * 56 * @return The command section 57 */ 58 public final CommandsSection getCommandSection() { 59 return commandSection; 60 } 61 62 /** 63 * Returns the server section of the configuration file. 64 * 65 * @return The server section 66 */ 67 public final ServerSection getServerSection() { 68 return serverSection; 69 } 70 71 /** 72 * Returns a command repository containing all the commands configured 73 * inside the configuration file. 74 * 75 * @return The command repository 76 */ 77 public final CommandRepository createCommandRepository() { 78 CommandRepository cr = new CommandRepository(); 79 80 for (Command c : commandSection.getAllCommands()) { 81 CommandDefinition cd = 82 new CommandDefinition(c.getName(), c.getPlugin()); 83 cd.setArgs(c.getCommandLine()); 84 85 cr.addCommandDefinition(cd); 86 } 87 88 return cr; 89 } 90 }