| /******************************************************************************* |
| * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Gabor Bergmann - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.gtasm.patternmatcher.incremental.simple; |
| |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.adapters.GTASMBuildable; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.construction.RetePatternBuildException; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.construction.Stub; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.construction.helpers.BuildHelper; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.util.Options; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.util.Options.BuilderMethod; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.simple.legacy.BodyScaffold; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPatternBody; |
| |
| |
| |
| public class PatternScaffold<StubHandle, Collector> { |
| protected SimpleReteBuilder<StubHandle, Collector> baseBuilder; |
| protected GTASMBuildable<StubHandle, Collector> baseBuildable; |
| |
| protected GTPattern gtPattern; |
| protected Collector prodNode; // FIXME |
| |
| /** |
| * @param baseBuilder |
| * @param pattern |
| */ |
| public PatternScaffold(SimpleReteBuilder<StubHandle, Collector> builder, GTPattern gtPattern, |
| Collector production) { |
| super(); |
| this.baseBuilder = builder; |
| this.baseBuildable = builder.baseBuildable; // TODO select container? |
| this.gtPattern = gtPattern; |
| this.prodNode = production; |
| } |
| |
| public Collector run() throws RetePatternBuildException { |
| baseBuilder.context.logDebug( |
| "SimpleReteBuilder starts construction of: " + gtPattern.getName()); |
| |
| // Production prodNode = baseBuilder.boundary.accessProduction(gtPattern); |
| |
| Collector collector = prodNode; |
| // if (false /*gtPattern.isDistinctMatching()*/) |
| // { |
| // UniquenessEnforcerNode uen = new |
| // UniquenessEnforcerNode(baseBuilder.reteNet); |
| // baseBuilder.reteNet.connect(uen,collector); |
| // collector = uen; |
| // } |
| |
| for (GTPatternBody body : gtPattern.getPatternBodies()) { |
| // select container |
| GTASMBuildable<StubHandle, Collector> currentBuildable = baseBuildable.getNextContainer().putOnTab(gtPattern); |
| |
| if (Options.builderMethod == BuilderMethod.LEGACY) { |
| new BodyScaffold<StubHandle, Collector>(baseBuilder, currentBuildable, this, body, collector).run(); |
| } else { |
| GTPatternBodyToPSystem<StubHandle, Collector> converter = |
| new GTPatternBodyToPSystem<StubHandle, Collector>(gtPattern, body, baseBuilder, currentBuildable); |
| Stub<StubHandle> bodyFinal = |
| Options.builderMethod.<GTPattern,StubHandle,Collector>layoutStrategy().layout(converter.toPSystem()); |
| BuildHelper.projectIntoCollector(currentBuildable, bodyFinal, collector, converter.symbolicParameterArray()); |
| } |
| } |
| |
| return prodNode; |
| |
| } |
| |
| // /** |
| // * @return the baseBuilder |
| // */ |
| // public SimpleReteBuilder<StubHandle, Collector> getBuilder() { |
| // return baseBuilder; |
| // } |
| |
| // /** |
| // * @return the baseBuildable |
| // */ |
| // public GTASMBuildable<StubHandle, Collector> getBuildable() { |
| // return baseBuildable; |
| // } |
| |
| /** |
| * @return the gtPattern |
| */ |
| public GTPattern getGtPattern() { |
| return gtPattern; |
| } |
| |
| |
| |
| } |