blob: e399b0c505d79f8e54e998b321022f43a771e22e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Akos Horvath, Gergely Varro 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:
* Akos Horvath, Gergely Varro - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.core;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
import org.eclipse.viatra2.gtasm.patternmatcher.PatternMatcherParameters;
import org.eclipse.viatra2.gtasm.patternmatcher.extension.IGTRuleMatcherFactory;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GTErrorStrings;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.exceptions.GraphTransformationException;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.gtmatcher.internal.TraditionalGTRuleMatcher;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.BasicTermHandler;
import org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.term.TermHandler;
import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IGTRuleMatcher;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTRule;
/**
* Implements the IGTRuleMatcherFactory org.eclipse.viatra2.gtasm.patternmatcher.extension point for the viatra GTASM org.eclipse.viatra2.gtasm.interpreter.impl.interpreter with Local search based pattern matching
* @author Akos Horvath
*
*/
public class LocalSearchGTRuleMatcherFactory implements IGTRuleMatcherFactory {
private IGTRuleMatcher construct(GTRule gtRule, IExecutionEnvironment enviroment, PatternMatcherParameters pmParams)
throws ViatraTransformationException {
if (gtRule.getPrecondition() != null) {
// traditional type gtRule with local search based pattern matching
TermHandler handler = new BasicTermHandler(enviroment);
return new TraditionalGTRuleMatcher(gtRule,enviroment, handler, pmParams);
} else {
enviroment.getFramework().getLogger().warning("ActionPattern type GTRule not yet supported");
}
return null;
}
public IGTRuleMatcher getGTMatcher(IExecutionEnvironment gtEnviroment,
GTRule gtRule, PatternMatcherParameters mp)
throws ViatraTransformationException {
IGTRuleMatcher gtMatcher=null;
if (GTRuleMatchers.getInstance().containsKey(gtRule)) {
// We already had it precompiled
gtMatcher=GTRuleMatchers.getInstance().get(gtRule);
gtMatcher.initGTRule(gtEnviroment);
} else {
// We need to make a new gtMatcher
// GTRuleBuilder gtBuilder = new GTRuleBuilder(gtEnviroment.getFramework().getLogger(), gtEnviroment.getFramework().getTopmodel().getModelManager(), handlerr);
// gtMatcher = gtBuilder.construct(gtRule, gtEnviroment,mp);
gtMatcher = construct(gtRule, gtEnviroment,mp);
if (gtMatcher != null) {
GTRuleMatchers.getInstance().put(gtRule, gtMatcher);
} else {
String[] context = {gtRule.getName()};
throw new GraphTransformationException(GTErrorStrings.GTRULETYPE_NOTSUPPORTED
,context
,gtRule);
}
}
return gtMatcher;
}
}