1 5 6 package org.exoplatform.services.jcr.impl.util; 7 8 import javax.jcr.*; 9 10 16 17 public class PropertyConvertor { 18 19 public static Value convert(Value oldValue, int type) throws IllegalStateException , RepositoryException { 20 Value[] values = new Value[1]; 21 values[0] = oldValue; 22 return convert(values, type)[0]; 23 } 24 25 public static Value[] convert(Value[] oldValues, int type) throws RepositoryException { 26 Value[] newValues = new Value[oldValues.length]; 27 if(oldValues.length == 0) 28 return oldValues; 29 if (oldValues[0] != null && oldValues[0].getType() == type) 30 return oldValues; 31 32 for (int i = 0; i < oldValues.length; i++) { 33 Value value = oldValues[i]; 34 switch (type) { 35 case PropertyType.STRING: 36 newValues[i] = (oldValues[i] == null)?new StringValue(null):new StringValue(value.getString()); 37 break; 38 case PropertyType.BINARY: 39 newValues[i] = (oldValues[i] == null)?new BinaryValue((String )null):new BinaryValue(value.getStream()); 40 break; 41 case PropertyType.BOOLEAN: 42 newValues[i] = (oldValues[i] == null)?new BooleanValue(null):new BooleanValue(value.getBoolean()); 43 break; 44 case PropertyType.LONG: 45 newValues[i] = (oldValues[i] == null)?new LongValue(null):new LongValue(value.getLong()); 46 break; 47 case PropertyType.DOUBLE: 48 newValues[i] = (oldValues[i] == null)?new DoubleValue(null):new DoubleValue(value.getDouble()); 49 break; 50 case PropertyType.DATE: 51 newValues[i] = (oldValues[i] == null)?new DateValue(null):new DateValue(value.getDate()); 52 break; 53 case PropertyType.SOFTLINK: 54 newValues[i] = (oldValues[i] == null)?new SoftLinkValue(null):new SoftLinkValue(value.getString()); 55 break; 56 case PropertyType.REFERENCE: 57 newValues[i] = (oldValues[i] == null)?new ReferenceValue((String )null):new ReferenceValue(value.getString()); 58 break; 59 default: 60 newValues[i] = null; 61 } 63 } 64 return newValues; 65 } 67 68 } 69 | Popular Tags |