View Javadoc
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.sql;
21  
22  import java.sql.Driver;
23  import java.sql.DriverManager;
24  import java.sql.SQLException;
25  
26  import com.garygregory.jcommander.converters.AbstractBaseConverter;
27  
28  /**
29   * Converts a {@link String} into a SQL {@link Driver}.
30   * <p>
31   * For a description of the format, see {@link DriverManager#getDriver(String)}.
32   * </p>
33   * 
34   * <p>
35   * Example:
36   * </p>
37   * 
38   * <pre class="prettyprint">
39   * <code class="language-java">&#64;Parameter(names = { "--driver" }, converter = DriverConverter.class)
40   * private Driver driver;</code>
41   * </pre>
42   * <p>
43   * 
44   * @see Driver
45   * @see DriverManager#getDriver(String)
46   * 
47   * @since 1.0.0
48   * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
49   */
50  public class DriverConverter extends AbstractBaseConverter<Driver> {
51  
52      /**
53       * Constructs a converter.
54       * 
55       * @param optionName
56       *            The option name, may be null.
57       */
58      public DriverConverter(final String optionName) {
59          super(optionName, Driver.class);
60      }
61  
62      @Override
63      protected Driver convertImpl(final String value) throws SQLException {
64          return DriverManager.getDriver(value);
65      }
66  
67  }