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