// extract model root
targetModelContainer = targetModelResource.getParent();
// now try to load the modeling project
LoadingService loadingService = new LoadingService();
ModelingProject project = null;
InputStream inStream = null;
try {
inStream = ((IFile)targetModelResource).getContents();
loadingService.setInStream(inStream);
loadingService.setLocationSolver(new WorkspaceLocationSolver());
loadingService.initialize();
loadingService.invoke();
q_impress.pmi.lib.project.IResource tempRes = loadingService.getLoadedResource();
if (!(tempRes instanceof ModelingProject)) throw new ExecutionException("Invalid model file.");
else project = (ModelingProject) tempRes;
} catch (CoreException e) {
throw new ExecutionException("Unable to load model.", e);
} catch (ServiceException e) {
throw new ExecutionException("Unable to load model.", e);
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (IOException e) {} // never happens
}
}
if (doBundling == true) { // do bundling
IPath copyPath = targetModelContainer.getFullPath().append(Constants.UML_MODELS_DIR).append(umlResource.getName());
try {
umlResource.copy(copyPath, true, null);
} catch (CoreException e) {
throw new ExecutionException("Unable to bundle XMI resource.", e);
}
}
// create the new XMI resource and add it to model
UmlResource newPmiRes = new UmlResource();
newPmiRes.setName(umlResource.getName().substring(0, umlResource.getName().indexOf(".")));
newPmiRes.setLocation(umlResource.getFullPath().toPortableString());
try {
project.addResource(newPmiRes);
} catch (ResourceException e) {
throw new ExecutionException("Unable to add XMI resource to model.", e);
}
// save the project