/**
 */
package org.etsi.mts.tdl.impl;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.ocl.pivot.evaluation.Executor;
import org.eclipse.ocl.pivot.ids.IdResolver;
import org.eclipse.ocl.pivot.library.oclany.OclAnyOclAsTypeOperation;
import org.eclipse.ocl.pivot.library.oclany.OclAnyOclIsTypeOfOperation;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.ocl.pivot.utilities.ValueUtil;
import org.eclipse.ocl.pivot.values.InvalidValueException;
import org.etsi.mts.tdl.AnyValue;
import org.etsi.mts.tdl.DataType;
import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.Element;
import org.etsi.mts.tdl.Member;
import org.etsi.mts.tdl.MemberAssignment;
import org.etsi.mts.tdl.Parameter;
import org.etsi.mts.tdl.ParameterBinding;
import org.etsi.mts.tdl.SpecialValueUse;
import org.etsi.mts.tdl.tdlPackage;
import org.etsi.mts.tdl.tdlTables;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Special Value Use</b></em>'.
 * <!-- end-user-doc -->
 *
 * @generated
 */
public abstract class SpecialValueUseImpl extends StaticDataUseImpl implements SpecialValueUse
{
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SpecialValueUseImpl()
	{
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass()
	{
		return tdlPackage.Literals.SPECIAL_VALUE_USE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataType resolveDataType()
	{
		/**
		 *
		 * if self.container().oclIsTypeOf(MemberAssignment)
		 * then
		 *   self.container()
		 *   .oclAsType(MemberAssignment).member.dataType
		 * else
		 *   if self.container().oclIsTypeOf(ParameterBinding)
		 *   then
		 *     self.container()
		 *     .oclAsType(ParameterBinding).parameter.dataType
		 *   else
		 *     if
		 *       self.container()
		 *       .oclIsTypeOf(Interaction) and
		 *       self.oclIsTypeOf(AnyValue)
		 *     then self.oclAsType(AnyValue).dataType
		 *     else null
		 *     endif
		 *   endif
		 * endif
		 */
		final /*@NonInvalid*/ Executor executor = PivotUtil.getExecutor(this);
		final /*@NonInvalid*/ IdResolver idResolver = executor.getIdResolver();
		final /*@NonInvalid*/ org.eclipse.ocl.pivot.Class TYP_tdl_c_c_MemberAssignment_0 = idResolver.getClass(tdlTables.CLSSid_MemberAssignment, null);
		final /*@NonInvalid*/ Element container = this.container();
		final /*@NonInvalid*/ boolean oclIsTypeOf = OclAnyOclIsTypeOfOperation.INSTANCE.evaluate(executor, container, TYP_tdl_c_c_MemberAssignment_0).booleanValue();
		/*@Thrown*/ DataType local_2;
		if (oclIsTypeOf) {
			final /*@Thrown*/ MemberAssignment oclAsType = (MemberAssignment)OclAnyOclAsTypeOperation.INSTANCE.evaluate(executor, container, TYP_tdl_c_c_MemberAssignment_0);
			final /*@Thrown*/ Member member = oclAsType.getMember();
			final /*@Thrown*/ DataType dataType = member.getDataType();
			local_2 = dataType;
		}
		else {
			final /*@NonInvalid*/ org.eclipse.ocl.pivot.Class TYP_tdl_c_c_ParameterBinding_0 = idResolver.getClass(tdlTables.CLSSid_ParameterBinding, null);
			final /*@NonInvalid*/ boolean oclIsTypeOf_0 = OclAnyOclIsTypeOfOperation.INSTANCE.evaluate(executor, container, TYP_tdl_c_c_ParameterBinding_0).booleanValue();
			/*@Thrown*/ DataType local_1;
			if (oclIsTypeOf_0) {
				final /*@Thrown*/ ParameterBinding oclAsType_0 = (ParameterBinding)OclAnyOclAsTypeOperation.INSTANCE.evaluate(executor, container, TYP_tdl_c_c_ParameterBinding_0);
				final /*@Thrown*/ Parameter parameter = oclAsType_0.getParameter();
				final /*@Thrown*/ DataType dataType_0 = parameter.getDataType();
				local_1 = dataType_0;
			}
			else {
				final /*@NonInvalid*/ org.eclipse.ocl.pivot.Class TYP_tdl_c_c_AnyValue_1 = idResolver.getClass(tdlTables.CLSSid_AnyValue, null);
				final /*@NonInvalid*/ org.eclipse.ocl.pivot.Class TYP_tdl_c_c_Interaction_0 = idResolver.getClass(tdlTables.CLSSid_Interaction, null);
				final /*@NonInvalid*/ boolean oclIsTypeOf_1 = OclAnyOclIsTypeOfOperation.INSTANCE.evaluate(executor, container, TYP_tdl_c_c_Interaction_0).booleanValue();
				final /*@NonInvalid*/ Boolean and;
				if (!oclIsTypeOf_1) {
					and = ValueUtil.FALSE_VALUE;
				}
				else {
					final /*@NonInvalid*/ boolean oclIsTypeOf_2 = OclAnyOclIsTypeOfOperation.INSTANCE.evaluate(executor, this, TYP_tdl_c_c_AnyValue_1).booleanValue();
					if (!oclIsTypeOf_2) {
						and = ValueUtil.FALSE_VALUE;
					}
					else {
						and = ValueUtil.TRUE_VALUE;
					}
				}
				if (and == null) {
					throw new InvalidValueException("Null if condition");
				}
				/*@Thrown*/ DataType local_0;
				if (and) {
					final /*@Thrown*/ AnyValue oclAsType_1 = (AnyValue)OclAnyOclAsTypeOperation.INSTANCE.evaluate(executor, this, TYP_tdl_c_c_AnyValue_1);
					final /*@Thrown*/ DataType dataType_1 = oclAsType_1.getDataType();
					local_0 = dataType_1;
				}
				else {
					local_0 = null;
				}
				local_1 = local_0;
			}
			local_2 = local_1;
		}
		return local_2;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass)
	{
		if (baseClass == DataUse.class) {
			switch (baseOperationID) {
				case tdlPackage.DATA_USE___RESOLVE_DATA_TYPE: return tdlPackage.SPECIAL_VALUE_USE___RESOLVE_DATA_TYPE;
				default: return super.eDerivedOperationID(baseOperationID, baseClass);
			}
		}
		return super.eDerivedOperationID(baseOperationID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException
	{
		switch (operationID) {
			case tdlPackage.SPECIAL_VALUE_USE___RESOLVE_DATA_TYPE:
				return resolveDataType();
		}
		return super.eInvoke(operationID, arguments);
	}

} //SpecialValueUseImpl
