carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.lite.templates/xpt/expressions/RegexpExpressionFactory.xpt
author cawthron
Fri, 04 Dec 2009 11:06:59 -0600
changeset 422 033392511bf7
permissions -rw-r--r--
add files for RCL_2_2

/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * 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:
 *    bblajer (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::GenModelUtils»

«DEFINE RegexpExpressionFactory FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::copyright FOR container.editorGen»
package «container.expressionsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «className» «EXPAND supertypes» {
	«EXPAND ctor-»

	«EXPAND getExpression-»

	«EXPAND additions-»

	«EXPAND Expression-»
}
«ENDDEFINE»

«DEFINE supertypes FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»

«DEFINE ctor FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
private «className»() {
}
«ENDDEFINE»

«DEFINE getExpression FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
	return new «EXPAND ExpressionClassName»(body, context, environment);
}

«EXPAND xpt::Common::generatedMemberComment»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context) {
	return getExpression(body, context, java.util.Collections.EMPTY_MAP);
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»

«DEFINE ExpressionClassName FOR gmfgen::GenExpressionInterpreter»Expression«ENDDEFINE»

«DEFINE Expression FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedClassComment»
private static class «EXPAND ExpressionClassName» extends «container.getAbstractExpressionQualifiedClassName()» {
	«EXPAND Expression_pattern-»

	«EXPAND Expression_ctor-»

	«EXPAND Expression_doEvaluate-»

	«EXPAND Expression_additions-»
}
«ENDDEFINE»

«DEFINE Expression_pattern FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
private final java.util.regex.Pattern pattern;
«ENDDEFINE»

«DEFINE Expression_ctor FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
public «EXPAND ExpressionClassName»(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
	super(body, context);
	java.util.regex.Pattern p;
	try {
		p = java.util.regex.Pattern.compile(body);
	} catch (java.util.regex.PatternSyntaxException e) {
		setStatus(org.eclipse.core.runtime.IStatus.ERROR, e.getMessage(), e);
		p = null;
	}
	this.pattern = p;
}
«ENDDEFINE»

«DEFINE Expression_doEvaluate FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
protected Object doEvaluate(Object contextInstance, java.util.Map env) {
	if (pattern == null) {
		return null;
	}

	if(context() instanceof org.eclipse.emf.ecore.EDataType) {
		contextInstance = org.eclipse.emf.ecore.util.EcoreUtil.convertToString((org.eclipse.emf.ecore.EDataType)context(), contextInstance);
	}

	java.util.regex.Matcher matcher = this.pattern.matcher(String.valueOf(contextInstance));
	return Boolean.valueOf(«EXPAND possibleNegation»matcher.matches());
}
«ENDDEFINE»

«DEFINE possibleNegation FOR gmfgen::GenExpressionInterpreter»«IF language.literal != gmfgen::GenLanguage::regexp.literal»!«ENDIF»«ENDDEFINE»

«DEFINE Expression_additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»