1 24 package javax.jcr; 25 26 import java.util.Calendar ; 27 28 34 public class BooleanValue extends BaseValue { 35 36 public static final int TYPE = PropertyType.BOOLEAN; 37 38 private final Boolean bool; 39 40 45 public BooleanValue(Boolean bool) { 46 super(TYPE); 47 this.bool = bool; 48 } 49 50 55 public BooleanValue(boolean bool) { 56 super(TYPE); 57 this.bool = new Boolean (bool); 58 } 59 60 68 public static BooleanValue valueOf(String s) { 69 return new BooleanValue(Boolean.valueOf(s)); 70 } 71 72 83 public boolean equals(Object obj) { 84 if (this == obj) { 85 return true; 86 } 87 if (obj instanceof BooleanValue) { 88 BooleanValue other = (BooleanValue) obj; 89 if (bool == other.bool) { 90 return true; 91 } else if (bool != null && other.bool != null) { 92 return bool.equals(other.bool); 93 } 94 } 95 return false; 96 } 97 98 102 public Calendar getDate() throws ValueFormatException, IllegalStateException , RepositoryException { 103 setValueConsumed(); 104 105 throw new ValueFormatException("conversion to date failed: inconvertible types"); 106 } 107 108 111 public long getLong() throws ValueFormatException, IllegalStateException , RepositoryException { 112 setValueConsumed(); 113 114 throw new ValueFormatException("conversion to long failed: inconvertible types"); 115 } 116 117 120 public boolean getBoolean() throws ValueFormatException, IllegalStateException , RepositoryException { 121 setValueConsumed(); 122 123 if (bool != null) { 124 return bool.booleanValue(); 125 } else { 126 throw new ValueFormatException("empty value"); 127 } 128 } 129 130 133 public double getDouble() throws ValueFormatException, IllegalStateException , RepositoryException { 134 setValueConsumed(); 135 136 throw new ValueFormatException("conversion to double failed: inconvertible types"); 137 } 138 139 142 public String getString() throws ValueFormatException, IllegalStateException , RepositoryException { 143 setValueConsumed(); 144 145 if (bool != null) { 146 return bool.toString(); 147 } else { 148 throw new ValueFormatException("empty value"); 149 } 150 } 151 } 152 | Popular Tags |