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