01: /*
02: * Copyright 2006 Le Duc Bao, Ralf Joachim
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package org.castor.ddlgen;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.castor.ddlgen.typeinfo.TypeInfo;
22:
23: /**
24: * AbstractTypeMapper is the base class for mapping JDBC supported type and
25: * RDBMS data type.
26: * <p/>The initialize(Configuration) is used to defined the mapping table in which
27: * the configuration is handled parameters for TypeInfo. Please refer to
28: * org.castor.ddl.typeinfo for TypeInfo definitions
29: *
30: * @author <a href="mailto:leducbao AT gmail DOT com">Le Duc Bao</a>
31: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
32: * @version $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
33: * @since 1.1
34: */
35: public abstract class AbstractTypeMapper implements TypeMapper {
36: //--------------------------------------------------------------------------
37:
38: /** Map of known types which associates JDBC type to corresponding TypeInfo. */
39: private final Map _types = new HashMap();
40:
41: //--------------------------------------------------------------------------
42:
43: /**
44: * Construct an abstract TypeMapper using given configuration to get default
45: * parameters for parameterized types.
46: *
47: * @param conf The configuration to get default parameter values from.
48: */
49: protected AbstractTypeMapper(final DDLGenConfiguration conf) {
50: initialize(conf);
51: }
52:
53: /**
54: * Initialize map of known types using given configuration to get default parameters
55: * for parameterized types.
56: *
57: * @param conf The configuration to get default parameter values from.
58: */
59: protected abstract void initialize(final DDLGenConfiguration conf);
60:
61: //--------------------------------------------------------------------------
62:
63: /**
64: * Add TypeInfo to map of known types.
65: *
66: * @param type The TypeInfo to add.
67: */
68: protected final void add(final TypeInfo type) {
69: _types.put(type.getJdbcType(), type);
70: }
71:
72: /**
73: * {@inheritDoc}
74: */
75: public final TypeInfo getType(final String jdcbType) {
76: String ddlJdbcType = jdcbType.toLowerCase();
77:
78: if (ddlJdbcType.matches(".*\\Q[\\E.*")) {
79: ddlJdbcType = ddlJdbcType.substring(0, ddlJdbcType
80: .indexOf("["));
81: }
82: return (TypeInfo) _types.get(ddlJdbcType);
83: }
84:
85: //--------------------------------------------------------------------------
86: }
|