use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.
the class HibernateWDAOImpl method get_double_seq.
public double[] get_double_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
Object objectValue;
try {
objectValue = getField(propertyName);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
}
// no conversion needed
if (objectValue instanceof double[])
return (double[]) objectValue;
Class<? extends Object> type = objectValue.getClass();
if (objectValue instanceof String) {
String[] tokens = ((String) objectValue).split(",");
double[] retVal = new double[tokens.length];
try {
for (int i = 0; i < tokens.length; i++) retVal[i] = Double.parseDouble(tokens[i].trim());
return retVal;
} catch (NullPointerException npe) {
if (!m_silent)
m_logger.log(AcsLogLevel.NOTICE, "Failed to cast '" + objectValue + "' to dluble[].");
AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx();
e2.setValue(objectValue.getClass().toString());
e2.setDataType("double[]");
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 double[].");
AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx();
e2.setValue(objectValue.getClass().toString());
e2.setDataType("double[]");
throw e2.toWrongCDBDataTypeEx();
}
// do fancy conversion
int len = Array.getLength(objectValue);
double[] seq = new double[len];
for (int i = 0; i < len; i++) seq[i] = ((Number) Array.get(objectValue, i)).doubleValue();
return seq;
}
use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.
the class HibernateWDAOImpl method get_string.
@SuppressWarnings("unchecked")
public String get_string(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
Object objectValue;
try {
objectValue = getField(propertyName);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
}
try {
if (objectValue.getClass().isArray())
return DOMJavaClassIntrospector.stringifyArray(objectValue);
if (objectValue instanceof Map) {
Object[] arr = ((Map) objectValue).keySet().toArray();
StringBuilder sb = new StringBuilder();
boolean first = true;
for (Object a : arr) {
if (first)
first = false;
else
sb.append(',');
sb.append((String) a);
}
return sb.toString();
}
Class<? extends Object> valueType = objectValue.getClass();
if (!DOMJavaClassIntrospector.isPrimitive(valueType))
throw new ClassCastException(valueType + " not a primitive/string/array");
objectValue = DOMJavaClassIntrospector.handleInfinity(objectValue);
return objectValue.toString();
} catch (ClassCastException nfe) {
if (!m_silent)
m_logger.log(AcsLogLevel.NOTICE, "Failed to cast '" + objectValue + "' to string: " + nfe);
AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx(nfe);
e2.setValue(objectValue.toString());
e2.setDataType("string");
throw e2.toWrongCDBDataTypeEx();
}
}
use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.
the class HibernateWDAOImpl method get_string_seq.
@SuppressWarnings("unchecked")
public String[] get_string_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
Object objectValue;
try {
objectValue = getField(propertyName);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
}
// no conversion needed
if (objectValue instanceof String[])
return (String[]) objectValue;
// Map keys
if (objectValue instanceof Map) {
Map map = (Map) objectValue;
String[] retVal = new String[map.size()];
int i = 0;
for (Object obj : map.keySet()) retVal[i++] = (String) obj;
return retVal;
}
Class<? extends Object> type = objectValue.getClass();
if (objectValue instanceof String) {
String[] tokens = ((String) objectValue).split(",");
for (int i = 0; i < tokens.length; i++) tokens[i] = tokens[i].trim();
return tokens;
} else if (!type.isArray() || !DOMJavaClassIntrospector.isPrimitive(type.getComponentType())) {
if (!m_silent) {
// TODO take out the dummy exception. Now needed for debugging an OMC/TMCDB issue.
m_logger.log(AcsLogLevel.NOTICE, "DAO '" + m_name + "' failed to cast to String[] the property '" + propertyName + "' of type '" + type.toString() + "' with value " + objectValue + "'.", new Exception("just for stack trace"));
}
AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx();
e2.setValue(objectValue.getClass().toString());
e2.setDataType("String[]");
throw e2.toWrongCDBDataTypeEx();
}
// do fancy conversion
int len = Array.getLength(objectValue);
String[] seq = new String[len];
for (int i = 0; i < len; i++) seq[i] = DOMJavaClassIntrospector.handleInfinity(Array.get(objectValue, i)).toString();
return seq;
}
use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.
the class DAOImpl method get_long_seq.
public int[] get_long_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
String stringValue;
try {
stringValue = getField(propertyName);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
}
ArrayList list = new ArrayList();
String val = null;
try {
StringTokenizer st = new StringTokenizer(stringValue, ",");
while (st.hasMoreTokens()) {
val = st.nextToken().trim();
list.add(new Integer(val));
}
} catch (NumberFormatException nfe) {
if (!m_silent)
m_logger.log(AcsLogLevel.NOTICE, "Failed to cast element #" + list.size() + " of value '" + val + "' to long: " + nfe);
AcsJWrongCDBDataTypeEx e2 = new AcsJWrongCDBDataTypeEx(nfe);
e2.setValue(val);
e2.setDataType("long");
throw e2.toWrongCDBDataTypeEx();
}
int[] seq = new int[list.size()];
for (int i = 0; i < list.size(); i++) seq[i] = ((Integer) list.get(i)).intValue();
return seq;
}
use of alma.cdbErrType.wrappers.AcsJWrongCDBDataTypeEx in project ACS by ACS-Community.
the class DAOImpl method get_double_seq.
public double[] get_double_seq(String propertyName) throws WrongCDBDataTypeEx, CDBFieldDoesNotExistEx {
String stringValue;
try {
stringValue = getField(propertyName);
} catch (AcsJCDBFieldDoesNotExistEx e) {
throw e.toCDBFieldDoesNotExistEx();
}
ArrayList list = new ArrayList();
String val = null;
try {
StringTokenizer st = new StringTokenizer(stringValue, ",");
while (st.hasMoreTokens()) {
val = st.nextToken().trim();
list.add(new Double(val));
}
} catch (NumberFormatException nfe) {
if (!m_silent)
m_logger.log(AcsLogLevel.NOTICE, "Failed to cast element #" + list.size() + " of value '" + val + "' to double: " + nfe);
AcsJWrongCDBDataTypeEx e = new AcsJWrongCDBDataTypeEx(nfe);
e.setValue(val);
e.setDataType("double");
throw e.toWrongCDBDataTypeEx();
}
double[] seq = new double[list.size()];
for (int i = 0; i < list.size(); i++) seq[i] = ((Double) list.get(i)).doubleValue();
return seq;
}
Aggregations