org.eclipse.ocl.options.EvaluationOptions Maven / Gradle / Ivy
/**
*
*
* Copyright (c) 2007, 2008 IBM Corporation, Zeligsoft Inc., 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
* Zeligsoft - Bug 253252
*
*
*
* $Id: EvaluationOptions.java,v 1.2 2008/11/05 16:30:17 cdamus Exp $
*/
package org.eclipse.ocl.options;
import org.eclipse.ocl.EvaluationEnvironment;
import org.eclipse.ocl.util.OCLUtil;
/**
* Options applicable to {@link EvaluationEnvironment}s to
* {@linkplain Customizable customize} their evaluation behaviour.
*
* @author Christian W. Damus (cdamus)
*
* @since 1.2
*/
public class EvaluationOptions {
/**
*
* Evaluation option indicating whether to implement lax handling of null
* values in certain OclAny-defined operations. When true,
* the null.oclIsKindOf(OclType) and null.oclIsTypeOf(OclType)
* operations will return true for any OCL type instead of
* returning OclInvalid, as OclVoid is defined as
* conforming to all other types. Similarly, null.oclAsType(OclType)
* will return null for any OCL type instead of OclInvalid
* as prescribed by the OCL 2.0 Specification.
*
* For backward compatibility with the 1.1 release behaviour, the default
* value of this option is true. For strict conformance to the
* specification, use false.
*
*
* @since 1.2
*/
public static final Option LAX_NULL_HANDLING = new BasicOption(
"lax.null.handling", true); //$NON-NLS-1$
/**
* Not instantiable by clients.
*/
private EvaluationOptions() {
super();
}
/**
* Add an option to apply to the specified environment, adapting it as
* necessary to the {@link Customizable} API.
*
* @param env an evaluation environment on which to set an option
* @param option the option
* @param value the option's value
*
* @see Cusotmizable#setOption(Option, Object)
*/
public static void setOption(EvaluationEnvironment, ?, ?, ?, ?> env,
Option option, T value) {
Customizable custom = OCLUtil.getAdapter(env, Customizable.class);
if (custom != null) {
custom.setOption(option, value);
}
}
/**
* Obtains the value of the specified option's setting in the the given
* environment's options map, adapting the environment as necessary to the
* {@link Customizable} API. If not already set, return the option's
* {@linkplain #getDefaultValue() default value}.
*
* @param env an evaluation environment on which to query an option
* @param option an option to query
*
* @return value of the option
*
* @see Customizable#getValue(Option)
*/
public static T getValue(EvaluationEnvironment, ?, ?, ?, ?> env,
Option option) {
Customizable custom = OCLUtil.getAdapter(env, Customizable.class);
if (custom != null) {
return custom.getValue(option);
}
return option.getDefaultValue();
}
}