Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
*
*
* Copyright (c) 2007, 2009 IBM Corporation and others.
* 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:
* IBM - Initial API and implementation
* Adolfo Sanchez-Barbudo Herrera - Bug 233673
* Zeligsoft - Bugs 233673, 261128
* E.D.Willink - Bug 242236
* Radek Dvorak - Bug 261128
*
*
*
* $Id: OCLUtil.java,v 1.10 2009/12/04 21:26:07 ewillink Exp $
*/
package org.eclipse.ocl.util;
import java.lang.ref.Reference;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.ocl.Environment;
import org.eclipse.ocl.EnvironmentFactory;
import org.eclipse.ocl.EvaluationEnvironment;
import org.eclipse.ocl.LookupException;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.SemanticException;
import org.eclipse.ocl.SyntaxException;
import org.eclipse.ocl.TypeChecker;
import org.eclipse.ocl.lpg.AbstractBasicEnvironment;
import org.eclipse.ocl.lpg.BasicEnvironment;
import org.eclipse.ocl.lpg.BasicEnvironment2;
import org.eclipse.ocl.lpg.ProblemHandler;
import org.eclipse.ocl.options.Customizable;
import org.eclipse.ocl.parser.OCLProblemHandler;
import org.eclipse.ocl.utilities.TypedElement;
/**
* Miscellaneous utilities for use by the OCL parser/interpreter and by clients.
*
* @author Christian W. Damus (cdamus)
*
* @since 1.2
*/
public final class OCLUtil {
/** Use weak references as the keys to avoid memory leaks. */
private static final Map, Reference> environments = new java.util.WeakHashMap, Reference>();
/** Use weak references as the keys to avoid memory leaks. */
private static final Map, Reference>> typesCheckerEnvironments = new java.util.WeakHashMap, Reference>>();
// prevent instantiation
private OCLUtil() {
super();
}
/**
* Obtains an adapter for the specified interface type. Even for
* environments that do not adapt to the following interfaces, this method
* will provide a default implementation for convenience:
*
*
{@link BasicEnvironment}. In the case that the environment is not
* intrinsically adaptable to this interface and an extrinsic adapter
* is provided, multiple adaptations of the same environment will
* always return the same adapter instance
*
{@link Customizable}. In the case that the environment is not
* intrinsically adaptable to this interface it is forcibly adapted to
* the {@link BasicEnvironment} protocol
*
{@link ProblemHandler}
*
{@link Environment.Lookup}
*
*
* @param the requested adapter interface
*
* @param env an environment to adapt
* @param adapterType the requested adapter interface
* @return an instance of the requested interface, or null
* if this environment does not adapt to it
*/
@SuppressWarnings("unchecked")
public static T getAdapter(
Environment, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?> env,
Class adapterType) {
T result;
if (env instanceof Adaptable) {
result = ((Adaptable) env).getAdapter(adapterType);
} else if (adapterType.isInstance(env)) {
result = (T) env;
} else {
result = null;
}
if (result == null) {
if (adapterType == TypeChecker.class) {
result = (T) getTypeChecker(env);
} else if (adapterType == BasicEnvironment.class) {
result = (T) getBasicEnvironment(env);
} else if (adapterType == BasicEnvironment2.class) {
result = (T) getBasicEnvironment(env);
} else if (adapterType == ProblemHandler.class) {
result = (T) getAdapter(env, BasicEnvironment.class).getProblemHandler();
} else if (adapterType == Environment.Lookup.class) {
final Environment