View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package goldengate.common.xml;
22  
23  import java.sql.Date;
24  import java.sql.Timestamp;
25  
26  /**
27   * Type of Classes supported in Enum type
28   * 
29   * @author Frederic Bregier
30   * 
31   */
32  public enum XmlType {
33      BOOLEAN(Boolean.TYPE), INTEGER(Integer.TYPE), FLOAT(Float.TYPE), CHARACTER(
34              Character.TYPE), BYTE(Byte.TYPE), LONG(Long.TYPE), DOUBLE(
35              Double.TYPE), SHORT(Short.TYPE), SQLDATE(Date.class), TIMESTAMP(
36              Timestamp.class), STRING(String.class), XVAL(XmlValue.class),
37              EMPTY(XmlType.class);
38  
39      public Class<?> classType;
40  
41      /**
42       * @param classType
43       */
44      private XmlType(Class<?> classType) {
45          this.classType = classType;
46      }
47  
48      /**
49       * 
50       * @return the associated Native Java class
51       */
52      public Class<?> getClassType() {
53          return classType;
54      }
55  
56      /**
57       * 
58       * @param value
59       * @return True if the Object is natively compatible with the internal Type
60       */
61      public boolean isNativelyCompatible(Object value) {
62          Class<?> type = value.getClass();
63          switch (this) {
64              case BOOLEAN:
65                  return (type.equals(Boolean.TYPE) || Boolean.class
66                          .isAssignableFrom(type));
67              case INTEGER:
68                  return (type.equals(Integer.TYPE) || Integer.class
69                          .isAssignableFrom(type));
70              case FLOAT:
71                  return (type.equals(Float.TYPE) || Float.class
72                          .isAssignableFrom(type));
73              case CHARACTER:
74                  return (type.equals(Character.TYPE) || Character.class
75                          .isAssignableFrom(type));
76              case BYTE:
77                  return (type.equals(Byte.TYPE) || Byte.class
78                          .isAssignableFrom(type));
79              case LONG:
80                  return (type.equals(Long.TYPE) || Long.class
81                          .isAssignableFrom(type));
82              case DOUBLE:
83                  return (type.equals(Double.TYPE) || Double.class
84                          .isAssignableFrom(type));
85              case SHORT:
86                  return (type.equals(Short.TYPE) || Short.class
87                          .isAssignableFrom(type));
88              case SQLDATE:
89                  return (java.sql.Date.class.isAssignableFrom(type));
90              case TIMESTAMP:
91                  return (Timestamp.class.isAssignableFrom(type));
92              case STRING:
93                  return (String.class.isAssignableFrom(type));
94              case XVAL:
95                  if (type.isArray() &&
96                          type.getName().contains(XmlValue.class.getName())) {
97                      return true;
98                  }
99                  return false;
100         }
101         return false;
102     }
103 
104     public boolean isBoolean() {
105         return this == BOOLEAN;
106     }
107 
108     public boolean isInteger() {
109         return this == INTEGER;
110     }
111 
112     public boolean isFloat() {
113         return this == FLOAT;
114     }
115 
116     public boolean isCharacter() {
117         return this == CHARACTER;
118     }
119 
120     public boolean isByte() {
121         return this == BYTE;
122     }
123 
124     public boolean isLong() {
125         return this == LONG;
126     }
127 
128     public boolean isDouble() {
129         return this == DOUBLE;
130     }
131 
132     public boolean isShort() {
133         return this == SHORT;
134     }
135 
136     public boolean isDate() {
137         return this == SQLDATE;
138     }
139 
140     public boolean isTimestamp() {
141         return this == TIMESTAMP;
142     }
143 
144     public boolean isString() {
145         return this == STRING;
146     }
147 
148     public boolean isXmlValue() {
149         return this == XVAL;
150     }
151     
152     public boolean isEmpty() {
153         return this == EMPTY;
154     }
155 }