001    /*
002     * JBoss, Home of Professional Open Source.
003     * Copyright 2008, Red Hat Middleware LLC, and individual contributors
004     * as indicated by the @author tags. See the copyright.txt file in the
005     * distribution for a full listing of individual contributors. 
006     *
007     * This is free software; you can redistribute it and/or modify it
008     * under the terms of the GNU Lesser General Public License as
009     * published by the Free Software Foundation; either version 2.1 of
010     * the License, or (at your option) any later version.
011     *
012     * This software is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * Lesser General Public License for more details.
016     *
017     * You should have received a copy of the GNU Lesser General Public
018     * License along with this software; if not, write to the Free
019     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021     */
022    package org.jboss.dna.graph.properties.basic;
023    
024    import java.io.InputStream;
025    import java.io.Reader;
026    import java.math.BigDecimal;
027    import java.net.URI;
028    import java.util.Calendar;
029    import java.util.Date;
030    import java.util.UUID;
031    import net.jcip.annotations.Immutable;
032    import org.jboss.dna.common.text.TextDecoder;
033    import org.jboss.dna.common.util.CheckArg;
034    import org.jboss.dna.graph.properties.Binary;
035    import org.jboss.dna.graph.properties.DateTime;
036    import org.jboss.dna.graph.properties.IoException;
037    import org.jboss.dna.graph.properties.Name;
038    import org.jboss.dna.graph.properties.Path;
039    import org.jboss.dna.graph.properties.PropertyType;
040    import org.jboss.dna.graph.properties.Reference;
041    import org.jboss.dna.graph.properties.ValueFactory;
042    import org.jboss.dna.graph.properties.ValueFormatException;
043    
044    /**
045     * The standard {@link ValueFactory} for {@link PropertyType#OBJECT} values.
046     * 
047     * @author Randall Hauch
048     * @author John Verhaeg
049     */
050    @Immutable
051    public class ObjectValueFactory extends AbstractValueFactory<Object> {
052    
053        private final ValueFactory<Binary> binaryValueFactory;
054    
055        public ObjectValueFactory( TextDecoder decoder,
056                                   ValueFactory<String> stringValueFactory,
057                                   ValueFactory<Binary> binaryValueFactory ) {
058            super(PropertyType.OBJECT, decoder, stringValueFactory);
059            CheckArg.isNotNull(binaryValueFactory, "binaryValueFactory");
060            this.binaryValueFactory = binaryValueFactory;
061        }
062    
063        /**
064         * @return binaryValueFactory
065         */
066        protected ValueFactory<Binary> getBinaryValueFactory() {
067            return this.binaryValueFactory;
068        }
069    
070        /**
071         * {@inheritDoc}
072         */
073        public Object create( String value ) {
074            return this.getStringValueFactory().create(value);
075        }
076    
077        /**
078         * {@inheritDoc}
079         */
080        public Object create( String value,
081                              TextDecoder decoder ) {
082            return this.getStringValueFactory().create(value, decoder);
083        }
084    
085        /**
086         * {@inheritDoc}
087         */
088        public Object create( int value ) {
089            return Integer.valueOf(value);
090        }
091    
092        /**
093         * {@inheritDoc}
094         */
095        public Object create( long value ) {
096            return Long.valueOf(value);
097        }
098    
099        /**
100         * {@inheritDoc}
101         */
102        public Object create( boolean value ) {
103            return Boolean.valueOf(value);
104        }
105    
106        /**
107         * {@inheritDoc}
108         */
109        public Object create( float value ) {
110            return Float.valueOf(value);
111        }
112    
113        /**
114         * {@inheritDoc}
115         */
116        public Object create( double value ) {
117            return Double.valueOf(value);
118        }
119    
120        /**
121         * {@inheritDoc}
122         */
123        public Object create( BigDecimal value ) {
124            return value;
125        }
126    
127        /**
128         * {@inheritDoc}
129         */
130        public Object create( Calendar value ) {
131            return value;
132        }
133    
134        /**
135         * {@inheritDoc}
136         */
137        public Object create( Date value ) {
138            return value;
139        }
140    
141        /**
142         * {@inheritDoc}
143         * 
144         * @see org.jboss.dna.graph.properties.ValueFactory#create(org.jboss.dna.graph.properties.DateTime)
145         */
146        public Object create( DateTime value ) {
147            return value;
148        }
149    
150        /**
151         * {@inheritDoc}
152         */
153        public Object create( Name value ) {
154            return value;
155        }
156    
157        /**
158         * {@inheritDoc}
159         */
160        public Object create( Path value ) {
161            return value;
162        }
163    
164        /**
165         * {@inheritDoc}
166         */
167        public Object create( Reference value ) {
168            return value;
169        }
170    
171        /**
172         * {@inheritDoc}
173         */
174        public Object create( URI value ) {
175            return value;
176        }
177    
178        /**
179         * {@inheritDoc}
180         * 
181         * @see org.jboss.dna.graph.properties.ValueFactory#create(java.util.UUID)
182         */
183        public Object create( UUID value ) {
184            return value;
185        }
186    
187        /**
188         * {@inheritDoc}
189         * 
190         * @see org.jboss.dna.graph.properties.basic.AbstractValueFactory#create(java.lang.Object)
191         */
192        @Override
193        public Object create( Object value ) {
194            return value;
195        }
196    
197        /**
198         * {@inheritDoc}
199         * 
200         * @see org.jboss.dna.graph.properties.basic.AbstractValueFactory#create(java.lang.Object[])
201         */
202        @Override
203        public Object[] create( Object[] values ) {
204            return values;
205        }
206    
207        /**
208         * {@inheritDoc}
209         */
210        public Object create( byte[] value ) {
211            return getBinaryValueFactory().create(value);
212        }
213    
214        /**
215         * {@inheritDoc}
216         * 
217         * @see org.jboss.dna.graph.properties.ValueFactory#create(org.jboss.dna.graph.properties.Binary)
218         */
219        public Object create( Binary value ) throws ValueFormatException, IoException {
220            return value;
221        }
222    
223        /**
224         * {@inheritDoc}
225         */
226        public Object create( InputStream stream,
227                              long approximateLength ) {
228            return getBinaryValueFactory().create(stream, approximateLength);
229        }
230    
231        /**
232         * {@inheritDoc}
233         */
234        public Object create( Reader reader,
235                              long approximateLength ) {
236            return getBinaryValueFactory().create(reader, approximateLength);
237        }
238    
239        /**
240         * {@inheritDoc}
241         */
242        @Override
243        protected Object[] createEmptyArray( int length ) {
244            return new Object[length];
245        }
246    
247    }