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