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