|
|
|
Re: [Xpand2]Loading multiple model files [message #676041 is a reply to message #676036] |
Thu, 02 June 2011 15:15 |
|
Hi,
what about asking the resources for their contents. and add all the contents to the slot. see the org.eclipse.emf.mwe.utils.Reader component.
final Resource res;
try {
res = resourceSet.getResource(URI.createURI(uri), true);
if (res == null)
throw new WorkflowInterruptedException("Couldn't find resource under " + uri);
if (!res.isLoaded()) {
res.load(Collections.EMPTY_MAP);
}
}
catch (final WrappedException e) {
if (ignoreMissingModel) {
return null;
}
throw new WorkflowInterruptedException("Couldn't load resource under " + uri + " : " + e.getMessage());
}
catch (final IOException e) {
if (ignoreMissingModel) {
return null;
}
throw new WorkflowInterruptedException("Couldn't load resource under " + uri + " : " + e.getMessage());
}
final EList<EObject> result = res.getContents();
if (firstElementOnly) {
if (result.isEmpty())
return null;
return result.iterator().next();
}
else
return result;
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
|
Re: [Xpand2]Loading multiple model files [message #676608 is a reply to message #676563] |
Sun, 05 June 2011 17:20 |
|
Hi,
you have to write (as Serge did) a custom workflow component that does this for you. this component could look like (quick n dirty) or a mix of serges and my post above.
package components;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.lib.WorkflowComponentWithModelSlot;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
public class MultiModelReader extends WorkflowComponentWithModelSlot {
private List<String> uris = new ArrayList<String>();
public void addUri(String uri) {
uris.add(uri);
}
@Override
protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
Issues issues) {
ResourceSet set = new ResourceSetImpl();
List<EObject> allContents = new ArrayList<EObject>();
for(String uri : uris){
Resource resource = set.getResource(URI.createURI(uri), true);
allContents.addAll(resource.getContents());
}
ctx.set(getModelSlot(), allContents);
}
}
<?xml version="1.0"?>
<workflow>
<property name="src-gen" value="src-gen" />
<!-- set up EMF for standalone execution -->
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
<platformUri value=".."/>
<registerEcoreFile value="src/metamodel/metamodel.ecore" />
</bean>
<!-- instantiate metamodel -->
<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<!-- load model and store it in slot 'model' -->
<component class="components.MultiModelReader">
<uri value="platform:/resource/my.generator.project/src/model/Model.xmi" />
<uri value="platform:/resource/my.generator.project/src/model/Model2.xmi" />
<modelSlot value="model" />
</component>
<!-- generate code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel idRef="mm_emf"/>
<expand
value="template::Template::main FOREACH model" />
<outlet path="${src-gen}" >
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
</outlet>
</component>
</workflow>
if you want to scan a directory you need somthing like serge + but as discussed before you have to add all contents of the resources to a list as i do it in my code.
if you want to call a template for a list simpoly ajust the definition
«DEFINE main FOR List[Model]»
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
[Updated on: Sun, 05 June 2011 17:38] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03923 seconds