use of ncsa.hdf.object.DataFormat in project vcell by virtualcell.
the class VH5Path method walk.
/**
* find next object in sequence
* @param hobj previous element in sequence
* @param steps name of each step
* @param index current step
* @return next object path, if present
* @throws HDF5Exception
*/
private static Object walk(Object hobj, String[] steps, int index) throws Exception {
final boolean isLastIndex = lastIndex(index, steps);
final String finding = steps[index];
Group g = BeanUtils.downcast(Group.class, hobj);
if (g != null) {
List<HObject> ml = g.getMemberList();
for (HObject sub : ml) {
// String full = sub.getFullName();
if (finding.equals(sub.getName())) {
if (isLastIndex) {
return sub;
}
return walk(sub, steps, index + 1);
}
}
}
H5CompoundDS cds = BeanUtils.downcast(H5CompoundDS.class, hobj);
if (cds != null) {
cds.read();
String[] mn = cds.getMemberNames();
for (int i = 0; i < mn.length; i++) {
if (finding.equals(mn[i])) {
Object c = cds.read();
Vector<?> vec = BeanUtils.downcast(Vector.class, c);
if (vec != null) {
VCAssert.assertTrue(i < vec.size(), "Disconnect between H5CompoundDS.getMemberNames( ) and returned Vector");
Object child = vec.get(i);
if (isLastIndex) {
return child;
}
} else {
throw new UnsupportedOperationException("Unsupported H5CompoundDS subtype " + className(c));
}
}
}
}
if (isLastIndex) {
DataFormat df = BeanUtils.downcast(DataFormat.class, hobj);
if (df != null && df.hasAttribute()) {
try {
@SuppressWarnings("unchecked") List<Object> meta = df.getMetadata();
for (Object o : meta) {
Attribute a = BeanUtils.downcast(Attribute.class, o);
if (a != null) {
if (finding.equals(a.getName())) {
return a.getValue();
}
} else {
lg.warn(concat(steps, finding) + " fetching metadata unexpected type " + className(o));
}
}
} catch (Exception e) {
throw new RuntimeException(concat(steps, finding) + " fetching metadata", e);
}
}
}
return null;
}
Aggregations