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