blob: 7856004c15cd91b9d6f4dc5f2491fe1ef47d0ab9 [file] [log] [blame]
/***********************************************************************************************************************
* Copyright (c) 2010 Attensity Europe GmbH.
* 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
**********************************************************************************************************************/
package org.eclipse.smila.processing.designer.model.record.impl;
import java.util.Collection;
import java.util.List;
import org.eclipse.bpel.model.impl.ExtensibleElementImpl;
import org.eclipse.bpel.model.util.ReconciliationHelper;
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.*;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.smila.processing.designer.model.processor.util.DOMUtils;
import org.eclipse.smila.processing.designer.model.record.*;
import org.eclipse.smila.processing.designer.model.record.util.RecordConstants;
import org.w3c.dom.Element;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Annotation</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.smila.processing.designer.model.record.impl.AnnotationImpl#getName <em>Name</em>}</li>
* <li>{@link org.eclipse.smila.processing.designer.model.record.impl.AnnotationImpl#getAnnotationValues <em>Annotation Values</em>}</li>
* <li>{@link org.eclipse.smila.processing.designer.model.record.impl.AnnotationImpl#getAnnotations <em>Annotations</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class AnnotationImpl extends ExtensibleElementImpl implements Annotation
{
/**
* 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 cached value of the '{@link #getAnnotationValues() <em>Annotation Values</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getAnnotationValues()
* @generated
* @ordered
*/
protected EList<AnnotationValue> annotationValues;
/**
* The cached value of the '{@link #getAnnotations() <em>Annotations</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getAnnotations()
* @generated
* @ordered
*/
protected EList<Annotation> annotations;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected AnnotationImpl()
{
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass()
{
return RecordPackage.Literals.ANNOTATION;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String getName()
{
return name;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @customized
*/
@Override
public void setName(String newName)
{
String oldName = name;
name = newName;
if (!isReconciling())
{
ReconciliationHelper.replaceAttribute(this, RecordConstants.ATT_N, newName);
}
if (eNotificationRequired())
{
eNotify(new ENotificationImpl(this, Notification.SET, RecordPackage.ANNOTATION__NAME, oldName, name));
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EList<AnnotationValue> getAnnotationValues()
{
if (annotationValues == null)
{
annotationValues =
new EObjectContainmentEList<AnnotationValue>(AnnotationValue.class, this,
RecordPackage.ANNOTATION__ANNOTATION_VALUES);
}
return annotationValues;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EList<Annotation> getAnnotations()
{
if (annotations == null)
{
annotations =
new EObjectContainmentEList<Annotation>(Annotation.class, this, RecordPackage.ANNOTATION__ANNOTATIONS);
}
return annotations;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
{
switch (featureID)
{
case RecordPackage.ANNOTATION__ANNOTATION_VALUES :
return ((InternalEList<?>) getAnnotationValues()).basicRemove(otherEnd, msgs);
case RecordPackage.ANNOTATION__ANNOTATIONS :
return ((InternalEList<?>) getAnnotations()).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 RecordPackage.ANNOTATION__NAME :
return getName();
case RecordPackage.ANNOTATION__ANNOTATION_VALUES :
return getAnnotationValues();
case RecordPackage.ANNOTATION__ANNOTATIONS :
return getAnnotations();
}
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 RecordPackage.ANNOTATION__NAME :
setName((String) newValue);
return;
case RecordPackage.ANNOTATION__ANNOTATION_VALUES :
getAnnotationValues().clear();
getAnnotationValues().addAll((Collection<? extends AnnotationValue>) newValue);
return;
case RecordPackage.ANNOTATION__ANNOTATIONS :
getAnnotations().clear();
getAnnotations().addAll((Collection<? extends Annotation>) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID)
{
switch (featureID)
{
case RecordPackage.ANNOTATION__NAME :
setName(NAME_EDEFAULT);
return;
case RecordPackage.ANNOTATION__ANNOTATION_VALUES :
getAnnotationValues().clear();
return;
case RecordPackage.ANNOTATION__ANNOTATIONS :
getAnnotations().clear();
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID)
{
switch (featureID)
{
case RecordPackage.ANNOTATION__NAME :
return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
case RecordPackage.ANNOTATION__ANNOTATION_VALUES :
return annotationValues != null && !annotationValues.isEmpty();
case RecordPackage.ANNOTATION__ANNOTATIONS :
return annotations != null && !annotations.isEmpty();
}
return super.eIsSet(featureID);
}
/**
* <!-- 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(')');
return result.toString();
}
/**
* Adopt any new annotation / annotation value.
*
* @see org.eclipse.wst.wsdl.internal.impl.WSDLElementImpl#adoptContent
*/
@Override
protected void adoptContent(EReference eReference, Object newValue)
{
boolean isAnnoatation = newValue instanceof Annotation;
if (isAnnoatation || newValue instanceof AnnotationValue)
{
boolean oldUpdatingDom = super.isUpdatingDOM();
if (!ReconciliationHelper.isLoading(this) && getElement() != null)
{
try
{
setUpdatingDOM(true);
Element parentElement = getElement();
if (isAnnoatation)
{
Annotation annotation = (Annotation) newValue;
Element annotationElement = annotation.getElement();
if (annotationElement == null)
{
annotationElement =
parentElement.getOwnerDocument().createElementNS(RecordPackage.eNS_URI,
RecordConstants.NODE_AN);
annotation.setElement(annotationElement);
annotationElement.setPrefix(RecordPackage.eNS_PREFIX);
if (annotation.getName() != null)
{
annotationElement.setAttribute(RecordConstants.ATT_N, annotation.getName());
}
}
if (annotationElement.getParentNode() != parentElement)
{
int index = annotations.indexOf(annotation);
List<Element> elements =
DOMUtils.getChildElements(parentElement, RecordPackage.eNS_URI, RecordConstants.NODE_AN);
Element next;
if (index >= elements.size())
{
// Insert element after the last AN element (before any other)
if (elements.size() == 0)
{
next = DOMUtils.getNextElement(parentElement.getFirstChild());
}
else
{
next = DOMUtils.getNextElement(elements.get(elements.size() - 1).getNextSibling());
}
}
else
{
next = elements.get(index);
}
DOMUtils.insertIndented(parentElement, annotationElement, next);
}
}
else
{
AnnotationValue value = (AnnotationValue) newValue;
Element element = value.getElement();
if (element == null)
{
element =
parentElement.getOwnerDocument().createElementNS(RecordPackage.eNS_URI,
RecordConstants.NODE_V);
value.setElement(element);
element.setPrefix(RecordPackage.eNS_PREFIX);
if (value.getValue() != null)
{
DOMUtils.writeTextContent(element, value.getValue());
}
}
if (element.getParentNode() != parentElement)
{
int index = annotationValues.indexOf(value);
List<Element> elements =
DOMUtils.getChildElements(parentElement, RecordPackage.eNS_URI, RecordConstants.NODE_V);
DOMUtils.insertIndented(parentElement, element,
index >= elements.size() ? null : elements.get(index));
}
}
}
finally
{
setUpdatingDOM(oldUpdatingDom);
}
}
}
else
{
super.adoptContent(eReference, newValue);
}
}
@Override
protected void orphanContent(EReference eReference, Object obj)
{
if (obj instanceof Annotation && !isReconciling())
{
ReconciliationHelper.orphanChild(this, (Annotation) obj);
}
if (obj instanceof AnnotationValue && !isReconciling())
{
ReconciliationHelper.orphanChild(this, (AnnotationValue) obj);
}
super.orphanContent(eReference, obj);
}
} //AnnotationImpl