public static int toIntValue(Object o, int defaultValue) {

	if (o instanceof Number) return ((Number) o).intValue();
	else if (o instanceof Boolean) return ((Boolean) o).booleanValue() ? 1 : 0;
	else if (o instanceof CharSequence) return toIntValue(o.toString().trim(), defaultValue);
	// else if(o instanceof Clob) return toIntValue(toString(o));
	else if (o instanceof Character) return (int) (((Character) o).charValue());
	else if (o instanceof Castable) {
	    return (int) ((Castable) o).castToDoubleValue(defaultValue);

	}
	else if (o instanceof Date) return (int) new DateTimeImpl((Date) o).castToDoubleValue();
	else if (o instanceof ObjectWrap) return toIntValue(((ObjectWrap) o).getEmbededObject(Integer.valueOf(defaultValue)), defaultValue);

	return defaultValue;
    }
public static int toIntValue ( Object o , int defaultValue ) { if ( o instanceof Number ) return ( ( Number ) o ) . intValue ( ) ; else if ( o instanceof Boolean ) return ( ( Boolean ) o ) . booleanValue ( ) ? 1 : 0 ; else if ( o instanceof CharSequence ) return toIntValue ( o . toString ( ) . trim ( ) , defaultValue ) ; else if ( o instanceof Character ) return ( int ) ( ( ( Character ) o ) . charValue ( ) ) ; else if ( o instanceof Castable ) { return ( int ) ( ( Castable ) o ) . castToDoubleValue ( defaultValue ) ; } else if ( o instanceof Date ) return ( int ) new DateTimeImpl ( ( Date ) o ) . castToDoubleValue ( ) ; else if ( o instanceof ObjectWrap ) return toIntValue ( ( ( ObjectWrap ) o ) . getEmbededObject ( Integer . valueOf ( defaultValue ) ) , defaultValue ) ; return defaultValue ; }
cast a Object to a int value (primitive value type)

@param o Object to cast
@param defaultValue
@return casted int value