XPandfacade and Check [message #732211] |
Tue, 04 October 2011 05:08  |
Eclipse User |
|
|
|
hi to all
i have some problemens using check in XPand
for now i have done this:
Resource resource;
//...load resource
OutputImpl output = new OutputImpl();
//...
ProtectedRegionResolverImpl prs = new ProtectedRegionResolverImpl();
//...
UML2MetaModel mm = new UML2MetaModel();
Map<String,Variable> globalVarsMap = new HashMap<String,Variable>();
//...
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, prs,
globalVarsMap, null, null);
execCtx.registerMetaModel(mm);
//checkcomponents
CheckComponent c = new CheckComponent();
c.addMetaModel(mm);
c.addCheckFile("templateMiddle::javacheck");
WorkflowContextImpl ctx = new WorkflowContextImpl();
ctx.put("", resource.getContents().get(0));
c.invoke(ctx);
//für primtive Types etc...
new Setup().setStandardUML2Setup(true);
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("templateMiddle::Template::main", resource.getContents().get(0));
i have added to the checkcomponent the metamodel and the checkFile. because i found no possibility to set the checkcomponent in the executionContext, i guess i have to use the invoke method of the checkcomponent. but this method expects a WorkFlowContext Object. but i'm not sure what i have put in this workFlowObject. Maybe someone knows it?
greetings
stoehm
|
|
|
|
|
|
|
|
|
Re: XPandfacade and Check [message #734959 is a reply to message #734919] |
Mon, 10 October 2011 10:24  |
Eclipse User |
|
|
|
thanks a lot, now it works fine!
for everbody who is interested, the code is below
//...put the model in a resource
LinkedList<Object> ll = new LinkedList<Object>();
//copy the treeIterator from eAllContents into a linkedList
for(TreeIterator<EObject> iterator = resource.getContents().get(0).eAllContents(); iterator.hasNext();){
ll.add(iterator.next());
}
IssuesImpl issues =new IssuesImpl();
CheckFacade.checkAll("templateMiddle::javacheck",ll , execCtx, issues);
//print out all Errors that are detected
MWEDiagnostic[] errors = issues.getErrors();
for(int i=0;i<errors.length;i++){
System.out.println(errors[i].toString());
}
//print out all Warnings that are detected
MWEDiagnostic[] warnings = issues.getWarnings();
for(int i=0;i<warnings.length;i++){
System.out.println(warnings[i].toString());
}
//only evalute the xpandfacade when there are no errors
if(!issues.hasErrors()){
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("templateMiddle::Template::main", resource.getContents().get(0));
}
|
|
|
Powered by
FUDForum. Page generated in 0.05591 seconds