[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] Problem with ATL transformation

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/sample-Families.ecore
Families=file:/C:/dev/TestAtl/models/Families2Persons/Families.ecore EMF
--out OUT=file:/C:/dev/TestAtl/models/Families2Persons/sample-Persons.ecore
Persons=file:/C:/dev/workspace/TestAtl/models/Families2Persons/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(XMLHandler.java:1715)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:1553)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:717)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:765)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:462)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:65)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:449)
at org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWrapper.java:73)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.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(XMLResourceImpl.java:169)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:977)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:832)
at org.atl.engine.repositories.emf4atl.ASMEMFModel.loadASMEMFModel(ASMEMFModel.java:323)
at org.atl.eclipse.engine.AtlEMFModelHandler.loadModel(AtlEMFModelHandler.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(currentOutModel, (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.