View Javadoc

1   /*
2    PlantUMLDependencyDisplayPackageNameOptionArgument.java
3    Creation date : 31 mai 2014
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  package net.sourceforge.plantumldependency.cli.main.option.display.packagename.argument;
25  
26  import static java.util.regex.Pattern.compile;
27  import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.BAD_PATTERN_ARGUMENT_ERROR;
28  import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
29  import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
30  import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.EMPTY_OPTION_ARGUMENT_ERROR;
31  
32  import java.util.regex.Pattern;
33  import java.util.regex.PatternSyntaxException;
34  
35  import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
36  import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
37  
38  /**
39   * The display name option argument, telling the program what to display in the generated file.
40   * <i>Note : no option should have the same main or secondary names</i>.
41   *
42   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
43   * @since 1.4.0
44   * @version 1.4.0
45   */
46  public class PlantUMLDependencyDisplayPackageNameOptionArgument extends AbstractOptionArgument < Pattern > {
47  
48      /** The argument main usage constant. */
49      private static final String MAIN_USAGE = "DISPLAY_PACKAGE_NAME_PATTERN";
50  
51      /** The argument main usage description constant. */
52      private static final String USAGE_DESCRIPTION = MAIN_USAGE
53              + " specifies display package name pattern when generating the plantUML output file, it is a regular expression following the Java pattern (see http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html for description).";
54  
55      /** Serial version UID. */
56      private static final long serialVersionUID = -6205492935149580240L;
57  
58      /**
59       * Default constructor.
60       *
61       * @since 1.4.0
62       */
63      public PlantUMLDependencyDisplayPackageNameOptionArgument() {
64          super(true, new StringBuilder(USAGE_DESCRIPTION));
65      }
66  
67      /**
68       * {@inheritDoc}
69       *
70       * @since 1.4.0
71       */
72      @Override
73      protected String getMainUsageDescription() {
74          return MAIN_USAGE;
75      }
76  
77      /**
78       * {@inheritDoc}
79       *
80       * @since 1.4.0
81       */
82      @Override
83      public Pattern parseArgument(final String argument) throws CommandLineException {
84          Pattern displayPackageNameArgument = null;
85  
86          if (isNotEmpty(argument)) {
87              try {
88                  displayPackageNameArgument = compile(argument);
89              } catch (final PatternSyntaxException e) {
90                  throw new CommandLineException(buildLogString(BAD_PATTERN_ARGUMENT_ERROR, argument), e);
91              }
92          } else {
93              throw new CommandLineException(EMPTY_OPTION_ARGUMENT_ERROR);
94          }
95  
96          return displayPackageNameArgument;
97      }
98  }