KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > URLConverterTrim


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcTypeRegistry;
16 import com.versant.core.jdbc.metadata.JdbcColumn;
17
18 import java.net.URL JavaDoc;
19 import java.net.MalformedURLException JavaDoc;
20
21 import com.versant.core.common.BindingSupportImpl;
22
23 /**
24  * This converter converts java.net.URL objects to and from SQL. It assumes
25  * that the File is stored in a column compatible with ResultSet.getString and
26  * PreparedStatement.setString.
27  * @keep-all
28  */

29 public class URLConverterTrim extends TypeAsTrimStringConverterBase {
30
31     public static class Factory extends NoArgJdbcConverterFactory {
32
33         private URLConverterTrim converter;
34
35         /**
36          * Create a converter for col using args as parameters. Return null if
37          * no converter is required.
38          */

39         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
40                 JdbcTypeRegistry jdbcTypeRegistry) {
41             if (converter == null) converter = new URLConverterTrim();
42             return converter;
43         }
44
45     }
46
47     /**
48      * Create an instance of our type from a String.
49      * @param s String to use (never null)
50      */

51     protected Object JavaDoc fromString(String JavaDoc s) {
52         try {
53             return new URL JavaDoc(s);
54         } catch (MalformedURLException JavaDoc e) {
55             throw BindingSupportImpl.getInstance().fatalDatastore(e.toString(), e);
56         }
57     }
58
59     /**
60      * Get the type of our expected value objects (e.g. java.util.Locale
61      * for a converter for Locale's).
62      */

63     public Class JavaDoc getValueType() {
64         return URL JavaDoc.class;
65     }
66
67 }
68
69
Popular Tags