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   */
28  public class UriConverter extends AbstractBasicConverter {
29      public boolean canConvert(final Class type) {
30          assert type != null;
31  
32          return type.equals(URI.class);
33      }
34  
35      public Object fromString(final String str) throws ComponentConfigurationException {
36          assert str != null;
37  
38          try {
39              return new URI(str);
40          } catch (URISyntaxException e) {
41              throw new ComponentConfigurationException("Unable to convert to URI: " + str, e);
42          }
43      }
44  }