1 package org.codehaus.xfire.aegis; 2 3 import org.codehaus.xfire.XFireRuntimeException; 4 5 /*** 6 * Basic type conversions for reading messages. 7 * 8 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 9 */ 10 public abstract class AbstractMessageReader 11 implements MessageReader 12 { 13 public AbstractMessageReader() 14 { 15 } 16 17 public boolean hasValue() 18 { 19 return getValue() != null; 20 } 21 22 /*** 23 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsInt() 24 */ 25 public int getValueAsInt() 26 { 27 if (getValue() == null) return 0; 28 29 return Integer.parseInt( getValue() ); 30 } 31 32 /*** 33 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsLong() 34 */ 35 public long getValueAsLong() 36 { 37 if (getValue() == null) return 0l; 38 39 return Long.parseLong( getValue() ); 40 } 41 42 /*** 43 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsDouble() 44 */ 45 public double getValueAsDouble() 46 { 47 if (getValue() == null) return 0d; 48 49 return Double.parseDouble( getValue() ); 50 } 51 52 /*** 53 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsFloat() 54 */ 55 public float getValueAsFloat() 56 { 57 if (getValue() == null) return 0f; 58 59 return Float.parseFloat( getValue() ); 60 } 61 62 /*** 63 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsBoolean() 64 */ 65 public boolean getValueAsBoolean() 66 { 67 String value = getValue(); 68 if (value == null) return false; 69 70 if ("true".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) 71 return true; 72 73 if ("false".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) 74 return false; 75 76 throw new XFireRuntimeException("Invalid boolean value: " + value); 77 } 78 }