[ATL] Splitting ASMModel [message #60167] |
Sun, 02 September 2007 14:34 |
Eclipse User |
|
|
|
Originally posted by: rb_account.yahoo.de
Hello,
my transformation gives me the following output model:
************************************************************ **********
<xmi>
<root id=3D1></root>
<root id=3D2></root>
<root id=3D3></root>
</xmi>
I now want to split the model programmatically in 3 outputmodels, each =
containing one of the root-elements:
************************************************************ **********
File1:
<root id=3D1></root>
File2:
<root id=3D2></root>
File3:
<root id=3D3></root>
Having the outputModel, I create a new ASMModel for each root-Element, b=
ut =
how do I get the rootElement in the ASMModel?
There is only a method addSubModel() and no methods to add an element to=
=
the model.
Or do I need to work with EMF to do the splitting?
************************************************************ **********
ASMModel outModel;
ASMModel metaModel;
....
Set<ASMModelElement> rootElements =3D (Set<ASMModelElement>) =
outModel.getElementsByType("root");
Iterator<ASMModelElement> iterator =3D rootElements.iterator();
while(iterator.hasNext()) {
ASMModelElement rootElement =3D iterator.next();
ASMModel rootModel =3D handler.newModel(rootElement.getName(), metaMode=
l);
//adding element to model
rootModel.addModelElement(rootElement);
....
//saving model
}
=
Thanks Rainer
|
|
|
Re: [ATL] Splitting ASMModel [message #60191 is a reply to message #60167] |
Sun, 02 September 2007 19:47 |
Eclipse User |
|
|
|
Originally posted by: rb_account.yahoo.de
Well, I tried it with EMF and it works now.
For anyone who is interested:
The code is used within a eclipse plugin.
The plugin project needs to import the generated EMF model code of the =
Metamodel.
//********************************************************** *****
/*
roots.model is the saved ASMModel:
<xmi>
<Root id=3D1></Root>
<Root id=3D2></Root>
<Root id=3D3></Root>
</xmi>
*/
URI fileURI =3D URI.createFileURI(new File("roots.model").getAbsolutePat=
h());
Resource source =3D resourceSet.getResource(fileURI, true);
//Get all root-elements
TreeIterator elements =3D source.getAllContents();
//Root is the EMF generated class representing the metamodel element
ArrayList<Root> rootElements =3D new ArrayList<Root>();
while(packages.hasNext()) {
EObject o =3D (EObject)elements.next();
if(o instanceof Root) {
rootElements.add((Root)o);
}
}
//Saving each root-Element as model
for(int i =3D 0; i < packs.size(); i++) { =
=
Root root =3D roots.get(i);
//<Root id=3D1></Root>
//Get the URI of the model file.
URI newFileURI =3D URI.createFileURI(root.getId() + ".model");
//Create a resource for this file.
Resource resource =3D resourceSet.createResource(newFileURI);
// Add the book and writer objects to the contents.
resource.getContents().add(root);
try
{
resource.save(Collections.EMPTY_MAP);
}
catch (IOException e) {}
}
//********************************************************** *****
Rainer
|
|
|
Powered by
FUDForum. Page generated in 0.02688 seconds