View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17  
18  package org.apache.commons.betwixt.schema;
19  
20  import java.math.BigDecimal;
21  import java.math.BigInteger;
22  
23  /**
24   * Default <code>DataTypeMapper</code>implementation.
25   * Provides a reasonably standard and compatible mapping.
26   * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
27   * @version $Revision: 561314 $
28   */
29  public class DefaultDataTypeMapper extends DataTypeMapper {
30  
31      /**
32       * This implementation provides
33       * @see org.apache.commons.betwixt.schema.DataTypeMapper#toXMLSchemaDataType(java.lang.Class)
34       */
35      public String toXMLSchemaDataType(Class type) {
36          // default mapping is to string
37          String result = "xsd:string";
38          if (String.class.equals(type)) {
39              result = "xsd:string";
40              
41          } else if (BigInteger.class.equals(type)) {
42              result = "xsd:integer";
43              
44          } else if (Integer.TYPE.equals(type)) {
45              result = "xsd:int";
46  
47          } else if (Integer.class.equals(type)) {
48              result = "xsd:int";
49              
50          } else if (Long.TYPE.equals(type)) {
51              result = "xsd:long";
52  
53          } else if (Long.class.equals(type)) {
54              result = "xsd:long";
55  
56          } else if (Short.TYPE.equals(type)) {
57              result = "xsd:short";
58  
59          } else if (Short.class.equals(type)) {
60              result = "xsd:short";
61  
62          } else if (BigDecimal.class.equals(type)) {
63              result = "xsd:decimal";
64  
65          } else if (Float.TYPE.equals(type)) {
66              result = "xsd:float";
67  
68          } else if (Float.class.equals(type)) {
69              result = "xsd:float";
70  
71          } else if (Double.TYPE.equals(type)) {
72              result = "xsd:double";
73  
74          } else if (Double.class.equals(type)) {
75              result = "xsd:double";
76  
77          } else if (Boolean.TYPE.equals(type)) {
78              result = "xsd:boolean";
79  
80          } else if (Boolean.class.equals(type)) {
81              result = "xsd:boolean";
82  
83          } else if (Byte.TYPE.equals(type)) {
84              result = "xsd:byte";
85  
86          } else if (Byte.class.equals(type)) {
87              result = "xsd:byte";
88  
89          } else if (java.util.Date.class.equals(type)) {
90              result = "xsd:dateTime";
91              
92          } else if (java.sql.Date.class.equals(type)) {
93              result = "xsd:date";
94  
95          } else if (java.sql.Time.class.equals(type)) {
96              result = "xsd:time";
97          }
98          
99          return result;
100     }
101     
102     
103 }