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.common.util.CheckArg;
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 ObjectValueFactory extends AbstractValueFactory<Object> {
51
52 private final ValueFactory<Binary> binaryValueFactory;
53
54 public ObjectValueFactory( TextDecoder decoder,
55 ValueFactory<String> stringValueFactory,
56 ValueFactory<Binary> binaryValueFactory ) {
57 super(PropertyType.OBJECT, decoder, stringValueFactory);
58 CheckArg.isNotNull(binaryValueFactory, "binaryValueFactory");
59 this.binaryValueFactory = binaryValueFactory;
60 }
61
62
63
64
65 protected ValueFactory<Binary> getBinaryValueFactory() {
66 return this.binaryValueFactory;
67 }
68
69
70
71
72 public Object create( String value ) {
73 return this.getStringValueFactory().create(value);
74 }
75
76
77
78
79 public Object create( String value,
80 TextDecoder decoder ) {
81 return this.getStringValueFactory().create(value, decoder);
82 }
83
84
85
86
87 public Object create( int value ) {
88 return Integer.valueOf(value);
89 }
90
91
92
93
94 public Object create( long value ) {
95 return Long.valueOf(value);
96 }
97
98
99
100
101 public Object create( boolean value ) {
102 return Boolean.valueOf(value);
103 }
104
105
106
107
108 public Object create( float value ) {
109 return Float.valueOf(value);
110 }
111
112
113
114
115 public Object create( double value ) {
116 return Double.valueOf(value);
117 }
118
119
120
121
122 public Object create( BigDecimal value ) {
123 return value;
124 }
125
126
127
128
129 public Object create( Calendar value ) {
130 return value;
131 }
132
133
134
135
136 public Object create( Date value ) {
137 return value;
138 }
139
140
141
142
143
144
145 public Object create( DateTime value ) {
146 return value;
147 }
148
149
150
151
152 public Object create( Name value ) {
153 return value;
154 }
155
156
157
158
159 public Object create( Path value ) {
160 return value;
161 }
162
163
164
165
166 public Object create( Path.Segment value ) {
167 return value;
168 }
169
170
171
172
173 public Object create( Reference value ) {
174 return value;
175 }
176
177
178
179
180 public Object create( URI value ) {
181 return value;
182 }
183
184
185
186
187
188
189 public Object create( UUID value ) {
190 return value;
191 }
192
193
194
195
196
197
198 @Override
199 public Object create( Object value ) {
200 return value;
201 }
202
203
204
205
206
207
208 @Override
209 public Object[] create( Object[] values ) {
210 return values;
211 }
212
213
214
215
216 public Object create( byte[] value ) {
217 return getBinaryValueFactory().create(value);
218 }
219
220
221
222
223
224
225 public Object create( Binary value ) throws ValueFormatException, IoException {
226 return value;
227 }
228
229
230
231
232 public Object create( InputStream stream,
233 long approximateLength ) {
234 return getBinaryValueFactory().create(stream, approximateLength);
235 }
236
237
238
239
240 public Object create( Reader reader,
241 long approximateLength ) {
242 return getBinaryValueFactory().create(reader, approximateLength);
243 }
244
245
246
247
248 @Override
249 protected Object[] createEmptyArray( int length ) {
250 return new Object[length];
251 }
252
253 }