001/** 002 * Copyright (C) 2016 Gary Gregory. All rights reserved. 003 * 004 * See the NOTICE.txt file distributed with this work for additional 005 * information regarding copyright ownership. 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package com.garygregory.jcommander.converters.security.cert; 021 022import java.security.cert.CertificateException; 023import java.security.cert.CertificateFactory; 024 025import com.garygregory.jcommander.converters.AbstractBaseConverter; 026 027/** 028 * Converts a {@link String} into a {@link CertificateFactory}. 029 * <p> 030 * For a description of the format, see {@link CertificateFactory#getInstance(String)}. 031 * </p> 032 * 033 * <p> 034 * Example: 035 * </p> 036 * 037 * <pre class="prettyprint"> 038 * <code class="language-java">@Parameter(names = { "--certificateFactory" }, converter = CertificateFactoryConverter.class) 039 * private CertificateFactory certificateFactory;</code> 040 * </pre> 041 * <p> 042 * 043 * @see CertificateFactory 044 * @see CertificateFactory#getInstance(String) 045 * 046 * @since 1.0.0 047 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a> 048 */ 049public class CertificateFactoryConverter extends AbstractBaseConverter<CertificateFactory> { 050 051 /** 052 * Constructs a converter. 053 * 054 * @param optionName 055 * The option name, may be null. 056 */ 057 public CertificateFactoryConverter(final String optionName) { 058 super(optionName, CertificateFactory.class); 059 } 060 061 @Override 062 protected CertificateFactory convertImpl(final String value) throws CertificateException { 063 return CertificateFactory.getInstance(value); 064 } 065 066}