2011年9月29日

Eclipse EMF load and save Resource


public Resource loadResource(IResource resource) throws IOException {
ResourceSet resourceSet = new ResourceSetImpl();

// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(resource.getFullPath().toString(), true);

// Create a resource for this file.
//
Resource eResource = resourceSet.createResource(fileURI);

eResource.load(new HashMap());
return eResource;
}

public void saveResource(Resource eResource) throws IOException {
// Save only resources that have actually changed.
//
Map saveOptions = new HashMap();
saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
eResource.save(saveOptions);
}

沒有留言:

網誌存檔