use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class AbstractTableInstanceWriter method getPropertyMap.
/**
* Iterates over properties of the instance and creates a map of the given
* properties
*
* @param instance the Instance to check
* @param headerRow the current header row of the table
* @param solveNestedProperties <code>true</code> if nested properties
* should be solved, otherwise <code>false</code>
* @return a map of properties with string of localpart of the QName of the
* property as key
*/
protected Map<String, Object> getPropertyMap(Instance instance, List<String> headerRow, boolean solveNestedProperties) {
// properties of current instance
Iterable<QName> allProperties = instance.getPropertyNames();
// write properties to map; currently only the first property of nested
// properties is selected
Map<String, Object> row = new HashMap<String, Object>();
for (QName qname : allProperties) {
// get properties of the current instance
Object[] properties = instance.getProperty(qname);
if (properties != null && properties.length != 0) {
String cellValue = "";
// only the first property is evaluated
Object property = properties[0];
if (shouldBeDisplayed(property)) {
cellValue = qname.getLocalPart();
}
// if property is an OInstance or OGroup, it's a nested property
if (solveNestedProperties && property instanceof Group) {
Group nextInstance = (Group) property;
iterateBuild(nextInstance, qname, headerRow, row, cellValue);
// Group inst = (Group) property;
// // check if property has a value and add it
// checkValue(inst, headerRow, row, cellValue);
// // go through nested properties to get other properties
// Iterator<QName> propertyIt = inst.getPropertyNames().iterator();
// if (propertyIt.hasNext()) {
// QName value = propertyIt.next();
// Object nextProp = inst.getProperty(value)[0];
// // check if current property should be displayed in map
// if (shouldBeDisplayed(nextProp)) {
// cellValue += ".";
// cellValue += value.getLocalPart();
// }
//
// // iterate over all nested properties
// while (nextProp instanceof Group) {
// Group oinst = (Group) nextProp;
// checkValue(oinst, headerRow, row, cellValue);
//
// // get localparts of all nested properties
// Iterator<QName> qnames = oinst.getPropertyNames().iterator();
// if (qnames.hasNext()) {
// value = qnames.next();
// nextProp = oinst.getProperty(value)[0];
// if (shouldBeDisplayed(nextProp)) {
// cellValue += ".";
// cellValue += value.getLocalPart();
// }
// else
// continue;
// }
// else
// break;
// }
// // add property with corresponding cellValue (localpart)
// // to map
// // no resolving of nested properties
// addProperty(headerRow, row, nextProp, cellValue);
// }
} else {
// map
if (property instanceof Group && shouldBeDisplayed(property)) {
checkValue((Group) property, headerRow, row, cellValue);
} else {
addProperty(headerRow, row, property, cellValue);
}
}
}
}
return row;
}
Aggregations