001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    
018    package org.apache.commons.betwixt.schema;
019    
020    import java.math.BigDecimal;
021    import java.math.BigInteger;
022    
023    /**
024     * Default <code>DataTypeMapper</code>implementation.
025     * Provides a reasonably standard and compatible mapping.
026     * @author <a href='http://commons.apache.org/'>Apache Commons Team</a>
027     * @version $Revision: 561314 $
028     */
029    public class DefaultDataTypeMapper extends DataTypeMapper {
030    
031        /**
032         * This implementation provides
033         * @see org.apache.commons.betwixt.schema.DataTypeMapper#toXMLSchemaDataType(java.lang.Class)
034         */
035        public String toXMLSchemaDataType(Class type) {
036            // default mapping is to string
037            String result = "xsd:string";
038            if (String.class.equals(type)) {
039                result = "xsd:string";
040                
041            } else if (BigInteger.class.equals(type)) {
042                result = "xsd:integer";
043                
044            } else if (Integer.TYPE.equals(type)) {
045                result = "xsd:int";
046    
047            } else if (Integer.class.equals(type)) {
048                result = "xsd:int";
049                
050            } else if (Long.TYPE.equals(type)) {
051                result = "xsd:long";
052    
053            } else if (Long.class.equals(type)) {
054                result = "xsd:long";
055    
056            } else if (Short.TYPE.equals(type)) {
057                result = "xsd:short";
058    
059            } else if (Short.class.equals(type)) {
060                result = "xsd:short";
061    
062            } else if (BigDecimal.class.equals(type)) {
063                result = "xsd:decimal";
064    
065            } else if (Float.TYPE.equals(type)) {
066                result = "xsd:float";
067    
068            } else if (Float.class.equals(type)) {
069                result = "xsd:float";
070    
071            } else if (Double.TYPE.equals(type)) {
072                result = "xsd:double";
073    
074            } else if (Double.class.equals(type)) {
075                result = "xsd:double";
076    
077            } else if (Boolean.TYPE.equals(type)) {
078                result = "xsd:boolean";
079    
080            } else if (Boolean.class.equals(type)) {
081                result = "xsd:boolean";
082    
083            } else if (Byte.TYPE.equals(type)) {
084                result = "xsd:byte";
085    
086            } else if (Byte.class.equals(type)) {
087                result = "xsd:byte";
088    
089            } else if (java.util.Date.class.equals(type)) {
090                result = "xsd:dateTime";
091                
092            } else if (java.sql.Date.class.equals(type)) {
093                result = "xsd:date";
094    
095            } else if (java.sql.Time.class.equals(type)) {
096                result = "xsd:time";
097            }
098            
099            return result;
100        }
101        
102        
103    }