View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   * The standard {@link ValueFactory} for {@link PropertyType#OBJECT} values.
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       * @return binaryValueFactory
64       */
65      protected ValueFactory<Binary> getBinaryValueFactory() {
66          return this.binaryValueFactory;
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      public Object create( String value ) {
73          return this.getStringValueFactory().create(value);
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      public Object create( String value,
80                            TextDecoder decoder ) {
81          return this.getStringValueFactory().create(value, decoder);
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      public Object create( int value ) {
88          return Integer.valueOf(value);
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      public Object create( long value ) {
95          return Long.valueOf(value);
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     public Object create( boolean value ) {
102         return Boolean.valueOf(value);
103     }
104 
105     /**
106      * {@inheritDoc}
107      */
108     public Object create( float value ) {
109         return Float.valueOf(value);
110     }
111 
112     /**
113      * {@inheritDoc}
114      */
115     public Object create( double value ) {
116         return Double.valueOf(value);
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     public Object create( BigDecimal value ) {
123         return value;
124     }
125 
126     /**
127      * {@inheritDoc}
128      */
129     public Object create( Calendar value ) {
130         return value;
131     }
132 
133     /**
134      * {@inheritDoc}
135      */
136     public Object create( Date value ) {
137         return value;
138     }
139 
140     /**
141      * {@inheritDoc}
142      * 
143      * @see org.modeshape.graph.property.ValueFactory#create(org.modeshape.graph.property.DateTime)
144      */
145     public Object create( DateTime value ) {
146         return value;
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     public Object create( Name value ) {
153         return value;
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     public Object create( Path value ) {
160         return value;
161     }
162 
163     /**
164      * {@inheritDoc}
165      */
166     public Object create( Reference value ) {
167         return value;
168     }
169 
170     /**
171      * {@inheritDoc}
172      */
173     public Object create( URI value ) {
174         return value;
175     }
176 
177     /**
178      * {@inheritDoc}
179      * 
180      * @see org.modeshape.graph.property.ValueFactory#create(java.util.UUID)
181      */
182     public Object create( UUID value ) {
183         return value;
184     }
185 
186     /**
187      * {@inheritDoc}
188      * 
189      * @see org.modeshape.graph.property.basic.AbstractValueFactory#create(java.lang.Object)
190      */
191     @Override
192     public Object create( Object value ) {
193         return value;
194     }
195 
196     /**
197      * {@inheritDoc}
198      * 
199      * @see org.modeshape.graph.property.basic.AbstractValueFactory#create(java.lang.Object[])
200      */
201     @Override
202     public Object[] create( Object[] values ) {
203         return values;
204     }
205 
206     /**
207      * {@inheritDoc}
208      */
209     public Object create( byte[] value ) {
210         return getBinaryValueFactory().create(value);
211     }
212 
213     /**
214      * {@inheritDoc}
215      * 
216      * @see org.modeshape.graph.property.ValueFactory#create(org.modeshape.graph.property.Binary)
217      */
218     public Object create( Binary value ) throws ValueFormatException, IoException {
219         return value;
220     }
221 
222     /**
223      * {@inheritDoc}
224      */
225     public Object create( InputStream stream,
226                           long approximateLength ) {
227         return getBinaryValueFactory().create(stream, approximateLength);
228     }
229 
230     /**
231      * {@inheritDoc}
232      */
233     public Object create( Reader reader,
234                           long approximateLength ) {
235         return getBinaryValueFactory().create(reader, approximateLength);
236     }
237 
238     /**
239      * {@inheritDoc}
240      */
241     @Override
242     protected Object[] createEmptyArray( int length ) {
243         return new Object[length];
244     }
245 
246 }