/**
* <copyright>
* </copyright>
*
* $Id$
*/
package OntoUML.impl;
import OntoUML.Element;
import OntoUML.OntoUMLPackage;
import OntoUML.Relationship;
import java.util.Collection;
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.util.EcoreEList;
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>Relationship</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link OntoUML.impl.RelationshipImpl#getRelatedElement <em>Related Element</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class RelationshipImpl extends ElementImpl implements Relationship {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected RelationshipImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return OntoUMLPackage.Literals.RELATIONSHIP;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EList<Element> getRelatedElement() {
EStructuralFeature eFeature = OntoUMLPackage.Literals.RELATIONSHIP__RELATED_ELEMENT;
if (relatedElementDeriveOCL == null) {
Helper helper = OCL_ENV.createOCLHelper();
helper.setAttributeContext(OntoUMLPackage.Literals.RELATIONSHIP, eFeature);
EAnnotation ocl = eFeature.getEAnnotation(OCL_ANNOTATION_SOURCE);
String derive = (String) ocl.getDetails().get("derive");
try {
relatedElementDeriveOCL = helper.createQuery(derive);
} catch (ParserException e) {
throw new UnsupportedOperationException(e.getLocalizedMessage());
}
}
Query<EClassifier, ?, ?> query = OCL_ENV.createQuery(relatedElementDeriveOCL);
@SuppressWarnings("unchecked")
Collection<Element> result = (Collection<Element>) query.evaluate(this);
return new EcoreEList.UnmodifiableEList<Element>(this, eFeature, result.size(), result.toArray());
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case OntoUMLPackage.RELATIONSHIP__RELATED_ELEMENT:
return getRelatedElement();
}
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.RELATIONSHIP__RELATED_ELEMENT:
getRelatedElement().clear();
getRelatedElement().addAll((Collection<? extends Element>)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case OntoUMLPackage.RELATIONSHIP__RELATED_ELEMENT:
getRelatedElement().clear();
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case OntoUMLPackage.RELATIONSHIP__RELATED_ELEMENT:
return !getRelatedElement().isEmpty();
}
return super.eIsSet(featureID);
}
/**
* The parsed OCL expression for the derivation of '{@link #getRelatedElement <em>Related Element</em>}' property.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getRelatedElement
* @generated
*/
private static OCLExpression<EClassifier> relatedElementDeriveOCL;
private static final String OCL_ANNOTATION_SOURCE = "http://www.eclipse.org/ocl/examples/OCL";
private static final OCL OCL_ENV = OCL.newInstance();
} //RelationshipImpl