1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package javax.net.ssl;
19
20import java.security.KeyStore;
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24
25/**
26 * The parameters for {@code KeyManager}s. The parameters are a list of
27 * {@code KeyStore.Builder}s.
28 *
29 * @since 1.5
30 * @see KeyStore.Builder
31 */
32public class KeyStoreBuilderParameters implements ManagerFactoryParameters {
33
34    private final List<KeyStore.Builder> ksbuilders;
35
36    /**
37     * Creates a new {@code KeyStoreBuilderParameters} with the specified key
38     * store builder.
39     *
40     * @param builder
41     *            the key store builder.
42     */
43    public KeyStoreBuilderParameters(KeyStore.Builder builder) {
44        if (builder == null) {
45            throw new NullPointerException("builder == null");
46        }
47        ksbuilders = Collections.singletonList(builder);
48    }
49
50    /**
51     * Creates a new {@code KeyStoreBuilderParameters} with the specified list
52     * of {@code KeyStore.Builder}s.
53     *
54     * @param parameters
55     *            the list of key store builders
56     * @throws IllegalArgumentException
57     *             if the specified list is empty.
58     */
59    public KeyStoreBuilderParameters(List<KeyStore.Builder> parameters) {
60        if (parameters == null) {
61            throw new NullPointerException("parameters == null");
62        }
63        if (parameters.isEmpty()) {
64            throw new IllegalArgumentException("parameters.isEmpty()");
65        }
66        ksbuilders = Collections.unmodifiableList(new ArrayList<KeyStore.Builder>(parameters));
67    }
68
69    /**
70     * Returns the unmodifiable list of {@code KeyStore.Builder}s associated
71     * with this parameters instance.
72     *
73     * @return the unmodifiable list of {@code KeyStore.Builder}s.
74     */
75    public List<KeyStore.Builder> getParameters() {
76        return ksbuilders;
77    }
78}
79