1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.management;
  27 
  28 /**
  29  * Diagnostic Command Argument information. It contains the description
  30  * of one parameter of the diagnostic command. A parameter can either be an
  31  * option or an argument. Options are identified by the option name while
  32  * arguments are identified by their position in the command line. The generic
  33  * syntax of a diagnostic command is:
  34  *  <blockquote>
  35  *    &lt;command name&gt; [&lt;option&gt;=&lt;value&gt;] [&lt;argument_value&gt;]
  36  * </blockquote>
  37  * Example:
  38  * <blockquote>
  39  * command_name option1=value1 option2=value argumentA argumentB argumentC
  40  * </blockquote>
  41  * In this command line, the diagnostic command receives five parameters, two
  42  * options named {@code option1} and {@code option2}, and three arguments.
  43  * argumentA's position is 0, argumentB's position is 1 and argumentC's
  44  * position is 2.
  45  *
  46  * @author  Frederic Parain
  47  * @since   7u6
  48  */
  49 
  50 class DiagnosticCommandArgumentInfo {
  51     private final String name;
  52     private final String description;
  53     private final String type;
  54     private final String defaultValue;
  55     private final boolean mandatory;
  56     private final boolean option;
  57     private final boolean multiple;
  58     private final int position;
  59 
  60     /**
  61      * Returns the argument name.
  62      *
  63      * @return the argument name
  64      */
  65     public String getName() {
  66         return name;
  67     }
  68 
  69    /**
  70      * Returns the argument description.
  71      *
  72      * @return the argument description
  73      */
  74     public String getDescription() {
  75         return description;
  76     }
  77 
  78     /**
  79      * Returns the argument type.
  80      *
  81      * @return the argument type
  82      */
  83     public String getType() {
  84         return type;
  85     }
  86 
  87     /**
  88      * Returns the default value as a String if a default value
  89      * is defined, null otherwise.
  90      *
  91      * @return the default value as a String if a default value
  92      * is defined, null otherwise.
  93      */
  94     public String getDefault() {
  95         return defaultValue;
  96     }
  97 
  98     /**
  99      * Returns {@code true} if the argument is mandatory,
 100      *         {@code false} otherwise.
 101      *
 102      * @return {@code true} if the argument is mandatory,
 103      *         {@code false} otherwise
 104      */
 105     public boolean isMandatory() {
 106         return mandatory;
 107     }
 108 
 109     /**
 110      * Returns {@code true} if the argument is an option,
 111      *         {@code false} otherwise. Options have to be specified using the
 112      *         &lt;key&gt;=&lt;value&gt; syntax on the command line, while other
 113      *         arguments are specified with a single &lt;value&gt; field and are
 114      *         identified by their position on command line.
 115      *
 116      * @return {@code true} if the argument is an option,
 117      *         {@code false} otherwise
 118      */
 119     public boolean isOption() {
 120         return option;
 121     }
 122 
 123     /**
 124      * Returns {@code true} if the argument can be specified multiple times,
 125      *         {@code false} otherwise.
 126      *
 127      * @return {@code true} if the argument can be specified multiple times,
 128      *         {@code false} otherwise
 129      */
 130     public boolean isMultiple() {
 131         return multiple;
 132     }
 133 
 134     /**
 135      * Returns the expected position of this argument if it is not an option,
 136      *         -1 otherwise. Argument position if defined from left to right,
 137      *         starting at zero and ignoring the diagnostic command name and
 138      *         options.
 139      *
 140      * @return the expected position of this argument if it is not an option,
 141      *         -1 otherwise.
 142      */
 143     public int getPosition() {
 144         return position;
 145     }
 146 
 147     public DiagnosticCommandArgumentInfo(String name, String description,
 148                                          String type, String defaultValue,
 149                                          boolean mandatory, boolean option,
 150                                          boolean multiple, int position) {
 151         this.name = name;
 152         this.description = description;
 153         this.type = type;
 154         this.defaultValue = defaultValue;
 155         this.mandatory = mandatory;
 156         this.option = option;
 157         this.multiple = multiple;
 158         this.position = position;
 159     }
 160 }