Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » Problem with ATL transformation
Problem with ATL transformation [message #80661] Sun, 04 May 2008 21:59 Go to next message
Geam Carlos is currently offline Geam CarlosFriend
Messages: 17
Registered: July 2009
Junior Member
Hi all,

First, excuse the English poor.

I would like the help of someone with this problem. I want to launch an
ATL Transformation by running a Java programm (Code of the main class
below). Firstly I tried this with the simple "Author2Person"
Transformation and it works fine, putting as argument the following models:
--trans file:/C:/dev/workspace/TestAtl
/models/Families2Persons/Families2Persons.asm
--in
IN=file:/C:/dev/workspace/TestAtl/models/Families2Persons/sa mple-Families.ecore
Families=file:/C:/dev/TestAtl/models/Families2Persons/Famili es.ecore EMF
--out OUT=file:/C:/dev/TestAtl/models/Families2Persons/sample-Pers ons.ecore
Persons=file:/C:/dev/workspace/TestAtl/models/Families2Perso ns/Persons.ecore
EMF

I got the output model what i want.
I want to run now the same class (Code of the main class below) with other
argument of models (uml2), for example:

--trans file:/C:/dev/workspace/TestAtl/trans/test.asm
--in IN=file:/C:/dev/workspace/TestAtl/models/model_test.uml2
UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF
//Obs.: UML metamodel withdrawn from
org.eclipse.uml2.source_2.1.1.v200708301222. It's the metamodel UML2
correct?
--in ASPECTS=file:/C:/dev/workspace/TestAtl/models/model_aspects. uml2
UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF
--out OUT=file:/C:/dev/workspace/TestAtl/model/test_out.uml2
UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF

Throw the following error:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
'http://www.eclipse.org/uml2/2.0.0/UML' not found.
(file:/C:/dev/workspace/TestAtl/metamodel/Superstructure.uml , 3, 58)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1715)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:717)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:765)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:462)
at
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
at
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
at
org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:533)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:878)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFra gmentScannerImpl.java:1693)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 368)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:834)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:764)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1242)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at
org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
at
org.atl.engine.repositories.emf4atl.ASMEMFModel.loadASMEMFMo del(ASMEMFModel.java:323)
at
org.atl.eclipse.engine.AtlEMFModelHandler.loadModel(AtlEMFMo delHandler.java:122)
at br.ufrj.nce.crossmda.MainMy.loadModel(MainMy.java:122)
at br.ufrj.nce.crossmda.MainMy.addInputModel(MainMy.java:228)
at br.ufrj.nce.crossmda.MainMy.parseArgs(MainMy.java:169)
at br.ufrj.nce.crossmda.MainMy.main(MainMy.java:98)

Someone help me?


Main class:
import org.atl.eclipse.engine.AtlEMFModelHandler;
import org.atl.eclipse.engine.AtlLauncher;
import org.atl.eclipse.engine.AtlModelHandler;
import org.atl.engine.repositories.emf4atl.ASMEMFModel;
import org.atl.engine.repositories.mdr4atl.AtlMDRModelHandler;
import org.atl.engine.vm.nativelib.ASMModel;

