1 /**
2 * Copyright (C) 2016 Gary Gregory. All rights reserved.
3 *
4 * See the NOTICE.txt file distributed with this work for additional
5 * information regarding copyright ownership.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package com.garygregory.jcommander.converters.security.cert;
21
22 import java.security.NoSuchAlgorithmException;
23 import java.security.cert.CertPathValidator;
24
25 import com.garygregory.jcommander.converters.AbstractBaseConverter;
26
27 /**
28 * Converts a {@link String} into a {@link CertPathValidator}.
29 * <p>
30 * For a description of the format, see {@link CertPathValidator#getInstance(String)}.
31 * </p>
32 *
33 * <p>
34 * Example:
35 * </p>
36 *
37 * <pre class="prettyprint">
38 * <code class="language-java">@Parameter(names = { "--certPathValidator" }, converter = CertPathValidatorConverter.class)
39 * private CertPathValidator certPathValidator;</code>
40 * </pre>
41 * <p>
42 *
43 * @see CertPathValidator
44 * @see CertPathValidator#getInstance(String)
45 *
46 * @since 1.0.0
47 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
48 */
49 public class CertPathValidatorConverter extends AbstractBaseConverter<CertPathValidator> {
50
51 /**
52 * Constructs a converter.
53 *
54 * @param optionName
55 * The option name, may be null.
56 */
57 public CertPathValidatorConverter(final String optionName) {
58 super(optionName, CertPathValidator.class);
59 }
60
61 @Override
62 protected CertPathValidator convertImpl(final String value) throws NoSuchAlgorithmException {
63 return CertPathValidator.getInstance(value);
64 }
65
66 }