View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.frontend.cli;
20  
21  import java.util.ArrayList;
22  
23  /**
24   * This class is an abstract for the implementation of command classes for the
25   * MyCoRe commandline system.
26   * 
27   * @author Jens Kupferschmidt
28   * @version $Revision$ $Date: 2009-07-28 11:32:04 +0200 (Tue, 28 Jul
29   *          2009) $
30   */
31  public abstract class MCRAbstractCommands implements MCRExternalCommandInterface {
32      /** The array holding all known commands */
33      protected ArrayList<MCRCommand> command = null;
34  
35      private String displayName;
36  
37      /**
38       * The constructor.
39       */
40      protected MCRAbstractCommands() {
41          init();
42      }
43  
44      private void init() {
45          setCommand(new ArrayList<>());
46      }
47  
48      /**
49       * @param displayName
50       *            a human readable name for this collection of commands
51       */
52      protected MCRAbstractCommands(String displayName) {
53          init();
54          this.displayName = displayName;
55      }
56  
57      /**
58       * The method return the list of possible commands of this class. Each
59       * command has TWO Strings, a String of the user command syntax and a String
60       * of the called method.
61       * 
62       * @return a ascending sorted command pair ArrayList
63       */
64      public ArrayList<MCRCommand> getPossibleCommands() {
65          return this.command;
66      }
67  
68      @Override
69      public String getDisplayName() {
70          return this.displayName == null ? this.getClass().getSimpleName() : this.displayName;
71      }
72  
73      @Override
74      public void setDisplayName(String s) {
75          this.displayName = s;
76      }
77  
78      public void addCommand(MCRCommand cmd) {
79          if (this.command == null) {
80              init();
81          }
82  
83          this.command.add(cmd);
84      }
85  
86      private void setCommand(ArrayList<MCRCommand> command) {
87          this.command = command;
88      }
89  }