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; 021 022import java.security.Provider; 023import java.security.Security; 024 025import com.garygregory.jcommander.converters.AbstractBaseConverter; 026 027/** 028 * Converts a {@link String} into a {@link Provider}. 029 * <p> 030 * For a description of the format, see {@link Security#getProvider(String)}. 031 * </p> 032 * 033 * <p> 034 * Example: 035 * </p> 036 * 037 * <pre class="prettyprint"> 038 * <code class="language-java">@Parameter(names = { "--provider" }, converter = ProviderConverter.class) 039 * private Provider provider;</code> 040 * </pre> 041 * <p> 042 * 043 * @see Provider 044 * @see Security 045 * @see Security#getProvider(String) 046 * 047 * @since 1.0.0 048 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a> 049 */ 050public class ProviderConverter extends AbstractBaseConverter<Provider> { 051 052 /** 053 * Constructs a converter. 054 * 055 * @param optionName 056 * The option name, may be null. 057 */ 058 public ProviderConverter(final String optionName) { 059 super(optionName, Provider.class); 060 } 061 062 @Override 063 protected Provider convertImpl(final String value) { 064 return Security.getProvider(value); 065 } 066 067}