1 /*
2 * Copyright (C) The Spice Group. All rights reserved.
3 *
4 * This software is published under the terms of the Spice
5 * Software License version 1.1, a copy of which has been included
6 * with this distribution in the LICENSE.txt file.
7 */
8 package org.codehaus.spice.converter.lib;
9
10 import java.net.MalformedURLException;
11 import java.net.URL;
12 import org.codehaus.spice.converter.AbstractConverter;
13 import org.codehaus.spice.converter.ConverterException;
14
15 /***
16 * String to URL converter
17 *
18 * @author Peter Donald
19 * @version $Revision: 1.1 $ $Date: 2003/12/02 08:37:56 $
20 */
21 public class StringToURLConverter
22 extends AbstractConverter
23 {
24 /***
25 * Construct the converter.
26 */
27 public StringToURLConverter()
28 {
29 this( null );
30 }
31
32 /***
33 * Construct the converter with a default value.
34 * If the default value is non-null, it will be returned if unable
35 * to convert object to correct type.
36 *
37 * @param defaultValue the default value
38 */
39 public StringToURLConverter( final URL defaultValue )
40 {
41 super( String.class, URL.class, defaultValue );
42 }
43
44 /***
45 * Converts a String to a URL.
46 *
47 * @param object the original object to convert
48 * @param context the context in which to convert object (unused)
49 * @return the converted object
50 * @throws ConverterException if error converting object
51 */
52 public Object convert( final Object object, final Object context )
53 throws ConverterException
54 {
55 try
56 {
57 return new URL( (String)object );
58 }
59 catch( final MalformedURLException mue )
60 {
61 return noConvert( object, mue );
62 }
63 }
64 }
65
This page was automatically generated by Maven