use of com.cosylab.cdb.jdal.hibernate.ConvertToPrimitiveFeature in project ACS by ACS-Community.
the class HibernateWDAOImpl method getField.
public Object getField(String path) throws AcsJCDBFieldDoesNotExistEx {
// backward compatibility
final String CHARACTERISTICS_KEY = "_characteristics";
final String ATTRIBUTES_KEY = "_attributes";
final String ELEMENTS_KEY = "_elements";
final String SUBNODES_KEY = "_subnodes";
boolean subnodesRequest = false;
boolean elementsRequest = false;
boolean attributesRequest = false;
if (path.endsWith(CHARACTERISTICS_KEY)) {
path = path.substring(0, path.length() - CHARACTERISTICS_KEY.length());
attributesRequest = elementsRequest = subnodesRequest = true;
} else if (path.endsWith(ATTRIBUTES_KEY)) {
path = path.substring(0, path.length() - ATTRIBUTES_KEY.length());
attributesRequest = true;
} else if (path.endsWith(ELEMENTS_KEY)) {
path = path.substring(0, path.length() - ELEMENTS_KEY.length());
elementsRequest = true;
} else if (path.endsWith(SUBNODES_KEY)) {
path = path.substring(0, path.length() - SUBNODES_KEY.length());
subnodesRequest = true;
}
Object field = DOMJavaClassIntrospector.getNode(path, m_rootNode);
if (field == null) {
AcsJCDBFieldDoesNotExistEx e2 = new AcsJCDBFieldDoesNotExistEx();
e2.setFieldName(path);
throw e2;
}
// request for elements/attibutes (empty name)
if (path.length() == 0 || path.charAt(path.length() - 1) == '/') {
// JDAL return attributes and subnodes
String[] attributes = attributesRequest ? DOMJavaClassIntrospector.getFields(field) : new String[0];
String[] elements = elementsRequest ? DOMJavaClassIntrospector.getElements(field) : new String[0];
String[] subnodes = subnodesRequest ? DOMJavaClassIntrospector.getSubnodes(field) : new String[0];
String[] concat = new String[attributes.length + elements.length + subnodes.length];
System.arraycopy(attributes, 0, concat, 0, attributes.length);
System.arraycopy(elements, 0, concat, attributes.length, elements.length);
System.arraycopy(subnodes, 0, concat, attributes.length + elements.length, subnodes.length);
field = concat;
}
// automatic conversion
if (field instanceof ConvertToPrimitiveFeature)
field = ((ConvertToPrimitiveFeature) field).convert();
// array support
if (field instanceof Element) {
NodeList childList = ((Element) field).getChildNodes();
int childCount = childList.getLength();
StringBuffer strignifiedArray = new StringBuffer();
for (int i = 0; i < childCount; i++) {
Node childNode = childList.item(i);
if (childNode instanceof Element && childNode.getAttributes().getLength() > 0) {
if (strignifiedArray.length() > 0)
strignifiedArray.append(',');
strignifiedArray.append(childNode.getAttributes().item(0).getTextContent());
}
}
field = strignifiedArray.toString();
}
if (!m_silent)
m_logger.log(AcsLogLevel.NOTICE, "DAO: '" + m_name + "' returned '" + path + "' = '" + (field.getClass().isArray() ? DOMJavaClassIntrospector.stringifyArray(field) : field) + "'");
return field;
}
Aggregations