}
return windowDTOs;
}
private WorkspaceDTO createWorkspaceDTO(Workspace workspace) {
WorkspaceDTO workspaceDTO = new WorkspaceDTO();
workspaceDTO.setId(workspace.getId());
workspaceDTO.setName(workspace.getName());
// collects resource sets accross all windows
DefaultResourceSetCollector resourceSetCollector = new DefaultResourceSetCollector();
List<WindowDTO> windowDTOs = createWindowDTOs(resourceSetCollector);
workspaceDTO.setWindows(windowDTOs.toArray(new WindowDTO[windowDTOs
.size()]));
// Resource set DTOs
// 1. resolved unmodified sets --> changes list size
List<ResourceSet> resourceSets = new ArrayList<ResourceSet>(
resourceSetCollector.getResourceSets());
for (ResourceSet resourceSet : resourceSets) {
if (resourceSet instanceof UnmodifiableResourceSet) {
resourceSetCollector
.storeResourceSet(((UnmodifiableResourceSet) resourceSet)
.getDelegate());
}
}
// 2. store sets
ResourceSet resourceCollector = new DefaultResourceSet();
ResourceSetDTO[] resourceSetDTOs = new ResourceSetDTO[resourceSetCollector
.getResourceSets().size()];
for (int i = 0; i < resourceSetCollector.getResourceSets().size(); i++) {
ResourceSetDTO dto = new ResourceSetDTO();
ResourceSet resourceSet = resourceSetCollector.getResourceSets()
.get(i);
if (resourceSet.hasLabel()) {
dto.setLabel(resourceSet.getLabel());
}
dto.setId(i);
if (resourceSet instanceof UnmodifiableResourceSet) {
ResourceSet sourceSet = ((UnmodifiableResourceSet) resourceSet)
.getDelegate();
dto.setDelegateSetId(resourceSetCollector
.storeResourceSet(sourceSet));
} else {
List<String> resourceIds = new ArrayList<String>();
for (Resource resource : resourceSet) {
resourceCollector.add(resource);
resourceIds.add(resource.getUri());
}
dto.setResourceIds(resourceIds);
}
resourceSetDTOs[i] = dto;
}
workspaceDTO.setResourceSets(resourceSetDTOs);
List<Resource> allResources = resourceManager.getAllResources();
Resource[] resources = allResources.toArray(new Resource[allResources
.size()]);
workspaceDTO.setResources(resources);
return workspaceDTO;
}