use of org.ovirt.engine.api.model.BaseResources in project ovirt-engine by oVirt.
the class LinkHelper method getInlineResources.
/**
* Obtain a set of inline BaseResource objects from @obj
*
* i.e. return the value of any properties on @obj which are a
* sub-type of BaseResource
*
* @param obj the object to check
* @return a list of any inline BaseResource objects
*/
@SuppressWarnings("unchecked")
private static List<BaseResource> getInlineResources(Object obj) {
ArrayList<BaseResource> ret = new ArrayList<>();
for (Method method : getRelevantMethods(obj.getClass())) {
// We need to recursively scan everything that is in the model package, as there may be references
// to resources deeply nested:
Object inline = null;
try {
inline = method.invoke(obj);
} catch (Exception e) {
// invocation target exception should not occur on simple getter
}
if (inline != null) {
if (inline instanceof BaseResource) {
ret.add((BaseResource) inline);
} else if (inline instanceof BaseResources) {
BaseResources entities = (BaseResources) inline;
Method getter = EntityHelper.getCollectionGetter(entities);
try {
List<BaseResource> entitiesList = (List<BaseResource>) getter.invoke(entities);
for (BaseResource entity : entitiesList) {
ret.add(entity);
}
} catch (Exception e) {
log.error("Error invoking method '{}' on class '{}'.", method.getName(), entities.getClass().getSimpleName());
log.error("Exception", e);
}
} else {
ret.addAll(getInlineResources(inline));
}
}
}
return ret;
}
Aggregations