1 9 package org.jboss.portal.common.value; 10 11 12 16 public class BooleanValue extends AbstractValue 17 { 18 19 private static final Boolean [] EMPTY_BOOLEAN_ARRAY = new Boolean [0]; 20 21 private Boolean value; 22 23 public BooleanValue() 24 { 25 this.value = null; 26 } 27 28 public BooleanValue(String value) 29 { 30 if ("true".equals(value)) 31 { 32 this.value = Boolean.TRUE; 33 } 34 else if ("false".equals(value)) 35 { 36 this.value = Boolean.FALSE; 37 } 38 else 39 { 40 throw new IllegalArgumentException (); 41 } 42 } 43 44 public BooleanValue(boolean _value) 45 { 46 this.value = Boolean.valueOf(_value); 47 } 48 49 public BooleanValue(Boolean value) 50 { 51 if (value == null) 52 { 53 throw new IllegalArgumentException (); 54 } 55 this.value = value; 56 } 57 58 public String asString() 59 { 60 return String.valueOf(value); 61 } 62 63 public boolean asBoolean() throws NullConversionException, FormatConversionException 64 { 65 if (value == null) 66 { 67 throw new NullConversionException(); 68 } 69 return value.booleanValue(); 70 } 71 72 public Object asObject() 73 { 74 return value; 75 } 76 77 public Object [] asObjectArray() 78 { 79 if (isNull()) 80 { 81 return EMPTY_BOOLEAN_ARRAY; 82 } 83 return new Boolean []{value}; 84 } 85 } 86 | Popular Tags |