View Javadoc
1   /*
2    * Copyright (C) 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.codehaus.plexus.component.configurator.converters.basic;
18  
19  import java.net.URI;
20  import java.net.URISyntaxException;
21  
22  import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
23  
24  /**
25   * Converter for {@link URI} objects.
26   *
27   * @version $Id$
28   */
29  public class UriConverter
30      extends AbstractBasicConverter
31  {
32      public boolean canConvert(final Class type) {
33          assert type != null;
34  
35          return type.equals(URI.class);
36      }
37  
38      public Object fromString(final String str) throws ComponentConfigurationException {
39          assert str != null;
40  
41          try {
42              return new URI(str);
43          }
44          catch (URISyntaxException e) {
45              throw new ComponentConfigurationException("Unable to convert to URI: " + str, e);
46          }
47      }
48  }