/* Public Interfaces */ public static URI newLink(DataObject resource) { if (resource == null) { throw new NullPointerException(); } ResourceTypeEnum res = ResourceTypeMapping.getResourceType(resource); try { URI parentId; if (res == null) { return new URI("/"); } switch (res) { case STORAGE_POOL: parentId = ((StoragePool) resource).getStorageDevice(); return secondaryResourceLink(res.getService(), resource.getId(), parentId); case STORAGE_PORT: parentId = ((StoragePort) resource).getStorageDevice(); return secondaryResourceLink(res.getService(), resource.getId(), parentId); case RDF_GROUP: parentId = ((RemoteDirectorGroup) resource).getSourceStorageSystemUri(); return secondaryResourceLink(res.getService(), resource.getId(), parentId); case BLOCK_MIRROR: parentId = ((BlockMirror) resource).getSource().getURI(); return secondaryResourceLink(res.getService(), resource.getId(), parentId); case VPLEX_MIRROR: parentId = ((VplexMirror) resource).getSource().getURI(); return secondaryResourceLink(res.getService(), resource.getId(), parentId); case PROTECTION_SET: // any volume in the volume string set is valid StringSet volumeIDs = ((ProtectionSet) resource).getVolumes(); if (volumeIDs != null && !volumeIDs.isEmpty()) { for (String volumeID : volumeIDs) { // No .get(), same as iterator. return secondaryResourceLink(res.getService(), resource.getId(), new URI(volumeID)); } } // This will not produce a good URI, but it's impossible to get here with the dependent // data model. return simpleServiceLink(res.getService(), resource.getId()); default: return simpleServiceLink(res, resource.getId()); } } catch (URISyntaxException ex) { return null; // impossible; } }
public static URI newLink(ResourceTypeEnum res, URI resource_id) { try { if (resource_id == null) { return new URI("/"); } if (res == null) { return new URI("/" + resource_id); } if (res == ResourceTypeEnum.STORAGE_POOL || res == ResourceTypeEnum.STORAGE_PORT || res == ResourceTypeEnum.BLOCK_MIRROR || res == ResourceTypeEnum.RDF_GROUP || res == ResourceTypeEnum.VPLEX_MIRROR) { URI link = _linkCache.get(resource_id); if (link == null) { DataObject resource = _dbClient.queryObject(ResourceTypeMapping.getDataObjectClass(res), resource_id); if (resource != null) { link = newLink(resource); _linkCache.put(resource_id, link); } else { link = NullColumnValueGetter.getNullURI(); } } return link; } else { return simpleServiceLink(res, resource_id); } } catch (URISyntaxException ex) { return null; // impossible; } catch (DatabaseException ex) { return null; } }