| //Generated on Thu Jan 12 17:22:18 CET 2012 with EGF 0.6.1.qualifier |
| package fcore.builder.patterns; |
| |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| import org.eclipse.egf.model.fcore.FactoryComponent; |
| import org.eclipse.egf.model.fprod.ProductionPlan; |
| import org.eclipse.egf.model.pattern.*; |
| import org.eclipse.egf.pattern.execution.*; |
| import org.eclipse.egf.pattern.query.IQuery; |
| import org.eclipse.egf.portfolio.genchain.generationChain.GenerationElement; |
| import org.eclipse.egf.portfolio.genchain.tools.FcoreBuilderConstants; |
| import org.eclipse.egf.portfolio.genchain.tools.utils.ActivityInvocationHelper; |
| import org.eclipse.egf.portfolio.genchain.tools.utils.FCMatcher; |
| |
| public class GenerationChainPattern { |
| |
| public GenerationChainPattern() { |
| //Here is the constructor |
| // add initialisation of the pattern variables (declaration has been already done). |
| } |
| |
| public void generate(Object argument) throws Exception { |
| InternalPatternContext ctx = (InternalPatternContext) argument; |
| IQuery.ParameterDescription paramDesc = null; |
| Map<String, String> queryCtx = null; |
| Node.Container currentNode = ctx.getNode(); |
| List<Object> parameterList = null; |
| //this pattern can only be called by another (i.e. it's not an entry point in execution) |
| |
| for (Object parameterParameter : parameterList) { |
| |
| this.parameter = (org.eclipse.egf.portfolio.genchain.generationChain.GenerationChain) parameterParameter; |
| |
| if (preCondition(ctx)) { |
| ctx.setNode(new Node.Container(currentNode, getClass())); |
| orchestration((PatternContext) argument); |
| |
| } |
| } |
| if (ctx.useReporter()) { |
| ctx.getReporter().executionFinished(OutputManager.computeExecutionOutput(ctx), ctx); |
| } |
| } |
| |
| public String orchestration(PatternContext ctx) throws Exception { |
| InternalPatternContext ictx = (InternalPatternContext) ctx; |
| Node.Container currentNode = ictx.getNode(); |
| method_body(new StringBuffer(), ictx); |
| ictx.setNode(currentNode); |
| if (ictx.useReporter()) { |
| Map<String, Object> parameterValues = new HashMap<String, Object>(); |
| parameterValues.put("parameter", this.parameter); |
| String outputWithCallBack = OutputManager.computeLoopOutput(ictx); |
| String loop = OutputManager.computeLoopOutputWithoutCallback(ictx); |
| ictx.getReporter().loopFinished(loop, outputWithCallBack, ictx, parameterValues); |
| } |
| return null; |
| } |
| |
| protected void method_body(final StringBuffer out, final PatternContext ctx) throws Exception { |
| Map<GenerationElement, FactoryComponent> fcs = (Map<GenerationElement, FactoryComponent>) ctx.getValue(FcoreBuilderConstants.CURRENT_FCORE); |
| |
| FactoryComponent parentFC = fcs.get((GenerationElement) (parameter.eContainer())); |
| |
| Collection<FactoryComponent> unused = (Collection<FactoryComponent>) ctx.getValue(FcoreBuilderConstants.UNUSED_FCORE); |
| FactoryComponent fc = FCMatcher.getFC(unused, parameter); |
| if (fc == null) { |
| fc = ActivityInvocationHelper.createDefaultFC(parameter.getName()); |
| parentFC.eResource().getContents().add(fc); |
| } else { |
| ActivityInvocationHelper.clearOrchestration(fc); |
| unused.remove(fc); |
| } |
| fcs.put(parameter, fc); |
| |
| ActivityInvocationHelper.addInvocation((ProductionPlan) parentFC.getOrchestration(), fc); |
| |
| InternalPatternContext ictx = (InternalPatternContext) ctx; |
| new Node.DataLeaf(ictx.getNode(), getClass(), "body", out.toString()); |
| } |
| |
| public boolean preCondition(PatternContext ctx) throws Exception { |
| return true; |
| } |
| |
| protected org.eclipse.egf.portfolio.genchain.generationChain.GenerationChain parameter; |
| |
| public void set_parameter(org.eclipse.egf.portfolio.genchain.generationChain.GenerationChain parameter) { |
| this.parameter = parameter; |
| } |
| |
| public Map<String, Object> getParameters() { |
| Map<String, Object> parameters = new HashMap<String, Object>(); |
| parameters.put("parameter", this.parameter); |
| return parameters; |
| } |
| |
| } |