View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation.
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.apache.commons.betwixt.schema;
18  
19  import java.math.BigDecimal;
20  import java.math.BigInteger;
21  
22  /***
23   * Default <code>DataTypeMapper</code>implementation.
24   * Provides a reasonably standard and compatible mapping.
25   * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
26   * @version $Revision: 155402 $
27   */
28  public class DefaultDataTypeMapper extends DataTypeMapper {
29  
30      /***
31       * This implementation provides
32       * @see org.apache.commons.betwixt.schema.DataTypeMapper#toXMLSchemaDataType(java.lang.Class)
33       */
34      public String toXMLSchemaDataType(Class type) {
35          // default mapping is to string
36          String result = "xsd:string";
37          if (String.class.equals(type)) {
38              result = "xsd:string";
39              
40          } else if (BigInteger.class.equals(type)) {
41              result = "xsd:integer";
42              
43          } else if (Integer.TYPE.equals(type)) {
44              result = "xsd:int";
45  
46          } else if (Integer.class.equals(type)) {
47              result = "xsd:int";
48              
49          } else if (Long.TYPE.equals(type)) {
50              result = "xsd:long";
51  
52          } else if (Long.class.equals(type)) {
53              result = "xsd:long";
54  
55          } else if (Short.TYPE.equals(type)) {
56              result = "xsd:short";
57  
58          } else if (Short.class.equals(type)) {
59              result = "xsd:short";
60  
61          } else if (BigDecimal.class.equals(type)) {
62              result = "xsd:decimal";
63  
64          } else if (Float.TYPE.equals(type)) {
65              result = "xsd:float";
66  
67          } else if (Float.class.equals(type)) {
68              result = "xsd:float";
69  
70          } else if (Double.TYPE.equals(type)) {
71              result = "xsd:double";
72  
73          } else if (Double.class.equals(type)) {
74              result = "xsd:double";
75  
76          } else if (Boolean.TYPE.equals(type)) {
77              result = "xsd:boolean";
78  
79          } else if (Boolean.class.equals(type)) {
80              result = "xsd:boolean";
81  
82          } else if (Byte.TYPE.equals(type)) {
83              result = "xsd:byte";
84  
85          } else if (Byte.class.equals(type)) {
86              result = "xsd:byte";
87  
88          } else if (java.util.Date.class.equals(type)) {
89              result = "xsd:dateTime";
90              
91          } else if (java.sql.Date.class.equals(type)) {
92              result = "xsd:date";
93  
94          } else if (java.sql.Time.class.equals(type)) {
95              result = "xsd:time";
96          }
97          
98          return result;
99      }
100     
101     
102 }