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.graph.property.basic;
25
26 import java.io.InputStream;
27 import java.io.Reader;
28 import java.math.BigDecimal;
29 import java.net.URI;
30 import java.util.Calendar;
31 import java.util.Date;
32 import java.util.UUID;
33 import net.jcip.annotations.Immutable;
34 import org.modeshape.common.text.TextDecoder;
35 import org.modeshape.graph.GraphI18n;
36 import org.modeshape.graph.property.Binary;
37 import org.modeshape.graph.property.DateTime;
38 import org.modeshape.graph.property.IoException;
39 import org.modeshape.graph.property.Name;
40 import org.modeshape.graph.property.Path;
41 import org.modeshape.graph.property.PropertyType;
42 import org.modeshape.graph.property.Reference;
43 import org.modeshape.graph.property.ValueFactory;
44 import org.modeshape.graph.property.ValueFormatException;
45
46
47
48
49 @Immutable
50 public class UuidReferenceValueFactory extends AbstractValueFactory<Reference> {
51
52 public UuidReferenceValueFactory( TextDecoder decoder,
53 ValueFactory<String> stringValueFactory ) {
54 super(PropertyType.REFERENCE, decoder, stringValueFactory);
55 }
56
57
58
59
60 public Reference create( String value ) {
61 if (value == null) return null;
62 try {
63 UUID uuid = UUID.fromString(value);
64 return new UuidReference(uuid);
65 } catch (IllegalArgumentException err) {
66 throw new ValueFormatException(value, getPropertyType(),
67 GraphI18n.errorConvertingType.text(String.class.getSimpleName(),
68 Reference.class.getSimpleName(),
69 value), err);
70 }
71 }
72
73
74
75
76 public Reference create( String value,
77 TextDecoder decoder ) {
78
79 return create(getDecoder(decoder).decode(value));
80 }
81
82
83
84
85 public Reference create( int value ) {
86 throw new ValueFormatException(value, getPropertyType(),
87 GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
88 Integer.class.getSimpleName(),
89 value));
90 }
91
92
93
94
95 public Reference create( long value ) {
96 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
97 Long.class.getSimpleName(),
98 value));
99 }
100
101
102
103
104 public Reference create( boolean value ) {
105 throw new ValueFormatException(value, getPropertyType(),
106 GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
107 Boolean.class.getSimpleName(),
108 value));
109 }
110
111
112
113
114 public Reference create( float value ) {
115 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
116 Float.class.getSimpleName(),
117 value));
118 }
119
120
121
122
123 public Reference create( double value ) {
124 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
125 Double.class.getSimpleName(),
126 value));
127 }
128
129
130
131
132 public Reference create( BigDecimal value ) {
133 throw new ValueFormatException(value, getPropertyType(),
134 GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
135 BigDecimal.class.getSimpleName(),
136 value));
137 }
138
139
140
141
142 public Reference create( Calendar value ) {
143 throw new ValueFormatException(value, getPropertyType(),
144 GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
145 Calendar.class.getSimpleName(),
146 value));
147 }
148
149
150
151
152 public Reference create( Date value ) {
153 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
154 Date.class.getSimpleName(),
155 value));
156 }
157
158
159
160
161
162
163 public Reference create( DateTime value ) throws ValueFormatException {
164 throw new ValueFormatException(value, getPropertyType(),
165 GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
166 DateTime.class.getSimpleName(),
167 value));
168 }
169
170
171
172
173 public Reference create( Name value ) {
174 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
175 Name.class.getSimpleName(),
176 value));
177 }
178
179
180
181
182 public Reference create( Path value ) {
183 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
184 Path.class.getSimpleName(),
185 value));
186 }
187
188
189
190
191 public Reference create( Reference value ) {
192 return value;
193 }
194
195
196
197
198
199
200 public Reference create( UUID value ) {
201 if (value == null) return null;
202 return new UuidReference(value);
203 }
204
205
206
207
208 public Reference create( URI value ) {
209 throw new ValueFormatException(value, getPropertyType(), GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
210 Date.class.getSimpleName(),
211 value));
212 }
213
214
215
216
217 public Reference create( byte[] value ) {
218
219 return create(getStringValueFactory().create(value));
220 }
221
222
223
224
225
226
227 public Reference create( Binary value ) throws ValueFormatException, IoException {
228
229 return create(getStringValueFactory().create(value));
230 }
231
232
233
234
235 public Reference create( InputStream stream,
236 long approximateLength ) throws IoException {
237
238 return create(getStringValueFactory().create(stream, approximateLength));
239 }
240
241
242
243
244 public Reference create( Reader reader,
245 long approximateLength ) throws IoException {
246
247 return create(getStringValueFactory().create(reader, approximateLength));
248 }
249
250
251
252
253 @Override
254 protected Reference[] createEmptyArray( int length ) {
255 return new Reference[length];
256 }
257
258 }