View Javadoc

1   /*
2    PlantUMLDependencyProgrammingLanguageOptionArgument.java
3    Creation date : 18/06/2010
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument;
26  
27  import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.PROGRAMMING_LANGUAGE_NAME_NULL_ERROR;
28  import static net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.ProgrammingLanguage.getProgrammingLanguageNamesSet;
29  import static net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.ProgrammingLanguage.valueOfIgnoringCase;
30  import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.DOT_CHAR;
31  import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
32  import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
33  import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
34  
35  /**
36   * The programming language implementation of the
37   * {@link net.sourceforge.plantumldependency.commoncli.option.argument.OptionArgument} interface,
38   * specifying a {@link ProgrammingLanguage} argument.
39   *
40   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
41   * @since 1.0.0
42   * @version 1.3.0
43   */
44  public class PlantUMLDependencyProgrammingLanguageOptionArgument extends AbstractOptionArgument < ProgrammingLanguage > {
45  
46      /** Serial version UID. */
47      private static final long serialVersionUID = -151684884591596960L;
48  
49      /** The argument main usage constant. */
50      private static final String MAIN_USAGE = "PROGRAMMING_LANGUAGE";
51  
52      /** The argument main usage description constant. */
53      private static final String USAGE_DESCRIPTION = MAIN_USAGE
54              + " specifies the programming language contains in the source files to analyse. Possible values : "
55              + getProgrammingLanguageNamesSet() + DOT_CHAR;
56  
57      /**
58       * Default constructor.
59       *
60       * @param optionArgumentIsMandatory
61       *            <code>true</code> if the argument is mandatory, <code>false</code> otherwise.
62       * @since 1.0.0
63       */
64      public PlantUMLDependencyProgrammingLanguageOptionArgument(final boolean optionArgumentIsMandatory) {
65          super(optionArgumentIsMandatory, new StringBuilder(USAGE_DESCRIPTION));
66      }
67  
68      /**
69       * {@inheritDoc}
70       *
71       * @since 1.0.0
72       */
73      @Override
74      protected String getMainUsageDescription() {
75          return MAIN_USAGE;
76      }
77  
78      /**
79       * {@inheritDoc}
80       *
81       * @since 1.0.0
82       */
83      @Override
84      public ProgrammingLanguage parseArgument(final String argument) throws CommandLineException {
85          ProgrammingLanguage language = null;
86  
87          if (isNotEmpty(argument)) {
88              try {
89                  language = valueOfIgnoringCase(argument.toUpperCase());
90              } catch (final IllegalArgumentException e) {
91                  throw new CommandLineException(e.getMessage(), e);
92              }
93          } else {
94              throw new CommandLineException(PROGRAMMING_LANGUAGE_NAME_NULL_ERROR);
95          }
96  
97          return language;
98      }
99  }