1 /* 2 * Copyright (c) 2011, 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 com.sun.management; 27 28 import java.beans.ConstructorProperties; 29 30 /** 31 * Diagnostic Command Argument information. It contains the description 32 * of one parameter of diagnostic command. A parameter can either be an option 33 * or an argument. Options are identified by the option name while arguments are 34 * identified by their position in the command line. The generic syntax of a 35 * diagnostic command is: 36 * <blockquote> 37 * <command name> [<option>=<value>] [<argument_value>] 38 * </blockquote> 39 * Example: 40 * <blockquote> 41 * command_name option1=value1 option2=value argumentA argumentB argumentC 42 * </blockquote> 43 * In this command line, the diagnostic command receives five parameters, two 44 * options named {@code option1} and {@code option2}, and three arguments. 45 * argumentA's position is 0, argumentB's position is 1 and argumentC's 46 * position is 2. 47 * 48 * @author Frederic Parain 49 * @since 7u4 50 */ 51 52 public class DiagnosticCommandArgumentInfo { 53 private final String name; 54 private final String description; 55 private final String type; 56 private final String defaultValue; 57 private final boolean mandatory; 58 private final boolean option; 59 private final int position; 60 61 /** 62 * Returns the argument name 63 * 64 * @return the argument name 65 */ 66 public String getName() { 67 return name; 68 } 69 70 /** 71 * Returns the argument description 72 * 73 * @return the argument description 74 */ 75 public String getDescription() { 76 return description; 77 } 78 79 /** 80 * Returns the argument type 81 * 82 * @return the argument type 83 */ 84 public String getType() { 85 return type; 86 } 87 88 /** 89 * Returns the default value as a String if a default value 90 * is defined, null otherwise. 91 * 92 * @return the default value as a String if a default value 93 * is defined, null otherwise. 94 */ 95 public String getDefault() { 96 return defaultValue; 97 } 98 99 /** 100 * Returns {@code true} if the argument is mandatory, 101 * {@code false} otherwise 102 * 103 * @return {@code true} if the argument is mandatory, 104 * {@code false} otherwise 105 */ 106 public boolean isMandatory() { 107 return mandatory; 108 } 109 110 /** 111 * Returns {@code true} if the argument is an option, 112 * {@code false} otherwise. Options have to be specified using the 113 * <key>=<value> syntax on the command line, while other 114 * arguments are specified with a single <value> field and are 115 * identified by their position on command line. 116 * 117 * @return {@code true} if the argument is an option, 118 * {@code false} otherwise 119 */ 120 public boolean isOption() { 121 return option; 122 } 123 124 /** 125 * Returns the expected position of this argument if it is not an option, 126 * -1 otherwise. Argument position if defined from left to right, 127 * starting at zero and ignoring the diagnostic command name and 128 * options. 129 * 130 * @return the expected position of this argument if it is not an option, 131 * -1 otherwise. 132 */ 133 public int getPosition() { 134 return position; 135 } 136 137 @ConstructorProperties({"name","description","type","default", 138 "mandatory","option","position"}) 139 public DiagnosticCommandArgumentInfo(String name, String description, 140 String type, String defaultValue, 141 boolean mandatory, boolean option, 142 int position) { 143 this.name = name; 144 this.description = description; 145 this.type = type; 146 this.defaultValue = defaultValue; 147 this.mandatory = mandatory; 148 this.option = option; 149 this.position = position; 150 } 151 }