/*
* Copyright (c) 2009, IETR/INSA of Rennes
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the IETR/INSA of Rennes nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
package net.sf.orcc.df.impl;
import net.sf.orcc.df.Connection;
import net.sf.orcc.df.DfPackage;
import net.sf.orcc.df.Port;
import net.sf.orcc.graph.impl.EdgeImpl;
import net.sf.orcc.ir.Expression;
import net.sf.orcc.ir.IrFactory;
import net.sf.orcc.ir.util.ExpressionEvaluator;
import net.sf.orcc.util.Attribute;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
/**
* This class represents a connection in a network. A connection can have a
* number of attributes, that can be types or expressions.
*
* @author Matthieu Wipliez
* @author Herve Yviquel
* @generated
*/
public class ConnectionImpl extends EdgeImpl implements Connection {
/**
* the bufferSize attribute can be attached to a FIFO to specify its size
*/
protected static final String BUFFER_SIZE = "bufferSize";
/**
* The cached value of the '{@link #getSourcePort() <em>Source Port</em>}' reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getSourcePort()
* @generated
* @ordered
*/
protected Port sourcePort;
/**
* The cached value of the '{@link #getTargetPort() <em>Target Port</em>}' reference.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @see #getTargetPort()
* @generated
* @ordered
*/
protected Port targetPort;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected ConnectionImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Port basicGetSourcePort() {
return sourcePort;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Port basicGetTargetPort() {
return targetPort;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case DfPackage.CONNECTION__SOURCE_PORT:
if (resolve)
return getSourcePort();
return basicGetSourcePort();
case DfPackage.CONNECTION__TARGET_PORT:
if (resolve)
return getTargetPort();
return basicGetTargetPort();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case DfPackage.CONNECTION__SOURCE_PORT:
return sourcePort != null;
case DfPackage.CONNECTION__TARGET_PORT:
return targetPort != null;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case DfPackage.CONNECTION__SOURCE_PORT:
setSourcePort((Port) newValue);
return;
case DfPackage.CONNECTION__TARGET_PORT:
setTargetPort((Port) newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return DfPackage.Literals.CONNECTION;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case DfPackage.CONNECTION__SOURCE_PORT:
setSourcePort((Port) null);
return;
case DfPackage.CONNECTION__TARGET_PORT:
setTargetPort((Port) null);
return;
}
super.eUnset(featureID);
}
@Override
public Integer getSize() {
Attribute attr = getAttribute(BUFFER_SIZE);
if (attr != null) {
if (attr.getContainedValue() instanceof Expression) {
Expression expr = (Expression) attr.getContainedValue();
return new ExpressionEvaluator().evaluateAsInteger(expr);
} else if (attr.getObjectValue() instanceof Integer) {
return (Integer) attr.getObjectValue();
}
}
return null;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Port getSourcePort() {
if (sourcePort != null && sourcePort.eIsProxy()) {
InternalEObject oldSourcePort = (InternalEObject) sourcePort;
sourcePort = (Port) eResolveProxy(oldSourcePort);
if (sourcePort != oldSourcePort) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE,
DfPackage.CONNECTION__SOURCE_PORT, oldSourcePort,
sourcePort));
}
}
return sourcePort;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public Port getTargetPort() {
if (targetPort != null && targetPort.eIsProxy()) {
InternalEObject oldTargetPort = (InternalEObject) targetPort;
targetPort = (Port) eResolveProxy(oldTargetPort);
if (targetPort != oldTargetPort) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE,
DfPackage.CONNECTION__TARGET_PORT, oldTargetPort,
targetPort));
}
}
return targetPort;
}
@Override
public void setSize(Integer size) {
if (size != null) {
setAttribute(BUFFER_SIZE, IrFactory.eINSTANCE.createExprInt(size));
}
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setSourcePort(Port newSourcePort) {
Port oldSourcePort = sourcePort;
sourcePort = newSourcePort;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
DfPackage.CONNECTION__SOURCE_PORT, oldSourcePort,
sourcePort));
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setTargetPort(Port newTargetPort) {
Port oldTargetPort = targetPort;
targetPort = newTargetPort;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET,
DfPackage.CONNECTION__TARGET_PORT, oldTargetPort,
targetPort));
}
@Override
public void unsetSize() {
removeAttribute(BUFFER_SIZE);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getSource().getLabel());
if (getSourcePort() != null) {
builder.append('.');
builder.append(getSourcePort().getName());
}
builder.append(" --> ");
builder.append(getTarget().getLabel());
if (getTargetPort() != null) {
builder.append('.');
builder.append(getTargetPort().getName());
}
return builder.toString();
}
}