/** * Lookup the #Collection instance which represents this object * * i.e. for a VM tag (i.e. a Tag object which its VM property set) * return the #Collection instance which encapsulates AssignedTagResource, * AssignedTagsResource and VM. * * @param model the object to query for * @param suggestedParentType the suggested parent type * @return the #Collection instance representing the object's collection */ private static Collection getCollection(BaseResource model, Class<? extends BaseResource> suggestedParentType) { ParentToCollectionMap collections = TYPES.get(model.getClass()); if (suggestedParentType != null) { for (Class<? extends BaseResource> parentType : collections.keySet()) { if (parentType.equals(suggestedParentType)) { return collections.get(parentType); } } } for (Class<? extends BaseResource> parentType : collections.keySet()) { if (parentType != NO_PARENT && getParentModel(model, parentType) != null) { return collections.get(parentType); } } return collections.get(NO_PARENT); }