blob: 50bd2a26cb767047058fd9e7d1f5f6d8ca1edaf5 [file] [log] [blame]
/*******************************************************************************
* 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;
import org.eclipse.viatra2.gtasm.interpreter.exception.ViatraTransformationException;
import org.eclipse.viatra2.gtasm.interpreter.executionEnvironment.IExecutionEnvironment;
import org.eclipse.viatra2.gtasm.patternmatcher.exceptions.PatternMatcherCompileTimeException;
import org.eclipse.viatra2.gtasm.patternmatcher.extension.IPatternMatcherFactory;
import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.construction.RetePatternBuildException;
import org.eclipse.viatra2.gtasm.patternmatcher.patterns.IPatternMatcher;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern;
/**
* @author Bergmann Gábor
*
*/
public class RetePatternMatcherFactory implements IPatternMatcherFactory {
public IPatternMatcher getPatternMatcher(IExecutionEnvironment env,
GTPattern pattern) throws ViatraTransformationException {
try {
return new ReteGTASMPatternMatcher(
EngineManager.getInstance()
.getReteEngine(env.getFramework())
.accessMatcher(pattern)
);
} catch (RetePatternBuildException e) {
String templateMessage = e.getTemplateMessage();
String[] templateContext = e.getTemplateContext();
Object patternDescription = e.getPatternDescription();
if (patternDescription!=null && patternDescription instanceof GTPattern && !patternDescription.equals(pattern))
throw new PatternMatcherCompileTimeException(templateMessage, templateContext,
(GTPattern) patternDescription, e).addNewStackElement(pattern);
else throw new PatternMatcherCompileTimeException(templateMessage, templateContext, pattern, e);
}
}
}