package org.codehaus.xfire.aegis;

import org.codehaus.xfire.XFireRuntimeException;

/**
 * Basic type conversions for reading messages.
 * 
 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
 */
public abstract class AbstractMessageReader
    implements MessageReader
{
    public AbstractMessageReader()
    {
    }
    
    /**
     * @see org.codehaus.xfire.aegis.MessageReader#getValueAsInt()
     */
    public int getValueAsInt()
    {
        return Integer.parseInt( getValue() );
    }

	/**
	 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsLong()
	 */
	public long getValueAsLong()
	{
        return Long.parseLong( getValue() );
	}
    
	/**
	 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsDouble()
	 */
	public double getValueAsDouble()
	{
		return Double.parseDouble( getValue() );
	}

	/**
	 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsFloat()
	 */
	public float getValueAsFloat()
	{
		return Float.parseFloat( getValue() );
	}

	/**
	 * @see org.codehaus.xfire.aegis.MessageReader#getValueAsBoolean()
	 */
	public boolean getValueAsBoolean()
	{
        String value = getValue();
        if ("true".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value))
            return true;

        if ("false".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value))
            return false;
        
        throw new XFireRuntimeException("Invalid boolean value: " + value);
	}
}

@@ -328,16 +328,94 @@
  %7B%0A    %7D
+%0A%0A    public boolean hasValue()%0A    %7B%0A        return getValue() != null;%0A    %7D
 %0A    %0A  
@@ -524,32 +524,83 @@
 ueAsInt()%0A    %7B%0A
+        if (getValue() == null) return 0;%0A        %0A
         return I
@@ -741,24 +741,76 @@
 AsLong()%0A%09%7B%0A
+        if (getValue() == null) return 0l;%0A        %0A
         retu
@@ -960,26 +960,84 @@
 Double()%0A%09%7B%0A
-%09%09
+        if (getValue() == null) return 0d;%0A        %0A        
 return Doubl
@@ -1184,10 +1184,68 @@
 %0A%09%7B%0A
-%09%09
+        if (getValue() == null) return 0f;%0A        %0A        
 retu
@@ -1396,24 +1396,24 @@
 oolean()%0A%09%7B%0A
-
         Stri
@@ -1435,16 +1435,66 @@
 alue();%0A
+        if (value == null) return false;%0A        %0A
         

Check for null values on primitives. We should really check hasValue() now in Boolean/Int/Long/etcType If it is false, we should return null in the Type.readObject().