src/jdk.jdi/share/classes/com/sun/tools/jdi/ConnectorImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 45714 jdk/src/jdk.jdi/share/classes/com/sun/tools/jdi/ConnectorImpl.java@1820d351198d
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.jdi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    28
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    30
import java.util.Collections;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    31
import java.util.Iterator;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    32
import java.util.LinkedHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    34
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ResourceBundle;
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    36
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    37
import com.sun.jdi.InternalException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    38
import com.sun.jdi.connect.Connector;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    39
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    40
import com.sun.jdi.connect.LaunchingConnector;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
abstract class ConnectorImpl implements Connector {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    43
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    44
    Map<String, Argument> defaultArguments = new LinkedHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // Used by BooleanArgument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static String trueString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static String falseString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public Map<String,Argument> defaultArguments() {
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
    51
        Map<String,Argument> defaults = new LinkedHashMap<>();
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
    52
        Collection<Argument> values = defaultArguments.values();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
    54
        Iterator<Argument> iter = values.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            ArgumentImpl argument = (ArgumentImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            defaults.put(argument.name(), (Argument)argument.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return defaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    void addStringArgument(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                           String defaultValue, boolean mustSpecify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        defaultArguments.put(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                             new StringArgumentImpl(name, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                                    description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                                    defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                                    mustSpecify));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    void addBooleanArgument(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                            boolean defaultValue, boolean mustSpecify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        defaultArguments.put(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                             new BooleanArgumentImpl(name, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                                     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                                     defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                                     mustSpecify));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    void addIntegerArgument(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                            String defaultValue, boolean mustSpecify,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                            int min, int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        defaultArguments.put(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                             new IntegerArgumentImpl(name, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                                     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                                     defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                                     mustSpecify,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                                     min, max));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    void addSelectedArgument(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                             String defaultValue, boolean mustSpecify,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                             List<String> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        defaultArguments.put(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                             new SelectedArgumentImpl(name, label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                                      description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                                      defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                                      mustSpecify, list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   101
    ArgumentImpl argument(String name, Map<String, ? extends Argument> arguments)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                throws IllegalConnectorArgumentsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        ArgumentImpl argument = (ArgumentImpl)arguments.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (argument == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new IllegalConnectorArgumentsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                         "Argument missing", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String value = argument.value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (value == null || value.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (argument.mustSpecify()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            throw new IllegalConnectorArgumentsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                         "Argument unspecified", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } else if(!argument.isValid(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new IllegalConnectorArgumentsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                         "Argument invalid", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return argument;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private ResourceBundle messages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    String getString(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (messages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            messages = ResourceBundle.getBundle("com.sun.tools.jdi.resources.jdi");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return messages.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        String string = name() + " (defaults: ";
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   135
        Iterator<Argument> iter = defaultArguments().values().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        boolean first = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            ArgumentImpl argument = (ArgumentImpl)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (!first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                string += ", ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            string += argument.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        string += ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
23012
b952c2b46e0d 8035453: Fix serial lint warnings in com.sun.tools and elsewhere
darcy
parents: 14342
diff changeset
   149
    @SuppressWarnings("serial") // JDK implementation class
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   150
    abstract class ArgumentImpl implements Connector.Argument, Cloneable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        private String label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        private String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        private String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        private boolean mustSpecify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ArgumentImpl(String name, String label, String description,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   158
                     String value, boolean mustSpecify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            this.label = label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            this.mustSpecify = mustSpecify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public abstract boolean isValid(String value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        public String name() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public String label() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public String description() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        public String value() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        public void setValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                throw new NullPointerException("Can't set null value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        public boolean mustSpecify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return mustSpecify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if ((obj != null) && (obj instanceof Connector.Argument)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                Connector.Argument other = (Connector.Argument)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                return (name().equals(other.name())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                       (description().equals(other.description())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                       (mustSpecify() == other.mustSpecify()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                       (value().equals(other.value()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return description().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                // Object should always support clone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                throw new InternalException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return name() + "=" + value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    class BooleanArgumentImpl extends ConnectorImpl.ArgumentImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                              implements Connector.BooleanArgument {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   227
        private static final long serialVersionUID = 1624542968639361316L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        BooleanArgumentImpl(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                            boolean value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                            boolean mustSpecify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            super(name, label, description, null, mustSpecify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if(trueString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                trueString = getString("true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                falseString = getString("false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            setValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         * Sets the value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        public void setValue(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            setValue(stringValueOf(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * Performs basic sanity check of argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         * @return <code>true</code> if value is a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         * representation of a boolean value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         * @see #stringValueOf(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public boolean isValid(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return value.equals(trueString) || value.equals(falseString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * Return the string representation of the <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * Does not set or examine the value or the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * @return the localized String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         * boolean value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        public String stringValueOf(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return value? trueString : falseString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         * Return the value of the argument as a boolean.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         * the argument may not have been set or may have an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * value {@link #isValid(String)} should be called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * {@link #value()} to check its validity.  If it is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * the boolean returned by this method is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * @return the value of the argument as a boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        public boolean booleanValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return value().equals(trueString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    class IntegerArgumentImpl extends ConnectorImpl.ArgumentImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                              implements Connector.IntegerArgument {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   282
        private static final long serialVersionUID = 763286081923797770L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        private final int min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        private final int max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        IntegerArgumentImpl(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                            String value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            boolean mustSpecify, int min, int max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            super(name, label, description, value, mustSpecify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            this.min = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            this.max = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * Sets the value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         * The value should be checked with {@link #isValid(int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * before setting it; invalid values will throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * when the connection is established - for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * on {@link LaunchingConnector#launch}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public void setValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            setValue(stringValueOf(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * Performs basic sanity check of argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * @return <code>true</code> if value represents an int that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         * <code>{@link #min()} &lt;= value &lt;= {@link #max()}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        public boolean isValid(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                return isValid(Integer.decode(value).intValue());
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   316
            } catch (NumberFormatException exc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         * Performs basic sanity check of argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * @return <code>true</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * <code>{@link #min()} &lt;= value  &lt;= {@link #max()}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        public boolean isValid(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            return min <= value && value <= max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * Return the string representation of the <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
         * Does not set or examine the value or the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
         * @return the String representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         * int value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        public String stringValueOf(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            // *** Should this be internationalized????
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            // *** Even Brian Beck was unsure if an Arabic programmer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            // *** would expect port numbers in Arabic numerals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // *** so punt for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return ""+value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * Return the value of the argument as a int.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * the argument may not have been set or may have an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * value {@link #isValid(String)} should be called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * {@link #value()} to check its validity.  If it is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * the int returned by this method is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * @return the value of the argument as a int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        public int intValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            if (value() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                return Integer.decode(value()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            } catch(NumberFormatException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * The upper bound for the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * @return the maximum allowed value for this argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        public int max() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         * The lower bound for the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * @return the minimum allowed value for this argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public int min() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    class StringArgumentImpl extends ConnectorImpl.ArgumentImpl
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   382
                             implements Connector.StringArgument {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   383
        private static final long serialVersionUID = 7500484902692107464L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        StringArgumentImpl(String name, String label, String description,
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   385
                           String value, boolean mustSpecify) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            super(name, label, description, value, mustSpecify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * Performs basic sanity check of argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * @return <code>true</code> always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        public boolean isValid(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    class SelectedArgumentImpl extends ConnectorImpl.ArgumentImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                              implements Connector.SelectedArgument {
11277
e3a1c90dd439 7117053: Fix build warnings in com/sun/tools/jdi/*
jjh
parents: 5506
diff changeset
   400
        private static final long serialVersionUID = -5689584530908382517L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        private final List<String> choices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        SelectedArgumentImpl(String name, String label, String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                             String value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                             boolean mustSpecify, List<String> choices) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            super(name, label, description, value, mustSpecify);
45714
1820d351198d 8183012: Code cleanup in com.sun.tools.jdi
clanger
parents: 25859
diff changeset
   407
            this.choices = Collections.unmodifiableList(new ArrayList<>(choices));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * Return the possible values for the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         * @return {@link List} of {@link String}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        public List<String> choices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return choices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         * Performs basic sanity check of argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         * @return <code>true</code> if value is one of {@link #choices()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        public boolean isValid(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return choices.contains(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
}