jdk/src/share/classes/sun/security/jca/ProviderList.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7973 dffe8439eb20
child 10336 0bb1999251f8
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7973
diff changeset
     2
 * Copyright (c) 2003, 2011, 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 sun.security.jca;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.Provider.Service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * List of Providers. Used to represent the provider preferences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The system starts out with a ProviderList that only has the classNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * of the Providers. Providers are loaded on demand only when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * For compatibility reasons, Providers that could not be loaded are ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * and internally presented as the instance EMPTY_PROVIDER. However, those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * objects cannot be presented to applications. Call the convert() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to force all Providers to be loaded and to obtain a ProviderList with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * invalid entries removed. All this is handled by the Security class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Note that all indices used by this class are 0-based per general Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * convention. These must be converted to the 1-based indices used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Security class externally when needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Instances of this class are immutable. This eliminates the need for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * cloning and synchronization in consumers. The add() and remove() style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * methods are static in order to avoid confusion about the immutability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public final class ProviderList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    final static sun.security.util.Debug debug =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        sun.security.util.Debug.getInstance("jca", "ProviderList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static ProviderConfig[] PC0 = new ProviderConfig[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final static Provider[] P0 = new Provider[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // constant for an ProviderList with no elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static final ProviderList EMPTY = new ProviderList(PC0, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // dummy provider object to use during initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // used to avoid explicit null checks in various places
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final Provider EMPTY_PROVIDER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        new Provider("##Empty##", 1.0d, "initialization in progress") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // override getService() to return null slightly faster
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            public Service getService(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // construct a ProviderList from the security properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // (static provider configuration in the java.security file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static ProviderList fromSecurityProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // doPrivileged() because of Security.getProperty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                        new PrivilegedAction<ProviderList>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            public ProviderList run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                return new ProviderList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static ProviderList add(ProviderList providerList, Provider p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return insertAt(providerList, p, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static ProviderList insertAt(ProviderList providerList, Provider p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (providerList.getProvider(p.getName()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return providerList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
7973
dffe8439eb20 7005608: diamond conversion of JCA and crypto providers
smarks
parents: 5506
diff changeset
    99
        List<ProviderConfig> list = new ArrayList<>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                    (Arrays.asList(providerList.configs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int n = list.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if ((position < 0) || (position > n)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            position = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        list.add(position, new ProviderConfig(p));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return new ProviderList(list.toArray(PC0), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static ProviderList remove(ProviderList providerList, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // make sure provider exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (providerList.getProvider(name) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return providerList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // copy all except matching to new list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        ProviderConfig[] configs = new ProviderConfig[providerList.size() - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        for (ProviderConfig config : providerList.configs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (config.getProvider().getName().equals(name) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                configs[j++] = config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return new ProviderList(configs, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // Create a new ProviderList from the specified Providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // This method is for use by SunJSSE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static ProviderList newList(Provider ... providers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        ProviderConfig[] configs = new ProviderConfig[providers.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        for (int i = 0; i < providers.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            configs[i] = new ProviderConfig(providers[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return new ProviderList(configs, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // configuration of the providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private final ProviderConfig[] configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // flag indicating whether all configs have been loaded successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private volatile boolean allLoaded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // List returned by providers()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private final List<Provider> userList = new AbstractList<Provider>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return configs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        public Provider get(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return getProvider(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Create a new ProviderList from an array of configs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private ProviderList(ProviderConfig[] configs, boolean allLoaded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this.configs = configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        this.allLoaded = allLoaded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Return a new ProviderList parsed from the java.security Properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private ProviderList() {
7973
dffe8439eb20 7005608: diamond conversion of JCA and crypto providers
smarks
parents: 5506
diff changeset
   163
        List<ProviderConfig> configList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (int i = 1; true; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            String entry = Security.getProperty("security.provider." + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            entry = entry.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (entry.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                System.err.println("invalid entry for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                   "security.provider." + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            int k = entry.indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            ProviderConfig config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (k == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                config = new ProviderConfig(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                String className = entry.substring(0, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                String argument = entry.substring(k + 1).trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                config = new ProviderConfig(className, argument);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // Get rid of duplicate providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (configList.contains(config) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                configList.add(config);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        configs = configList.toArray(PC0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            debug.println("provider configuration: " + configList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Construct a special ProviderList for JAR verification. It consists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * of the providers specified via jarClassNames, which must be on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * bootclasspath and cannot be in signed JAR files. This is to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * possible recursion and deadlock during verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    ProviderList getJarList(String[] jarClassNames) {
7973
dffe8439eb20 7005608: diamond conversion of JCA and crypto providers
smarks
parents: 5506
diff changeset
   203
        List<ProviderConfig> newConfigs = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        for (String className : jarClassNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            ProviderConfig newConfig = new ProviderConfig(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            for (ProviderConfig config : configs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                // if the equivalent object is present in this provider list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                // use the old object rather than the new object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                // this ensures that when the provider is loaded in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                // new thread local list, it will also become available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                // in this provider list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if (config.equals(newConfig)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    newConfig = config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            newConfigs.add(newConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        ProviderConfig[] configArray = newConfigs.toArray(PC0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return new ProviderList(configArray, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return configs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Return the Provider at the specified index. Returns EMPTY_PROVIDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * if the provider could not be loaded at this time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    Provider getProvider(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Provider p = configs[index].getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return (p != null) ? p : EMPTY_PROVIDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Return an unmodifiable List of all Providers in this List. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * individual Providers are loaded on demand. Elements that could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * be initialized are replaced with EMPTY_PROVIDER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public List<Provider> providers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return userList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private ProviderConfig getProviderConfig(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int index = getIndex(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return (index != -1) ? configs[index] : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    // return the Provider with the specified name or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public Provider getProvider(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        ProviderConfig config = getProviderConfig(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return (config == null) ? null : config.getProvider();
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 index at which the provider with the specified name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * installed or -1 if it is not present in this ProviderList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public int getIndex(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for (int i = 0; i < configs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Provider p = getProvider(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (p.getName().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    // attempt to load all Providers not already loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private int loadAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (allLoaded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return configs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            debug.println("Loading all providers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            new Exception("Call trace").printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        int n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        for (int i = 0; i < configs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            Provider p = configs[i].getProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                n++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (n == configs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            allLoaded = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Try to load all Providers and return the ProviderList. If one or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * more Providers could not be loaded, a new ProviderList with those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * entries removed is returned. Otherwise, the method returns this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    ProviderList removeInvalid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        int n = loadAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (n == configs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        ProviderConfig[] newConfigs = new ProviderConfig[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        for (int i = 0, j = 0; i < configs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            ProviderConfig config = configs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (config.isLoaded()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                newConfigs[j++] = config;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return new ProviderList(newConfigs, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    // return the providers as an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public Provider[] toArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return providers().toArray(P0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    // return a String representation of this ProviderList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return Arrays.asList(configs).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Return a Service describing an implementation of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * algorithm from the Provider with the highest precedence that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * supports that algorithm. Return null if no Provider supports this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public Service getService(String type, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        for (int i = 0; i < configs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Provider p = getProvider(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            Service s = p.getService(type, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Return a List containing all the Services describing implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * of the specified algorithms in precedence order. If no implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * exists, this method returns an empty List.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * The elements of this list are determined lazily on demand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * The List returned is NOT thread safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public List<Service> getServices(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return new ServiceList(type, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * This method exists for compatibility with JCE only. It will be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * once JCE has been changed to use the replacement method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @deprecated use getServices(List<ServiceId>) instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public List<Service> getServices(String type, List<String> algorithms) {
7973
dffe8439eb20 7005608: diamond conversion of JCA and crypto providers
smarks
parents: 5506
diff changeset
   359
        List<ServiceId> ids = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        for (String alg : algorithms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            ids.add(new ServiceId(type, alg));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return getServices(ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public List<Service> getServices(List<ServiceId> ids) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return new ServiceList(ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Inner class for a List of Services. Custom List implementation in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * order to delay Provider initialization and lookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Not thread safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private final class ServiceList extends AbstractList<Service> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // type and algorithm for simple lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // avoid allocating/traversing the ServiceId list for these lookups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        private final String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // list of ids for parallel lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // if ids is non-null, type and algorithm are null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        private final List<ServiceId> ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        // first service we have found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        // it is stored in a separate variable so that we can avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // allocating the services list if we do not need the second service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // this is the case if we don't failover (failovers are typically rare)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        private Service firstService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        // list of the services we have found so far
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        private List<Service> services;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // index into config[] of the next provider we need to query
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        private int providerIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        ServiceList(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            this.ids = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        ServiceList(List<ServiceId> ids) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            this.type = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            this.algorithm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            this.ids = ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        private void addService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (firstService == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                firstService = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                if (services == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    services = new ArrayList<Service>(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    services.add(firstService);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                services.add(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        private Service tryGet(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                if ((index == 0) && (firstService != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    return firstService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                } else if ((services != null) && (services.size() > index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    return services.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (providerIndex >= configs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                // check all algorithms in this provider before moving on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                Provider p = getProvider(providerIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                if (type != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    // simple lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    Service s = p.getService(type, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        addService(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    // parallel lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    for (ServiceId id : ids) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        Service s = p.getService(id.type, id.algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                            addService(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public Service get(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            Service s = tryGet(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (services != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                n = services.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                n = (firstService != null) ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            while (tryGet(n) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                n++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // override isEmpty() and iterator() to not call size()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // this avoids loading + checking all Providers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return (tryGet(0) == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        public Iterator<Service> iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return new Iterator<Service>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    return tryGet(index) != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                public Service next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    Service s = tryGet(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                    return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
}