public class MainMy implements Runnable {
public static final String USAGE =
"Usage: <this program> " +
"--trans <transformation url> " +
"[--in <id>=<model> <id>=<metamodel> <MDR|EMF>] " +
"[--out <id>=<model> <id>=<metamodel> <MDR|EMF>] " +
"[--lib <id>=<library url>] " +
"[--superimpose <transformation url>] " +
"--next --trans ...";
...
private static URI cwd = URI.createURI("file:" + new
File(".").getAbsolutePath());
private int argPos = 0;

public static AtlModelHandler getDefaultHandler(String repository) {
AtlModelHandler amh = null;
try {
amh = AtlModelHandler.getDefault(repository);
} catch (Throwable e) {
if ("MDR".equals(repository)) {
AtlModelHandler.registerDefaultHandler("MDR", new
AtlMDRModelHandler());
amh = AtlModelHandler.getDefault(repository);
} else {
throw new RuntimeException(e);
}
}
return amh;
}
public static void main(String[] args) {
MainMy main = new MainMy();
int argsLeft = args.length;
do {
argsLeft = main.parseArgs(args);
if (argsLeft > -1)
main.run();
} while (argsLeft > 0);
if (argsLeft < 0) {
System.exit(1);
} else {
System.exit(0);
}
}
public static ASMModel loadModel(AtlModelHandler amh, String
modelId, ASMModel metaModel, String uri)
throws FileNotFoundException {
ASMModel model = null;
if (amh instanceof AtlEMFModelHandler) {
URI absURI = URI.createURI(uri);//.resolve(cwd);
model = ((AtlEMFModelHandler)amh).loadModel(
modelId, metaModel, absURI);
try {
Method getReferencedExtents =
model.getClass().getMethod("getReferencedExtents", null);
System.out.println("Referenced extents: " +
getReferencedExtents.invoke(model, null));
} catch (Exception e) {
System.out.println("The EMF4ATL version used does not
support referenced extents (multiple-file models)");
}
} else {
model = amh.loadModel(modelId, metaModel, new
FileInputStream(uri));
}
return model;
}
private void logStrings(String[] strings) {
StringBuffer output = new StringBuffer();
for (int i = 0; i < strings.length; i++) {
if (i > 0) { output.append(' '); }
output.append(strings[i]);
}
System.out.println(output.toString());
}
public int parseArgs(String[] args) {
if (args.length <= argPos+1) {
System.out.println(USAGE);
return -1;
}
try {
for (int i = argPos; i < args.length; i++) {
if (args[i].equals("--trans")) {
i++;
logStrings(new String[] { args[i-1], args[i] });
trans = new URL(args[i]);
} else if (args[i].equals("--in")) {
i++; i++; i++;
logStrings(new String[] { args[i-3], args[i-2],
args[i-1], args[i] });
addInputModel(args[i-2], args[i-1], args[i]);
} else if (args[i].equals("--out")) {
i++; i++; i++;
logStrings(new String[] { args[i-3], args[i-2],
args[i-1], args[i] });
addOutputModel(args[i-2], args[i-1], args[i]);
} else if (args[i].equals("--lib")) {
i++;
logStrings(new String[] { args[i-1], args[i] });
addLib(args[i]);
} else if (args[i].equals("--superimpose")) {
i++;
logStrings(new String[] { args[i-1], args[i] });
superimpose.add(new URL(args[i]));
} else if (args[i].equals("--next")) {
i++;
argPos = i;
logStrings(new String[] { args[i-1] });
return args.length - argPos;
} else {
System.out.print(USAGE);
return -1;
}
}
} catch (Exception e) {
System.err.print(e.toString());
e.printStackTrace();
System.out.print(USAGE);
return -1;
}
return 0;
}

public void addInputModel(String model, String metamodel, String
repository)
throws Exception {
StringTokenizer mdl = new StringTokenizer(model, "=");
String modelid = mdl.nextToken();
String modelpath = mdl.nextToken();
StringTokenizer metamdl = new StringTokenizer(metamodel, "=");
String metaid = metamdl.nextToken();
String metapath = metamdl.nextToken();

AtlModelHandler amh = getDefaultHandler(repository);
ASMModel metaModel;
ASMModel inputModel;
if (metaid.equals("MOF")) {
System.out.println("Input metamodel is MOF - using built-in
metamodel");
metaModel = amh.getMof();
}
else {
metaModel = (ASMModel) in.get(metaid);
if (metaModel == null || !metapath.equals(paths.get(metaid))) {
System.out.println("Input metamodel " + metaid + " @ " +
amh + " not yet loaded - loading from " + metapath);
metaModel = loadModel(amh, metaid, amh.getMof(), metapath);
metaModel.setIsTarget(false);
in.put(metaid, metaModel);
}
}
handlers.put(metaid, repository);
System.out.println("Using input metamodel " + metaModel);
inputModel = (ASMModel) modelCache.get(modelid);
if (inputModel == null ||
!modelpath.equals(paths.get(modelid)) ||
!metaid.equals(inputModel.getMetamodel().getName())) {
System.out.println("Loading input model " + modelid + " from "
+ modelpath);
inputModel = loadModel(amh, modelid, metaModel, modelpath);
inputModel.setIsTarget(false);
if (inputModel instanceof ASMEMFModel)
((ASMEMFModel)inputModel).setCheckSameModel(false);
modelCache.put(modelid, inputModel);
}
System.out.println("Using input model " + inputModel);
in.put(modelid, inputModel);
paths.put(modelid, modelpath);
paths.put(metaid, metapath);
}

public void addOutputModel(String model, String metamodel, String
repository)
throws Exception {
StringTokenizer mdl = new StringTokenizer(model, "=");
String modelid = mdl.nextToken();
String modelpath = mdl.nextToken();
StringTokenizer metamdl = new StringTokenizer(metamodel, "=");
String metaid = metamdl.nextToken();
String metapath = metamdl.nextToken();

AtlModelHandler amh = getDefaultHandler(repository);
ASMModel metaModel;
ASMModel outputModel;
if (metaid.equals("MOF")) {
System.out.println("Output metamodel is MOF - using built-in
metamodel");
metaModel = amh.getMof();
}
else {
metaModel = (ASMModel) in.get(metaid);
if (metaModel == null || !metapath.equals(paths.get(metaid))) {
System.out.println("Loading output metamodel " + metaid +
" @ " + amh + " from " + metapath);
metaModel = loadModel(amh, metaid, amh.getMof(), metapath);
metaModel.setIsTarget(false);
in.put(metaid, metaModel);
}
}
handlers.put(metaid, repository);
System.out.println("Using output metamodel " + metaModel);
System.out.println("Creating new model " + modelid + " for
output");
outputModel = amh.newModel(modelid, modelpath, metaModel);
if (outputModel instanceof ASMEMFModel)
((ASMEMFModel)outputModel).setCheckSameModel(false);
out.put(modelid, outputModel);
paths.put(modelid, modelpath);
paths.put(metaid, metapath);
}

public void addLib(String lib) throws Exception {
StringTokenizer l = new StringTokenizer(lib, "=");
String libid = l.nextToken();
URL liburl = new URL(l.nextToken());
libs.put(libid, liburl);
}
public void run() {
try {
System.out.println("Starting model transformation " + trans);
Map models = new HashMap();
// add input models
for(Iterator i = in.keySet().iterator() ; i.hasNext() ; ) {
String mName = (String)i.next();
models.put(mName, in.get(mName));
}
// add output models
for(Iterator i = out.keySet().iterator() ; i.hasNext() ; ) {
String mName = (String)i.next();
models.put(mName, out.get(mName));
}
Map params = Collections.EMPTY_MAP;
AtlLauncher myLauncher = AtlLauncher.getDefault();
myLauncher.launch(trans, libs, models, params, superimpose);
System.out.println("Model transformation done");
// save output models
for(Iterator i = out.keySet().iterator(); i.hasNext() ; ) {
String mName = (String)i.next();
ASMModel currentOutModel = (ASMModel)out.get(mName);
String mmName = currentOutModel.getMetamodel().getName();

getDefaultHandler((String)handlers.get(mmName)).saveModel(cu rrentOutModel,
(String) paths.get(mName));
System.out.println("Wrote " + (String) paths.get(mName));
modelCache.put(mName, currentOutModel);
i.remove();
}
} catch (Exception e) {
System.err.print(e.toString());
e.printStackTrace();
System.out.println(USAGE);
System.exit(1);
}
}

}



any help?

best regards!

--
Geam Carlos.
[ATL] Re: Problem with ATL transformation [message #80774 is a reply to message #80661] Tue, 06 May 2008 09:43 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 297
Registered: July 2009
Senior Member
Hello,

First, remember to prefix your subjects with [ATL].

Geam Carlos a écrit :
> Hi all,
>
> First, excuse the English poor.
>
> I would like the help of someone with this problem. I want to launch an
> ATL Transformation by running a Java programm (Code of the main class
> below). Firstly I tried this with the simple "Author2Person"
> Transformation and it works fine, putting as argument the following models:
> --trans file:/C:/dev/workspace/TestAtl
> /models/Families2Persons/Families2Persons.asm
> --in
> IN=file:/C:/dev/workspace/TestAtl/models/Families2Persons/sa mple-Families.ecore
>
> Families=file:/C:/dev/TestAtl/models/Families2Persons/Famili es.ecore EMF
> --out OUT=file:/C:/dev/TestAtl/models/Families2Persons/sample-Pers ons.ecore
> Persons=file:/C:/dev/workspace/TestAtl/models/Families2Perso ns/Persons.ecore
> EMF
>
> I got the output model what i want.
> I want to run now the same class (Code of the main class below) with
> other argument of models (uml2), for example:
>
> --trans file:/C:/dev/workspace/TestAtl/trans/test.asm
> --in IN=file:/C:/dev/workspace/TestAtl/models/model_test.uml2
> UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF
> //Obs.: UML metamodel withdrawn from
> org.eclipse.uml2.source_2.1.1.v200708301222. It's the metamodel UML2
> correct?

Here you better have to use the UML2 uri :
http://www.eclipse.org/uml2/<version you use ?>/UML

> --in ASPECTS=file:/C:/dev/workspace/TestAtl/models/model_aspects. uml2
> UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF
> --out OUT=file:/C:/dev/workspace/TestAtl/model/test_out.uml2
> UML=file:/C:/dev/workspace/TestAtl/metamodel/Superstructure. uml EMF
>
> Throw the following error:
> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
> 'http://www.eclipse.org/uml2/2.0.0/UML' not found.

The error may comes from the fact that you use the wrong uml metamodel,
which doesn't provide the expected package.

Best regards,

William
> (file:/C:/dev/workspace/TestAtl/metamodel/Superstructure.uml , 3, 58)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1715)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType (XMLHandler.java:717)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XM LHandler.java:765)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:462)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
> at
> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(AbstractSAXParser.java:533)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.j ava:878)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFra gmentScannerImpl.java:1693)
>
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java: 368)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:834)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(XML11Configuration.java:764)
>
> at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(X MLParser.java:148)
>
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(AbstractSAXParser.java:1242)
>
> at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>
> at
> org.atl.engine.repositories.emf4atl.ASMEMFModel.loadASMEMFMo del(ASMEMFModel.java:323)
>
> at
> org.atl.eclipse.engine.AtlEMFModelHandler.loadModel(AtlEMFMo delHandler.java:122)
>
> at br.ufrj.nce.crossmda.MainMy.loadModel(MainMy.java:122)
> at br.ufrj.nce.crossmda.MainMy.addInputModel(MainMy.java:228)
> at br.ufrj.nce.crossmda.MainMy.parseArgs(MainMy.java:169)
> at br.ufrj.nce.crossmda.MainMy.main(MainMy.java:98)
>
> Someone help me?
>
>
> Main class:
> import org.atl.eclipse.engine.AtlEMFModelHandler;
> import org.atl.eclipse.engine.AtlLauncher;
> import org.atl.eclipse.engine.AtlModelHandler;
> import org.atl.engine.repositories.emf4atl.ASMEMFModel;
> import org.atl.engine.repositories.mdr4atl.AtlMDRModelHandler;
> import org.atl.engine.vm.nativelib.ASMModel;
>
> public class MainMy implements Runnable {
> public static final String USAGE =
> "Usage: <this program> " +
> "--trans <transformation url> " +
> "[--in <id>=<model> <id>=<metamodel> <MDR|EMF>] " +
> "[--out <id>=<model> <id>=<metamodel> <MDR|EMF>] " +
> "[--lib <id>=<library url>] " +
> "[--superimpose <transformation url>] " +
> "--next --trans ...";
> ...
> private static URI cwd = URI.createURI("file:" + new
> File(".").getAbsolutePath());
> private int argPos = 0;
>
> public static AtlModelHandler getDefaultHandler(String repository) {
> AtlModelHandler amh = null;
> try {
> amh = AtlModelHandler.getDefault(repository);
> } catch (Throwable e) {
> if ("MDR".equals(repository)) {
> AtlModelHandler.registerDefaultHandler("MDR", new
> AtlMDRModelHandler());
> amh = AtlModelHandler.getDefault(repository);
> } else {
> throw new RuntimeException(e);
> }
> }
> return amh;
> }
> public static void main(String[] args) {
> MainMy main = new MainMy();
> int argsLeft = args.length;
> do {
> argsLeft = main.parseArgs(args);
> if (argsLeft > -1)
> main.run();
> } while (argsLeft > 0);
> if (argsLeft < 0) {
> System.exit(1);
> } else {
> System.exit(0);
> }
> }
> public static ASMModel loadModel(AtlModelHandler amh, String
> modelId, ASMModel metaModel, String uri)
> throws FileNotFoundException {
> ASMModel model = null;
> if (amh instanceof AtlEMFModelHandler) {
> URI absURI = URI.createURI(uri);//.resolve(cwd);
> model = ((AtlEMFModelHandler)amh).loadModel(
> modelId, metaModel, absURI);
> try {
> Method getReferencedExtents =
> model.getClass().getMethod("getReferencedExtents", null);
> System.out.println("Referenced extents: " +
> getReferencedExtents.invoke(model, null));
> } catch (Exception e) {
> System.out.println("The EMF4ATL version used does not
> support referenced extents (multiple-file models)");
> }
> } else {
> model = amh.loadModel(modelId, metaModel, new
> FileInputStream(uri));
> }
> return model;
> }
> private void logStrings(String[] strings) {
> StringBuffer output = new StringBuffer();
> for (int i = 0; i < strings.length; i++) {
> if (i > 0) { output.append(' '); }
> output.append(strings[i]);
> }
> System.out.println(output.toString());
> }
> public int parseArgs(String[] args) {
> if (args.length <= argPos+1) {
> System.out.println(USAGE);
> return -1;
> }
> try {
> for (int i = argPos; i < args.length; i++) {
> if (args[i].equals("--trans")) {
> i++;
> logStrings(new String[] { args[i-1], args[i] });
> trans = new URL(args[i]);
> } else if (args[i].equals("--in")) {
> i++; i++; i++;
> logStrings(new String[] { args[i-3], args[i-2],
> args[i-1], args[i] });
> addInputModel(args[i-2], args[i-1], args[i]);
> } else if (args[i].equals("--out")) {
> i++; i++; i++;
> logStrings(new String[] { args[i-3], args[i-2],
> args[i-1], args[i] });
> addOutputModel(args[i-2], args[i-1], args[i]);
> } else if (args[i].equals("--lib")) {
> i++;
> logStrings(new String[] { args[i-1], args[i] });
> addLib(args[i]);
> } else if (args[i].equals("--superimpose")) {
> i++;
> logStrings(new String[] { args[i-1], args[i] });
> superimpose.add(new URL(args[i]));
> } else if (args[i].equals("--next")) {
> i++;
> argPos = i;
> logStrings(new String[] { args[i-1] });
> return args.length - argPos;
> } else {
> System.out.print(USAGE);
> return -1;
> }
> }
> } catch (Exception e) {
> System.err.print(e.toString());
> e.printStackTrace();
> System.out.print(USAGE);
> return -1;
> }
> return 0;
> }
>
> public void addInputModel(String model, String metamodel, String
> repository)
> throws Exception {
> StringTokenizer mdl = new StringTokenizer(model, "=");
> String modelid = mdl.nextToken();
> String modelpath = mdl.nextToken();
> StringTokenizer metamdl = new StringTokenizer(metamodel, "=");
> String metaid = metamdl.nextToken();
> String metapath = metamdl.nextToken();
>
> AtlModelHandler amh = getDefaultHandler(repository);
> ASMModel metaModel;
> ASMModel inputModel;
> if (metaid.equals("MOF")) {
> System.out.println("Input metamodel is MOF - using built-in
> metamodel");
> metaModel = amh.getMof();
> }
> else {
> metaModel = (ASMModel) in.get(metaid);
> if (metaModel == null || !metapath.equals(paths.get(metaid))) {
> System.out.println("Input metamodel " + metaid + " @ " +
> amh + " not yet loaded - loading from " + metapath);
> metaModel = loadModel(amh, metaid, amh.getMof(), metapath);
> metaModel.setIsTarget(false);
> in.put(metaid, metaModel);
> }
> }
> handlers.put(metaid, repository);
> System.out.println("Using input metamodel " + metaModel);
> inputModel = (ASMModel) modelCache.get(modelid);
> if (inputModel == null ||
> !modelpath.equals(paths.get(modelid)) ||
> !metaid.equals(inputModel.getMetamodel().getName())) {
> System.out.println("Loading input model " + modelid + " from
> " + modelpath);
> inputModel = loadModel(amh, modelid, metaModel, modelpath);
> inputModel.setIsTarget(false);
> if (inputModel instanceof ASMEMFModel)
> ((ASMEMFModel)inputModel).setCheckSameModel(false);
> modelCache.put(modelid, inputModel);
> }
> System.out.println("Using input model " + inputModel);
> in.put(modelid, inputModel);
> paths.put(modelid, modelpath);
> paths.put(metaid, metapath);
> }
>
> public void addOutputModel(String model, String metamodel, String
> repository)
> throws Exception {
> StringTokenizer mdl = new StringTokenizer(model, "=");
> String modelid = mdl.nextToken();
> String modelpath = mdl.nextToken();
> StringTokenizer metamdl = new StringTokenizer(metamodel, "=");
> String metaid = metamdl.nextToken();
> String metapath = metamdl.nextToken();
>
> AtlModelHandler amh = getDefaultHandler(repository);
> ASMModel metaModel;
> ASMModel outputModel;
> if (metaid.equals("MOF")) {
> System.out.println("Output metamodel is MOF - using built-in
> metamodel");
> metaModel = amh.getMof();
> }
> else {
> metaModel = (ASMModel) in.get(metaid);
> if (metaModel == null || !metapath.equals(paths.get(metaid))) {
> System.out.println("Loading output metamodel " + metaid +
> " @ " + amh + " from " + metapath);
> metaModel = loadModel(amh, metaid, amh.getMof(), metapath);
> metaModel.setIsTarget(false);
> in.put(metaid, metaModel);
> }
> }
> handlers.put(metaid, repository);
> System.out.println("Using output metamodel " + metaModel);
> System.out.println("Creating new model " + modelid + " for output");
> outputModel = amh.newModel(modelid, modelpath, metaModel);
> if (outputModel instanceof ASMEMFModel)
> ((ASMEMFModel)outputModel).setCheckSameModel(false);
> out.put(modelid, outputModel);
> paths.put(modelid, modelpath);
> paths.put(metaid, metapath);
> }
>
> public void addLib(String lib) throws Exception {
> StringTokenizer l = new StringTokenizer(lib, "=");
> String libid = l.nextToken();
> URL liburl = new URL(l.nextToken());
> libs.put(libid, liburl);
> }
> public void run() {
> try {
> System.out.println("Starting model transformation " + trans);
> Map models = new HashMap();
> // add input models
> for(Iterator i = in.keySet().iterator() ; i.hasNext() ; ) {
> String mName = (String)i.next();
> models.put(mName, in.get(mName));
> }
> // add output models
> for(Iterator i = out.keySet().iterator() ; i.hasNext() ; ) {
> String mName = (String)i.next();
> models.put(mName, out.get(mName));
> }
> Map params = Collections.EMPTY_MAP;
> AtlLauncher myLauncher = AtlLauncher.getDefault();
> myLauncher.launch(trans, libs, models, params, superimpose);
> System.out.println("Model transformation done");
> // save output models
> for(Iterator i = out.keySet().iterator(); i.hasNext() ; ) {
> String mName = (String)i.next();
> ASMModel currentOutModel = (ASMModel)out.get(mName);
> String mmName = currentOutModel.getMetamodel().getName();
>
> getDefaultHandler((String)handlers.get(mmName)).saveModel(cu rrentOutModel,
> (String) paths.get(mName));
> System.out.println("Wrote " + (String) paths.get(mName));
> modelCache.put(mName, currentOutModel);
> i.remove();
> }
> } catch (Exception e) {
> System.err.print(e.toString());
> e.printStackTrace();
> System.out.println(USAGE);
> System.exit(1);
> }
> }
>
> }
>
>
>
> any help?
>
> best regards!
>
> --
> Geam Carlos.
>
Re: [ATL] Re: Problem with ATL transformation [message #80822 is a reply to message #80774] Tue, 06 May 2008 12:46 Go to previous message
Geam Carlos is currently offline Geam CarlosFriend
Messages: 17
Registered: July 2009
Junior Member
William Piers, Thanks for the answer.

I changed the uri for uri: http://www.eclipse.org/uml2/2.1.0/UML and does
not present the error "Package not found", launched another error, but I
will check it.

Best Regards.
Previous Topic:[ATL] Copying one model with reference to another => ClassCastException
Next Topic:forcing late resolve
Goto Forum:
  


Current Time: Tue Jun 18 13:16:45 GMT 2019

Powered by FUDForum. Page generated in 0.01707 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top