1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.jcr;
25
26 import javax.jcr.PropertyType;
27 import net.jcip.annotations.Immutable;
28
29
30
31
32
33 @Immutable
34 public class PropertyTypeUtil {
35
36
37
38
39
40
41
42
43
44
45
46
47 static final int jcrPropertyTypeFor( org.modeshape.graph.property.Property property ) {
48 Object value = property.getFirstValue();
49 if (value == null) return PropertyType.UNDEFINED;
50
51
52 return jcrPropertyTypeFor(org.modeshape.graph.property.PropertyType.discoverType(value));
53 }
54
55
56
57
58
59
60
61 public static final org.modeshape.graph.property.PropertyType dnaPropertyTypeFor( int jcrPropertyType ) {
62
63 switch (jcrPropertyType) {
64 case PropertyType.STRING:
65 return org.modeshape.graph.property.PropertyType.STRING;
66 case PropertyType.BINARY:
67 return org.modeshape.graph.property.PropertyType.BINARY;
68 case PropertyType.BOOLEAN:
69 return org.modeshape.graph.property.PropertyType.BOOLEAN;
70 case PropertyType.DOUBLE:
71 return org.modeshape.graph.property.PropertyType.DOUBLE;
72 case PropertyType.LONG:
73 return org.modeshape.graph.property.PropertyType.LONG;
74 case PropertyType.DATE:
75 return org.modeshape.graph.property.PropertyType.DATE;
76 case PropertyType.DECIMAL:
77 return org.modeshape.graph.property.PropertyType.DECIMAL;
78 case PropertyType.PATH:
79 return org.modeshape.graph.property.PropertyType.PATH;
80 case PropertyType.NAME:
81 return org.modeshape.graph.property.PropertyType.NAME;
82 case PropertyType.REFERENCE:
83 return org.modeshape.graph.property.PropertyType.REFERENCE;
84 case PropertyType.WEAKREFERENCE:
85 return org.modeshape.graph.property.PropertyType.WEAKREFERENCE;
86 }
87 assert false;
88 return org.modeshape.graph.property.PropertyType.STRING;
89 }
90
91
92
93
94
95
96
97 public static final int jcrPropertyTypeFor( org.modeshape.graph.property.PropertyType dnaPropertyType ) {
98
99 switch (dnaPropertyType) {
100 case STRING:
101 return PropertyType.STRING;
102 case NAME:
103 return PropertyType.NAME;
104 case LONG:
105 return PropertyType.LONG;
106 case UUID:
107 return PropertyType.STRING;
108 case URI:
109 return PropertyType.STRING;
110 case PATH:
111 return PropertyType.PATH;
112 case BOOLEAN:
113 return PropertyType.BOOLEAN;
114 case DATE:
115 return PropertyType.DATE;
116 case DECIMAL:
117 return PropertyType.DECIMAL;
118 case DOUBLE:
119 return PropertyType.DOUBLE;
120 case BINARY:
121 return PropertyType.BINARY;
122 case OBJECT:
123 return PropertyType.UNDEFINED;
124 case REFERENCE:
125 return PropertyType.REFERENCE;
126 case WEAKREFERENCE:
127 return PropertyType.WEAKREFERENCE;
128 }
129 assert false;
130 return PropertyType.UNDEFINED;
131 }
132
133 }