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 java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21
22 /**
23 * The command section of a configuration.
24 *
25 * @author Massimiliano Ziccardi
26 */
27 class CommandsSection {
28 /**
29 * The list of commands.
30 */
31 private List<Command> commandsList = new ArrayList<Command>();
32
33 /**
34 * A single command definition.
35 *
36 * @author Massimiliano Ziccardi
37 */
38 public static class Command {
39 /**
40 * The command name.
41 */
42 private final String commandName;
43
44 /**
45 * The plugin name.
46 */
47 private final String pluginName;
48
49 /**
50 * The command line.
51 */
52 private final String commandLine;
53
54 /**
55 * Build the object.
56 *
57 * @param name
58 * The command name
59 * @param plugin
60 * The plugin name
61 * @param cl
62 * The command line
63 */
64 public Command(final String name,
65 final String plugin, final String cl) {
66 commandName = name;
67 pluginName = plugin;
68 commandLine = cl;
69 }
70
71 /**
72 * @return the command name
73 */
74 public String getName() {
75 return commandName;
76 }
77
78 /**
79 * @return the plugin name
80 */
81 public String getPlugin() {
82 return pluginName;
83 }
84
85 /**
86 * @return the command line
87 */
88 public String getCommandLine() {
89 return commandLine;
90 }
91 }
92
93 /**
94 * Adds a command to the section.
95 *
96 * @param commandName The command name
97 * @param pluginName The plugin name
98 * @param commandLine The command line
99 */
100 public void addCommand(final String commandName, final String pluginName,
101 final String commandLine) {
102 commandsList.add(new Command(commandName, pluginName, commandLine));
103 }
104
105 /**
106 * @return all commands
107 */
108 public Collection<Command> getAllCommands() {
109 return commandsList;
110 }
111 }