1 9 package org.jboss.portal.core.impl.preferences; 10 11 import org.jboss.portal.common.value.BooleanValues; 12 import org.jboss.portal.common.value.IntegerValues; 13 import org.jboss.portal.common.value.StringValues; 14 import org.jboss.portal.common.value.Value; 15 16 22 public class ValueManager 23 { 24 25 public static final int TYPE_NULL = 0; 26 public static final int TYPE_STRING = 1; 27 public static final int TYPE_INTEGER = 2; 28 public static final int TYPE_BOOLEAN = 3; 29 private static final String [] EMPTY_STRING_ARRAY = new String [0]; 30 31 public static Value createValue(TypedStringArray tsa) 32 { 33 switch(tsa.getType()) 34 { 35 case TYPE_NULL: 36 return new StringValues(); 37 case TYPE_INTEGER: 38 return new IntegerValues(tsa.getStrings()); 39 case TYPE_BOOLEAN: 40 return new BooleanValues(tsa.getStrings()); 41 default: 42 return new StringValues(tsa.getStrings()); 43 } 44 } 45 46 public static TypedStringArray createTypedStringArray(Value value) 47 { 48 if (value.isNull()) 49 { 50 return new TypedStringArray(TYPE_NULL, EMPTY_STRING_ARRAY); 51 } 52 else if (value instanceof IntegerValues) 53 { 54 return new TypedStringArray(TYPE_INTEGER, value.asStringArray()); 55 } 56 else if (value instanceof BooleanValues) 57 { 58 return new TypedStringArray(TYPE_BOOLEAN, value.asStringArray()); 59 } 60 else 61 { 62 return new TypedStringArray(TYPE_STRING, value.asStringArray()); 63 } 64 } 65 } 66 | Popular Tags |