|
Re: Creating a new resource from within a plugin [message #721525 is a reply to message #721482] |
Thu, 01 September 2011 21:43  |
Eclipse User |
|
|
|
now I see...
it´s creating the file at the working directory defined in the "arguments" tab of the "eclipse application" run configuration...
resolved just like this
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xxx", new XMIResourceFactoryImpl());
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
// Create a resource
Resource resource = resSet.createResource(URI
.createURI(cdu.getNome()+".xxx"));
// Get the first model element and cast it to the right type, in my
// example everything is hierarchical included in this first node
resource.getContents().add(cdu);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Now save the content.
try {
resource.save(baos, Collections.EMPTY_MAP);
//resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
IFolder folder = targetFolder;
IFile file = folder.getFile(cdu.getNome()+".xxx");
InputStream source = new ByteArrayInputStream(baos.toByteArray());
file.create(source, IResource.NONE, null);
|
|
|
Powered by
FUDForum. Page generated in 0.04004 seconds