Package OntoUML.impl

Source Code of OntoUML.impl.DirectedBinaryRelationshipImpl

/**
* <copyright>
* </copyright>
*
* $Id$
*/
package OntoUML.impl;

import OntoUML.Classifier;
import OntoUML.DirectedBinaryRelationship;
import OntoUML.Generalization;
import OntoUML.NamedElement;
import OntoUML.OntoUMLPackage;
import OntoUML.Property;
import OntoUML.RelationalClassifier;
import OntoUML.Type;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.ecore.OCL;
import org.eclipse.ocl.ecore.OCL.Helper;
import org.eclipse.ocl.expressions.OCLExpression;

/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Directed Binary Relationship</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
*   <li>{@link OntoUML.impl.DirectedBinaryRelationshipImpl#getName <em>Name</em>}</li>
*   <li>{@link OntoUML.impl.DirectedBinaryRelationshipImpl#getAttribute <em>Attribute</em>}</li>
*   <li>{@link OntoUML.impl.DirectedBinaryRelationshipImpl#isIsAbstract <em>Is Abstract</em>}</li>
*   <li>{@link OntoUML.impl.DirectedBinaryRelationshipImpl#getGeneral <em>General</em>}</li>
*   <li>{@link OntoUML.impl.DirectedBinaryRelationshipImpl#getGeneralization <em>Generalization</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class DirectedBinaryRelationshipImpl extends DirectedRelationshipImpl implements DirectedBinaryRelationship {
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The default value of the '{@link #isIsAbstract() <em>Is Abstract</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isIsAbstract()
   * @generated
   * @ordered
   */
  protected static final boolean IS_ABSTRACT_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isIsAbstract() <em>Is Abstract</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isIsAbstract()
   * @generated
   * @ordered
   */
  protected boolean isAbstract = IS_ABSTRACT_EDEFAULT;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected DirectedBinaryRelationshipImpl() {
    super();
  }

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName() {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Property> getAttribute() {
    EStructuralFeature eFeature = OntoUMLPackage.Literals.CLASSIFIER__ATTRIBUTE;
 
    if (attributeDeriveOCL == null) {
      Helper helper = OCL_ENV.createOCLHelper();
      helper.setAttributeContext(OntoUMLPackage.Literals.CLASSIFIER, eFeature);
     
      EAnnotation ocl = eFeature.getEAnnotation(OCL_ANNOTATION_SOURCE);
      String derive = (String) ocl.getDetails().get("derive");
     
      try {
        attributeDeriveOCL = helper.createQuery(derive);
      } catch (ParserException e) {
        throw new UnsupportedOperationException(e.getLocalizedMessage());
      }
    }
   
    Query<EClassifier, ?, ?> query = OCL_ENV.createQuery(attributeDeriveOCL);
 
    @SuppressWarnings("unchecked")
    Collection<Property> result = (Collection<Property>) query.evaluate(this);
    return new EcoreEList.UnmodifiableEList<Property>(this, eFeature, result.size(), result.toArray());
 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isIsAbstract() {
    return isAbstract;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setIsAbstract(boolean newIsAbstract) {
    boolean oldIsAbstract = isAbstract;
    isAbstract = newIsAbstract;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT, oldIsAbstract, isAbstract));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Classifier> getGeneral() {
    EStructuralFeature eFeature = OntoUMLPackage.Literals.CLASSIFIER__GENERAL;
 
    if (generalDeriveOCL == null) {
      Helper helper = OCL_ENV.createOCLHelper();
      helper.setAttributeContext(OntoUMLPackage.Literals.CLASSIFIER, eFeature);
     
      EAnnotation ocl = eFeature.getEAnnotation(OCL_ANNOTATION_SOURCE);
      String derive = (String) ocl.getDetails().get("derive");
     
      try {
        generalDeriveOCL = helper.createQuery(derive);
      } catch (ParserException e) {
        throw new UnsupportedOperationException(e.getLocalizedMessage());
      }
    }
   
    Query<EClassifier, ?, ?> query = OCL_ENV.createQuery(generalDeriveOCL);
 
    @SuppressWarnings("unchecked")
    Collection<Classifier> result = (Collection<Classifier>) query.evaluate(this);
    return new EcoreEList.UnmodifiableEList<Classifier>(this, eFeature, result.size(), result.toArray());
 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Generalization> getGeneralization() {
    EStructuralFeature eFeature = OntoUMLPackage.Literals.CLASSIFIER__GENERALIZATION;
 
    if (generalizationDeriveOCL == null) {
      Helper helper = OCL_ENV.createOCLHelper();
      helper.setAttributeContext(OntoUMLPackage.Literals.CLASSIFIER, eFeature);
     
      EAnnotation ocl = eFeature.getEAnnotation(OCL_ANNOTATION_SOURCE);
      String derive = (String) ocl.getDetails().get("derive");
     
      try {
        generalizationDeriveOCL = helper.createQuery(derive);
      } catch (ParserException e) {
        throw new UnsupportedOperationException(e.getLocalizedMessage());
      }
    }
   
    Query<EClassifier, ?, ?> query = OCL_ENV.createQuery(generalizationDeriveOCL);
 
    @SuppressWarnings("unchecked")
    Collection<Generalization> result = (Collection<Generalization>) query.evaluate(this);
    return new EcoreEList.UnmodifiableEList<Generalization>(this, eFeature, result.size(), result.toArray());
 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID) {
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE:
        return ((InternalEList<?>)getAttribute()).basicRemove(otherEnd, msgs);
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION:
        return ((InternalEList<?>)getGeneralization()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID) {
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME:
        return getName();
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE:
        return getAttribute();
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT:
        return isIsAbstract() ? Boolean.TRUE : Boolean.FALSE;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL:
        return getGeneral();
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION:
        return getGeneralization();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue) {
    switch (featureID) {
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME:
        setName((String)newValue);
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE:
        getAttribute().clear();
        getAttribute().addAll((Collection<? extends Property>)newValue);
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT:
        setIsAbstract(((Boolean)newValue).booleanValue());
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL:
        getGeneral().clear();
        getGeneral().addAll((Collection<? extends Classifier>)newValue);
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION:
        getGeneralization().clear();
        getGeneralization().addAll((Collection<? extends Generalization>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID) {
    switch (featureID) {
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME:
        setName(NAME_EDEFAULT);
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE:
        getAttribute().clear();
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT:
        setIsAbstract(IS_ABSTRACT_EDEFAULT);
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL:
        getGeneral().clear();
        return;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION:
        getGeneralization().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID) {
    switch (featureID) {
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE:
        return !getAttribute().isEmpty();
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT:
        return isAbstract != IS_ABSTRACT_EDEFAULT;
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL:
        return !getGeneral().isEmpty();
      case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION:
        return !getGeneralization().isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
    if (baseClass == NamedElement.class) {
      switch (derivedFeatureID) {
        case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME: return OntoUMLPackage.NAMED_ELEMENT__NAME;
        default: return -1;
      }
    }
    if (baseClass == Type.class) {
      switch (derivedFeatureID) {
        default: return -1;
      }
    }
    if (baseClass == Classifier.class) {
      switch (derivedFeatureID) {
        case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE: return OntoUMLPackage.CLASSIFIER__ATTRIBUTE;
        case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT: return OntoUMLPackage.CLASSIFIER__IS_ABSTRACT;
        case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL: return OntoUMLPackage.CLASSIFIER__GENERAL;
        case OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION: return OntoUMLPackage.CLASSIFIER__GENERALIZATION;
        default: return -1;
      }
    }
    if (baseClass == RelationalClassifier.class) {
      switch (derivedFeatureID) {
        default: return -1;
      }
    }
    return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
    if (baseClass == NamedElement.class) {
      switch (baseFeatureID) {
        case OntoUMLPackage.NAMED_ELEMENT__NAME: return OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__NAME;
        default: return -1;
      }
    }
    if (baseClass == Type.class) {
      switch (baseFeatureID) {
        default: return -1;
      }
    }
    if (baseClass == Classifier.class) {
      switch (baseFeatureID) {
        case OntoUMLPackage.CLASSIFIER__ATTRIBUTE: return OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__ATTRIBUTE;
        case OntoUMLPackage.CLASSIFIER__IS_ABSTRACT: return OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__IS_ABSTRACT;
        case OntoUMLPackage.CLASSIFIER__GENERAL: return OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERAL;
        case OntoUMLPackage.CLASSIFIER__GENERALIZATION: return OntoUMLPackage.DIRECTED_BINARY_RELATIONSHIP__GENERALIZATION;
        default: return -1;
      }
    }
    if (baseClass == RelationalClassifier.class) {
      switch (baseFeatureID) {
        default: return -1;
      }
    }
    return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(", isAbstract: ");
    result.append(isAbstract);
    result.append(')');
    return result.toString();
  }

  /**
   * The parsed OCL expression for the derivation of '{@link #getAttribute <em>Attribute</em>}' property.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getAttribute
   * @generated
   */
  private static OCLExpression<EClassifier> attributeDeriveOCL;

  /**
   * The parsed OCL expression for the derivation of '{@link #getGeneral <em>General</em>}' property.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getGeneral
   * @generated
   */
  private static OCLExpression<EClassifier> generalDeriveOCL;

  /**
   * The parsed OCL expression for the derivation of '{@link #getGeneralization <em>Generalization</em>}' property.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getGeneralization
   * @generated
   */
  private static OCLExpression<EClassifier> generalizationDeriveOCL;

  private static final String OCL_ANNOTATION_SOURCE = "http://www.eclipse.org/ocl/examples/OCL";

  private static final OCL OCL_ENV = OCL.newInstance();

} //DirectedBinaryRelationshipImpl
TOP

Related Classes of OntoUML.impl.DirectedBinaryRelationshipImpl

TOP
Copyright © 2015 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.