|
1 | | -/* |
2 | | - * Copyright (c) 2009-2018 LabKey Corporation |
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.labkey.api.exp.property; |
17 | | - |
18 | | -import org.labkey.api.exp.PropertyType; |
19 | | -import org.labkey.api.util.SimpleTime; |
20 | | - |
21 | | -import java.io.File; |
22 | | -import java.math.BigDecimal; |
23 | | -import java.nio.ByteBuffer; |
24 | | -import java.sql.Time; |
25 | | -import java.sql.Timestamp; |
26 | | -import java.util.Arrays; |
27 | | -import java.util.Date; |
28 | | -import java.util.HashSet; |
29 | | -import java.util.Set; |
30 | | - |
31 | | -/** |
32 | | -* User: adam |
33 | | -* Date: Apr 29, 2009 |
34 | | -* Time: 9:44:07 AM |
35 | | -*/ |
36 | | -// TODO: Consider getting rid of this, adding the xsd: to PropertyType instead |
37 | | -public enum Type |
38 | | -{ |
39 | | - StringType("Text (String)", "xsd:string", "varchar", String.class, ByteBuffer.class), |
40 | | - IntType("Integer", "xsd:int", "integer", Integer.class, Integer.TYPE, Short.class, Short.TYPE, Byte.class, Byte.TYPE), |
41 | | - LongType("Long", "xsd:long", "bigint", Long.class, long.class), |
42 | | - DoubleType("Number (Double)", "xsd:double", "double", Double.class, Double.TYPE, BigDecimal.class), // Double.TYPE is here because manually created datasets with required doubles return Double.TYPE as Class |
43 | | - FloatType("Number (Float)", "xsd:float", "float", Float.class, Float.TYPE), |
44 | | - TimeType("Time", PropertyType.TIME.getTypeUri(), "time", Time.class, SimpleTime.class), |
45 | | - DateTimeType("DateTime", "xsd:dateTime", "timestamp", Date.class, Timestamp.class, java.sql.Date.class), |
46 | | - BooleanType("Boolean", "xsd:boolean", "boolean", Boolean.class, Boolean.TYPE), |
47 | | - AttachmentType("Attachment", "xsd:attachment", "varchar", String.class, File.class); |
48 | | - |
49 | | - private final String label; |
50 | | - private final String xsd; |
51 | | - private final Class clazz; |
52 | | - private final Set<Class> allClasses = new HashSet<>(); |
53 | | - private final String sqlTypeName; |
54 | | - |
55 | | - Type(String label, String xsd, String sqlTypeName, Class clazz, Class... additionalClasses) |
56 | | - { |
57 | | - this.label = label; |
58 | | - this.xsd = xsd; |
59 | | - this.clazz = clazz; |
60 | | - this.allClasses.add(clazz); |
61 | | - this.allClasses.addAll(Arrays.asList(additionalClasses)); |
62 | | - this.sqlTypeName = sqlTypeName; |
63 | | - } |
64 | | - |
65 | | - public String getLabel() |
66 | | - { |
67 | | - return label; |
68 | | - } |
69 | | - |
70 | | - public String getXsdType() |
71 | | - { |
72 | | - return xsd; |
73 | | - } |
74 | | - |
75 | | - public Class getJavaClass() |
76 | | - { |
77 | | - return clazz; |
78 | | - } |
79 | | - |
80 | | - public boolean matches(Class clazz) |
81 | | - { |
82 | | - return allClasses.contains(clazz); |
83 | | - } |
84 | | - |
85 | | - public String getSqlTypeName() |
86 | | - { |
87 | | - return sqlTypeName; |
88 | | - } |
89 | | - |
90 | | - public boolean isNumeric() |
91 | | - { |
92 | | - return this == IntType || this == DoubleType; |
93 | | - } |
94 | | - |
95 | | - public static Type getTypeByXsdType(String xsd) |
96 | | - { |
97 | | - for (Type type : values()) |
98 | | - { |
99 | | - if (type.getXsdType().equals(xsd)) |
100 | | - return type; |
101 | | - } |
102 | | - return null; |
103 | | - } |
104 | | - |
105 | | - public static Type getTypeByClass(Class clazz) |
106 | | - { |
107 | | - for (Type type : values()) |
108 | | - { |
109 | | - if (type.matches(clazz)) |
110 | | - return type; |
111 | | - } |
112 | | - return null; |
113 | | - } |
114 | | -} |
| 1 | +/* |
| 2 | + * Copyright (c) 2009-2018 LabKey Corporation |
| 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.labkey.api.exp.property; |
| 17 | + |
| 18 | +import org.labkey.api.data.MultiChoice; |
| 19 | +import org.labkey.api.exp.PropertyType; |
| 20 | +import org.labkey.api.util.SimpleTime; |
| 21 | + |
| 22 | +import java.io.File; |
| 23 | +import java.math.BigDecimal; |
| 24 | +import java.nio.ByteBuffer; |
| 25 | +import java.sql.Time; |
| 26 | +import java.sql.Timestamp; |
| 27 | +import java.util.Arrays; |
| 28 | +import java.util.Date; |
| 29 | +import java.util.HashSet; |
| 30 | +import java.util.Set; |
| 31 | + |
| 32 | +/** |
| 33 | +* User: adam |
| 34 | +* Date: Apr 29, 2009 |
| 35 | +* Time: 9:44:07 AM |
| 36 | +*/ |
| 37 | +// TODO: Consider getting rid of this, adding the xsd: to PropertyType instead |
| 38 | +public enum Type |
| 39 | +{ |
| 40 | + StringType("Text (String)", "xsd:string", "varchar", String.class, ByteBuffer.class), |
| 41 | + IntType("Integer", "xsd:int", "integer", Integer.class, Integer.TYPE, Short.class, Short.TYPE, Byte.class, Byte.TYPE), |
| 42 | + LongType("Long", "xsd:long", "bigint", Long.class, long.class), |
| 43 | + DoubleType("Number (Double)", "xsd:double", "double", Double.class, Double.TYPE, BigDecimal.class), // Double.TYPE is here because manually created datasets with required doubles return Double.TYPE as Class |
| 44 | + FloatType("Number (Float)", "xsd:float", "float", Float.class, Float.TYPE), |
| 45 | + TimeType("Time", PropertyType.TIME.getTypeUri(), "time", Time.class, SimpleTime.class), |
| 46 | + DateTimeType("DateTime", "xsd:dateTime", "timestamp", Date.class, Timestamp.class, java.sql.Date.class), |
| 47 | + BooleanType("Boolean", "xsd:boolean", "boolean", Boolean.class, Boolean.TYPE), |
| 48 | + AttachmentType("Attachment", "xsd:attachment", "varchar", String.class, File.class), |
| 49 | + MultiChoiceArrayType("MultiChoiceArray", "xsd:multichoicearray", "varchar", MultiChoice.Array.class); |
| 50 | + |
| 51 | + private final String label; |
| 52 | + private final String xsd; |
| 53 | + private final Class clazz; |
| 54 | + private final Set<Class> allClasses = new HashSet<>(); |
| 55 | + private final String sqlTypeName; |
| 56 | + |
| 57 | + Type(String label, String xsd, String sqlTypeName, Class clazz, Class... additionalClasses) |
| 58 | + { |
| 59 | + this.label = label; |
| 60 | + this.xsd = xsd; |
| 61 | + this.clazz = clazz; |
| 62 | + this.allClasses.add(clazz); |
| 63 | + this.allClasses.addAll(Arrays.asList(additionalClasses)); |
| 64 | + this.sqlTypeName = sqlTypeName; |
| 65 | + } |
| 66 | + |
| 67 | + public String getLabel() |
| 68 | + { |
| 69 | + return label; |
| 70 | + } |
| 71 | + |
| 72 | + public String getXsdType() |
| 73 | + { |
| 74 | + return xsd; |
| 75 | + } |
| 76 | + |
| 77 | + public Class getJavaClass() |
| 78 | + { |
| 79 | + return clazz; |
| 80 | + } |
| 81 | + |
| 82 | + public boolean matches(Class clazz) |
| 83 | + { |
| 84 | + return allClasses.contains(clazz); |
| 85 | + } |
| 86 | + |
| 87 | + public String getSqlTypeName() |
| 88 | + { |
| 89 | + return sqlTypeName; |
| 90 | + } |
| 91 | + |
| 92 | + public boolean isNumeric() |
| 93 | + { |
| 94 | + return this == IntType || this == DoubleType; |
| 95 | + } |
| 96 | + |
| 97 | + public static Type getTypeByXsdType(String xsd) |
| 98 | + { |
| 99 | + for (Type type : values()) |
| 100 | + { |
| 101 | + if (type.getXsdType().equals(xsd)) |
| 102 | + return type; |
| 103 | + } |
| 104 | + return null; |
| 105 | + } |
| 106 | + |
| 107 | + public static Type getTypeByClass(Class clazz) |
| 108 | + { |
| 109 | + for (Type type : values()) |
| 110 | + { |
| 111 | + if (type.matches(clazz)) |
| 112 | + return type; |
| 113 | + } |
| 114 | + return null; |
| 115 | + } |
| 116 | +} |
0 commit comments