01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.sql.conv;
12:
13: import com.versant.core.jdbc.JdbcConverter;
14: import com.versant.core.jdbc.JdbcTypeRegistry;
15: import com.versant.core.jdbc.metadata.JdbcColumn;
16:
17: import java.net.URL;
18: import java.net.MalformedURLException;
19:
20: import com.versant.core.common.BindingSupportImpl;
21:
22: /**
23: * This converter converts java.net.URL objects to and from SQL. It assumes
24: * that the File is stored in a column compatible with ResultSet.getString and
25: * PreparedStatement.setString.
26: * @keep-all
27: */
28: public class URLConverter extends TypeAsStringConverterBase {
29:
30: public static class Factory extends NoArgJdbcConverterFactory {
31:
32: private URLConverter converter;
33:
34: /**
35: * Create a converter for col using args as parameters. Return null if
36: * no converter is required.
37: */
38: public JdbcConverter createJdbcConverter(JdbcColumn col,
39: Object args, JdbcTypeRegistry jdbcTypeRegistry) {
40: if (converter == null)
41: converter = new URLConverter();
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 fromString(String s) {
52: try {
53: return new URL(s);
54: } catch (MalformedURLException e) {
55: throw BindingSupportImpl.getInstance().fatalDatastore(
56: e.toString(), e);
57: }
58: }
59:
60: /**
61: * Get the type of our expected value objects (e.g. java.util.Locale
62: * for a converter for Locale's).
63: */
64: public Class getValueType() {
65: return URL.class;
66: }
67:
68: }
|