Search in sources :

Example 6 with AcsJWrongCDBDataTypeEx

use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.

the class HibernateWDAOImpl method get_long_seq.

public int[] get_long_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
    Object objectValue;
    try {
        objectValue = getField(propertyName);
    } catch (AcsJCDBFieldDoesNotExistEx e) {
        throw e.toCDBFieldDoesNotExistEx();
    }
    // no conversion needed
    if (objectValue instanceof int[])
        return (int[]) objectValue;
    Class<? extends Object> type = objectValue.getClass();
    if (objectValue instanceof String) {
        String[] tokens = ((String) objectValue).split(",");
        int[] retVal = new int[tokens.length];
        try {
            for (int i = 0; i < tokens.length; i++) retVal[i] = Integer.parseInt(tokens[i].trim());
            return retVal;
        } catch (NullPointerException npe) {
            if (!m_silent)
                m_logger.log(AcsLogLevel.NOTICE, "Failed to cast '" + objectValue + "' to long[].");
            AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx();
            e2.setValue(objectValue.getClass().toString());
            e2.setDataType("long[]");
            throw e2.toWrongCDBDataTypeEx();
        }
    } else if (!type.isArray() || !type.getComponentType().isAssignableFrom(Number.class)) {
        if (!m_silent)
            m_logger.log(AcsLogLevel.NOTICE, "Failed to cast '" + objectValue + "' to long[].");
        AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx();
        e2.setValue(objectValue.getClass().toString());
        e2.setDataType("long[]");
        throw e2.toWrongCDBDataTypeEx();
    }
    // do fancy conversion
    int len = Array.getLength(objectValue);
    int[] seq = new int[len];
    for (int i = 0; i < len; i++) seq[i] = ((Number) Array.get(objectValue, i)).intValue();
    return seq;
}
Also used : AcsJWrongCDBDataTypeEx(alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx) AcsJCDBFieldDoesNotExistEx(alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)

Aggregations

AcsJCDBFieldDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBFieldDoesNotExistEx)6 AcsJWrongCDBDataTypeEx (alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx)6 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2