/**
* <copyright>
* </copyright>
*
* $Id: ManyToOneImpl.java,v 1.8 2008/09/21 19:03:18 mtaal Exp $
*/
package org.eclipse.emf.teneo.annotations.pannotation.impl;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;
import org.eclipse.emf.teneo.annotations.pannotation.CascadeType;
import org.eclipse.emf.teneo.annotations.pannotation.FetchType;
import org.eclipse.emf.teneo.annotations.pannotation.ManyToOne;
import org.eclipse.emf.teneo.annotations.pannotation.PannotationPackage;
/**
* <!-- begin-user-doc --> An implementation of the model object '<em><b>Many To One</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.emf.teneo.annotations.pannotation.impl.ManyToOneImpl#getTargetEntity <em>Target Entity</em>}</li>
* <li>{@link org.eclipse.emf.teneo.annotations.pannotation.impl.ManyToOneImpl#getCascade <em>Cascade</em>}</li>
* <li>{@link org.eclipse.emf.teneo.annotations.pannotation.impl.ManyToOneImpl#getFetch <em>Fetch</em>}</li>
* <li>{@link org.eclipse.emf.teneo.annotations.pannotation.impl.ManyToOneImpl#isOptional <em>Optional</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class ManyToOneImpl extends PAnnotationImpl implements ManyToOne {
/**
* The default value of the '{@link #getTargetEntity() <em>Target Entity</em>}' attribute.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getTargetEntity()
* @generated
* @ordered
*/
protected static final String TARGET_ENTITY_EDEFAULT = null;
/**
* The cached value of the '{@link #getTargetEntity() <em>Target Entity</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getTargetEntity()
* @generated
* @ordered
*/
protected String targetEntity = TARGET_ENTITY_EDEFAULT;
/**
* The cached value of the '{@link #getCascade() <em>Cascade</em>}' attribute list. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getCascade()
* @generated
* @ordered
*/
protected EList<CascadeType> cascade;
/**
* The default value of the '{@link #getFetch() <em>Fetch</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getFetch()
* @generated
* @ordered
*/
protected static final FetchType FETCH_EDEFAULT = FetchType.EAGER;
/**
* The cached value of the '{@link #getFetch() <em>Fetch</em>}' attribute.
* <!-- begin-user-doc
* --> <!-- end-user-doc -->
* @see #getFetch()
* @generated
* @ordered
*/
protected FetchType fetch = FETCH_EDEFAULT;
/**
* This is true if the Fetch attribute has been set.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
protected boolean fetchESet;
/**
* The default value of the '{@link #isOptional() <em>Optional</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #isOptional()
* @generated
* @ordered
*/
protected static final boolean OPTIONAL_EDEFAULT = true;
/**
* The cached value of the '{@link #isOptional() <em>Optional</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #isOptional()
* @generated
* @ordered
*/
protected boolean optional = OPTIONAL_EDEFAULT;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected ManyToOneImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return PannotationPackage.Literals.MANY_TO_ONE;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public FetchType getFetch() {
return fetch;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setFetch(FetchType newFetch) {
FetchType oldFetch = fetch;
fetch = newFetch == null ? FETCH_EDEFAULT : newFetch;
boolean oldFetchESet = fetchESet;
fetchESet = true;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, PannotationPackage.MANY_TO_ONE__FETCH, oldFetch, fetch, !oldFetchESet));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void unsetFetch() {
FetchType oldFetch = fetch;
boolean oldFetchESet = fetchESet;
fetch = FETCH_EDEFAULT;
fetchESet = false;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.UNSET, PannotationPackage.MANY_TO_ONE__FETCH, oldFetch, FETCH_EDEFAULT, oldFetchESet));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean isSetFetch() {
return fetchESet;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public boolean isOptional() {
return optional;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setOptional(boolean newOptional) {
boolean oldOptional = optional;
optional = newOptional;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, PannotationPackage.MANY_TO_ONE__OPTIONAL, oldOptional, optional));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case PannotationPackage.MANY_TO_ONE__TARGET_ENTITY:
return getTargetEntity();
case PannotationPackage.MANY_TO_ONE__CASCADE:
return getCascade();
case PannotationPackage.MANY_TO_ONE__FETCH:
return getFetch();
case PannotationPackage.MANY_TO_ONE__OPTIONAL:
return isOptional() ? Boolean.TRUE : Boolean.FALSE;
}
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 PannotationPackage.MANY_TO_ONE__TARGET_ENTITY:
setTargetEntity((String)newValue);
return;
case PannotationPackage.MANY_TO_ONE__CASCADE:
getCascade().clear();
getCascade().addAll((Collection<? extends CascadeType>)newValue);
return;
case PannotationPackage.MANY_TO_ONE__FETCH:
setFetch((FetchType)newValue);
return;
case PannotationPackage.MANY_TO_ONE__OPTIONAL:
setOptional(((Boolean)newValue).booleanValue());
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case PannotationPackage.MANY_TO_ONE__TARGET_ENTITY:
setTargetEntity(TARGET_ENTITY_EDEFAULT);
return;
case PannotationPackage.MANY_TO_ONE__CASCADE:
getCascade().clear();
return;
case PannotationPackage.MANY_TO_ONE__FETCH:
unsetFetch();
return;
case PannotationPackage.MANY_TO_ONE__OPTIONAL:
setOptional(OPTIONAL_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case PannotationPackage.MANY_TO_ONE__TARGET_ENTITY:
return TARGET_ENTITY_EDEFAULT == null ? targetEntity != null : !TARGET_ENTITY_EDEFAULT.equals(targetEntity);
case PannotationPackage.MANY_TO_ONE__CASCADE:
return cascade != null && !cascade.isEmpty();
case PannotationPackage.MANY_TO_ONE__FETCH:
return isSetFetch();
case PannotationPackage.MANY_TO_ONE__OPTIONAL:
return optional != OPTIONAL_EDEFAULT;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public String getTargetEntity() {
return targetEntity;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setTargetEntity(String newTargetEntity) {
String oldTargetEntity = targetEntity;
targetEntity = newTargetEntity;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, PannotationPackage.MANY_TO_ONE__TARGET_ENTITY, oldTargetEntity, targetEntity));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public EList<CascadeType> getCascade() {
if (cascade == null) {
cascade = new EDataTypeUniqueEList<CascadeType>(CascadeType.class, this, PannotationPackage.MANY_TO_ONE__CASCADE);
}
return cascade;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
if (eIsProxy()) return super.toString();
StringBuffer result = new StringBuffer(super.toString());
result.append(" (targetEntity: ");
result.append(targetEntity);
result.append(", cascade: ");
result.append(cascade);
result.append(", fetch: ");
if (fetchESet) result.append(fetch); else result.append("<unset>");
result.append(", optional: ");
result.append(optional);
result.append(')');
return result.toString();
}
@Override
protected String getAnnotationValue(org.eclipse.emf.ecore.EObject eObject, EStructuralFeature eFeature,
boolean prependComma, List<String> imports) {
if (eFeature == PannotationPackage.eINSTANCE.getManyToOne_TargetEntity()) {
// do not return anything because jpa expects a real classname,
// the targetentity only has an entityname here.
return "";
}
return super.getAnnotationValue(eObject, eFeature, prependComma, imports);
}
} // ManyToOneImpl