Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2005, 2008 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: 
  *    Radek Dvorak (Borland) - initial API and implementation
  */
 package org.eclipse.gmf.internal.validate.expressions;
 
 import java.util.Map;
 
This class represents the base for expression. Clients providing new types of expression should sublass this class.
 
 public abstract class AbstractExpression implements IModelExpression  {
 	private IStatus status;
 	private String body;
 	private Map<StringEClassifierextEnv;

Constructs expression from its body, with specified context.

Parameters:
body specifies the evaluation logic in the language recognized by this expression.
context the class in which context the expression is to be parsed
extendedEnv additional parsing context information, can be null
Throws:
java.lang.IllegalArgumentException if any of the passed body, contextClassifier is null
 
 	protected AbstractExpression(String bodyEClassifier contextIParseEnvironment extendedEnv) {
 		if(body == null || context == null) {
 			throw new IllegalArgumentException("null body or context-class"); //$NON-NLS-1$
 		}
 		this. = body;			
 		this. = context;
 		if(extendedEnv != null) {
 			this. = new HashMap<StringEClassifier>(5);			
 			for (String nextVar : extendedEnv.getVariableNames()) {
 				.put(nextVarextendedEnv.getTypeOf(nextVar));
 			}
 		} else {
 			this. = Collections.emptyMap();
 		}
 	}
 	
 	protected Map<StringEClassifiergetExtEnvironment() {
 		return ;
 	}
 	
 	public boolean isLooselyTyped() {
 		return true;
 	}
 	
 	protected void setStatus(IStatus status) {
 		this. = status;
 	}

Performs evaluation of this expression in the context.

This method gets called by only if this expression has OK status and the passed context is valid

Parameters:
context the context instance for evaluation.
Returns:
result of this expression evalutation. In case this expression status is not OK status, null is returned.
 
 	protected abstract Object doEvaluate(Object context);

Performs evaluation of this expression in the extended context.

This method gets called by only if this expression has OK status and the passed context is valid

Parameters:
context the context instance for evaluation.
extendedEnv the environment with custom variables intialized for evaluation
Returns:
result of this expression evalutation. In case this expression status is not OK status, null is returned.
	protected abstract Object doEvaluate(Object contextIEvaluationEnvironment extendedEnv);	
	}
	public abstract boolean isAssignableTo(EClassifier ecoreType);
	public abstract boolean isAssignableToElement(ETypedElement typedElement);
	public abstract String getLanguage();	
	public final Object evaluate(Object context) {
		return evaluate(contextnull);
	}
	public final Object evaluate(Object contextInstanceIEvaluationEnvironment extendedEnv) {
		if(contextInstance == null || !hasCompatibleContext(contextInstance)) {
			throw new IllegalArgumentException("Invalid evaluation context:" + contextInstance); //$NON-NLS-1$
		}
		if(getStatus().isOK()) {
			try {
				if(extendedEnv != null) {
					return doEvaluate(contextInstanceextendedEnv);
				}
				return doEvaluate(contextInstance);				
catch (RuntimeException e) {
				IStatus status = GMFValidationPlugin.createStatus(
				GMFValidationPlugin.log(status);
			}
		}
		return null;
	}
	public IStatus getStatus() {
		return ;
	}
	public String getBody() {
		return ;
	}
	public EClassifier getContext() {
	}
	public String toString() {
		return  + " in context:[" + ..getObjectLabel() + "] "//$NON-NLS-1$ //$NON-NLS-2$
	}
	private boolean hasCompatibleContext(Object ctxInstance) {
		if( instanceof EClass) {
			EClass contextClass = (EClass);
			return (ctxInstance instanceof EObject) ? 
					contextClass.isSuperTypeOf(((EObject)ctxInstance).eClass()) : false;
		return .isInstance(ctxInstance);
	}	
New to GrepCode? Check out our FAQ X