001    /**
002     * <copyright>
003     * </copyright>
004     *
005     * $Id$
006     */
007    package com.hammurapi.flow.impl;
008    
009    import java.util.Collection;
010    
011    import org.eclipse.emf.common.notify.Notification;
012    import org.eclipse.emf.common.notify.NotificationChain;
013    import org.eclipse.emf.common.util.EList;
014    import org.eclipse.emf.ecore.EClass;
015    import org.eclipse.emf.ecore.InternalEObject;
016    import org.eclipse.emf.ecore.impl.ENotificationImpl;
017    import org.eclipse.emf.ecore.impl.EObjectImpl;
018    import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
019    import org.eclipse.emf.ecore.util.EcoreUtil;
020    import org.eclipse.emf.ecore.util.InternalEList;
021    
022    import com.hammurapi.config.Factory;
023    import com.hammurapi.flow.FlowPackage;
024    import com.hammurapi.flow.Node;
025    import com.hammurapi.flow.Pin;
026    import com.hammurapi.flow.Transition;
027    
028    /**
029     * <!-- begin-user-doc -->
030     * An implementation of the model object '<em><b>Pin</b></em>'.
031     * <!-- end-user-doc -->
032     * <p>
033     * The following features are implemented:
034     * <ul>
035     *   <li>{@link com.hammurapi.flow.impl.PinImpl#getOutput <em>Output</em>}</li>
036     *   <li>{@link com.hammurapi.flow.impl.PinImpl#getInput <em>Input</em>}</li>
037     *   <li>{@link com.hammurapi.flow.impl.PinImpl#getNode <em>Node</em>}</li>
038     *   <li>{@link com.hammurapi.flow.impl.PinImpl#getPinConfig <em>Pin Config</em>}</li>
039     *   <li>{@link com.hammurapi.flow.impl.PinImpl#getName <em>Name</em>}</li>
040     * </ul>
041     * </p>
042     *
043     * @generated
044     */
045    public class PinImpl extends EObjectImpl implements Pin {
046            /**
047             * The cached value of the '{@link #getOutput() <em>Output</em>}' reference list.
048             * <!-- begin-user-doc -->
049             * <!-- end-user-doc -->
050             * @see #getOutput()
051             * @generated
052             * @ordered
053             */
054            protected EList<Transition> output;
055    
056            /**
057             * The cached value of the '{@link #getInput() <em>Input</em>}' reference list.
058             * <!-- begin-user-doc -->
059             * <!-- end-user-doc -->
060             * @see #getInput()
061             * @generated
062             * @ordered
063             */
064            protected EList<Transition> input;
065    
066            /**
067             * The cached value of the '{@link #getPinConfig() <em>Pin Config</em>}' containment reference.
068             * <!-- begin-user-doc -->
069             * <!-- end-user-doc -->
070             * @see #getPinConfig()
071             * @generated
072             * @ordered
073             */
074            protected Factory pinConfig;
075    
076            /**
077             * The default value of the '{@link #getName() <em>Name</em>}' attribute.
078             * <!-- begin-user-doc -->
079             * <!-- end-user-doc -->
080             * @see #getName()
081             * @generated
082             * @ordered
083             */
084            protected static final String NAME_EDEFAULT = null;
085    
086            /**
087             * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
088             * <!-- begin-user-doc -->
089             * <!-- end-user-doc -->
090             * @see #getName()
091             * @generated
092             * @ordered
093             */
094            protected String name = NAME_EDEFAULT;
095    
096            /**
097             * <!-- begin-user-doc -->
098             * <!-- end-user-doc -->
099             * @generated
100             */
101            protected PinImpl() {
102                    super();
103            }
104    
105            /**
106             * <!-- begin-user-doc -->
107             * <!-- end-user-doc -->
108             * @generated
109             */
110            @Override
111            protected EClass eStaticClass() {
112                    return FlowPackage.Literals.PIN;
113            }
114    
115            /**
116             * <!-- begin-user-doc -->
117             * <!-- end-user-doc -->
118             * @generated
119             */
120            public String getName() {
121                    return name;
122            }
123    
124            /**
125             * <!-- begin-user-doc -->
126             * <!-- end-user-doc -->
127             * @generated
128             */
129            public void setName(String newName) {
130                    String oldName = name;
131                    name = newName;
132                    if (eNotificationRequired())
133                            eNotify(new ENotificationImpl(this, Notification.SET, FlowPackage.PIN__NAME, oldName, name));
134            }
135    
136            /**
137             * <!-- begin-user-doc -->
138             * <!-- end-user-doc -->
139             * @generated
140             */
141            public Factory getPinConfig() {
142                    return pinConfig;
143            }
144    
145            /**
146             * <!-- begin-user-doc -->
147             * <!-- end-user-doc -->
148             * @generated
149             */
150            public NotificationChain basicSetPinConfig(Factory newPinConfig, NotificationChain msgs) {
151                    Factory oldPinConfig = pinConfig;
152                    pinConfig = newPinConfig;
153                    if (eNotificationRequired()) {
154                            ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FlowPackage.PIN__PIN_CONFIG, oldPinConfig, newPinConfig);
155                            if (msgs == null) msgs = notification; else msgs.add(notification);
156                    }
157                    return msgs;
158            }
159    
160            /**
161             * <!-- begin-user-doc -->
162             * <!-- end-user-doc -->
163             * @generated
164             */
165            public void setPinConfig(Factory newPinConfig) {
166                    if (newPinConfig != pinConfig) {
167                            NotificationChain msgs = null;
168                            if (pinConfig != null)
169                                    msgs = ((InternalEObject)pinConfig).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FlowPackage.PIN__PIN_CONFIG, null, msgs);
170                            if (newPinConfig != null)
171                                    msgs = ((InternalEObject)newPinConfig).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FlowPackage.PIN__PIN_CONFIG, null, msgs);
172                            msgs = basicSetPinConfig(newPinConfig, msgs);
173                            if (msgs != null) msgs.dispatch();
174                    }
175                    else if (eNotificationRequired())
176                            eNotify(new ENotificationImpl(this, Notification.SET, FlowPackage.PIN__PIN_CONFIG, newPinConfig, newPinConfig));
177            }
178    
179            /**
180             * <!-- begin-user-doc -->
181             * <!-- end-user-doc -->
182             * @generated
183             */
184            public EList<Transition> getOutput() {
185                    if (output == null) {
186                            output = new EObjectWithInverseResolvingEList<Transition>(Transition.class, this, FlowPackage.PIN__OUTPUT, FlowPackage.TRANSITION__FROM_PIN);
187                    }
188                    return output;
189            }
190    
191            /**
192             * <!-- begin-user-doc -->
193             * <!-- end-user-doc -->
194             * @generated
195             */
196            public EList<Transition> getInput() {
197                    if (input == null) {
198                            input = new EObjectWithInverseResolvingEList<Transition>(Transition.class, this, FlowPackage.PIN__INPUT, FlowPackage.TRANSITION__TO_PIN);
199                    }
200                    return input;
201            }
202    
203            /**
204             * <!-- begin-user-doc -->
205             * <!-- end-user-doc -->
206             * @generated
207             */
208            public Node getNode() {
209                    if (eContainerFeatureID() != FlowPackage.PIN__NODE) return null;
210                    return (Node)eContainer();
211            }
212    
213            /**
214             * <!-- begin-user-doc -->
215             * <!-- end-user-doc -->
216             * @generated
217             */
218            public NotificationChain basicSetNode(Node newNode, NotificationChain msgs) {
219                    msgs = eBasicSetContainer((InternalEObject)newNode, FlowPackage.PIN__NODE, msgs);
220                    return msgs;
221            }
222    
223            /**
224             * <!-- begin-user-doc -->
225             * <!-- end-user-doc -->
226             * @generated
227             */
228            public void setNode(Node newNode) {
229                    if (newNode != eInternalContainer() || (eContainerFeatureID() != FlowPackage.PIN__NODE && newNode != null)) {
230                            if (EcoreUtil.isAncestor(this, newNode))
231                                    throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
232                            NotificationChain msgs = null;
233                            if (eInternalContainer() != null)
234                                    msgs = eBasicRemoveFromContainer(msgs);
235                            if (newNode != null)
236                                    msgs = ((InternalEObject)newNode).eInverseAdd(this, FlowPackage.NODE__PIN, Node.class, msgs);
237                            msgs = basicSetNode(newNode, msgs);
238                            if (msgs != null) msgs.dispatch();
239                    }
240                    else if (eNotificationRequired())
241                            eNotify(new ENotificationImpl(this, Notification.SET, FlowPackage.PIN__NODE, newNode, newNode));
242            }
243    
244            /**
245             * <!-- begin-user-doc -->
246             * <!-- end-user-doc -->
247             * @generated
248             */
249            @SuppressWarnings("unchecked")
250            @Override
251            public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
252                    switch (featureID) {
253                            case FlowPackage.PIN__OUTPUT:
254                                    return ((InternalEList<InternalEObject>)(InternalEList<?>)getOutput()).basicAdd(otherEnd, msgs);
255                            case FlowPackage.PIN__INPUT:
256                                    return ((InternalEList<InternalEObject>)(InternalEList<?>)getInput()).basicAdd(otherEnd, msgs);
257                            case FlowPackage.PIN__NODE:
258                                    if (eInternalContainer() != null)
259                                            msgs = eBasicRemoveFromContainer(msgs);
260                                    return basicSetNode((Node)otherEnd, msgs);
261                    }
262                    return super.eInverseAdd(otherEnd, featureID, msgs);
263            }
264    
265            /**
266             * <!-- begin-user-doc -->
267             * <!-- end-user-doc -->
268             * @generated
269             */
270            @Override
271            public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
272                    switch (featureID) {
273                            case FlowPackage.PIN__OUTPUT:
274                                    return ((InternalEList<?>)getOutput()).basicRemove(otherEnd, msgs);
275                            case FlowPackage.PIN__INPUT:
276                                    return ((InternalEList<?>)getInput()).basicRemove(otherEnd, msgs);
277                            case FlowPackage.PIN__NODE:
278                                    return basicSetNode(null, msgs);
279                            case FlowPackage.PIN__PIN_CONFIG:
280                                    return basicSetPinConfig(null, msgs);
281                    }
282                    return super.eInverseRemove(otherEnd, featureID, msgs);
283            }
284    
285            /**
286             * <!-- begin-user-doc -->
287             * <!-- end-user-doc -->
288             * @generated
289             */
290            @Override
291            public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
292                    switch (eContainerFeatureID()) {
293                            case FlowPackage.PIN__NODE:
294                                    return eInternalContainer().eInverseRemove(this, FlowPackage.NODE__PIN, Node.class, msgs);
295                    }
296                    return super.eBasicRemoveFromContainerFeature(msgs);
297            }
298    
299            /**
300             * <!-- begin-user-doc -->
301             * <!-- end-user-doc -->
302             * @generated
303             */
304            @Override
305            public Object eGet(int featureID, boolean resolve, boolean coreType) {
306                    switch (featureID) {
307                            case FlowPackage.PIN__OUTPUT:
308                                    return getOutput();
309                            case FlowPackage.PIN__INPUT:
310                                    return getInput();
311                            case FlowPackage.PIN__NODE:
312                                    return getNode();
313                            case FlowPackage.PIN__PIN_CONFIG:
314                                    return getPinConfig();
315                            case FlowPackage.PIN__NAME:
316                                    return getName();
317                    }
318                    return super.eGet(featureID, resolve, coreType);
319            }
320    
321            /**
322             * <!-- begin-user-doc -->
323             * <!-- end-user-doc -->
324             * @generated
325             */
326            @SuppressWarnings("unchecked")
327            @Override
328            public void eSet(int featureID, Object newValue) {
329                    switch (featureID) {
330                            case FlowPackage.PIN__OUTPUT:
331                                    getOutput().clear();
332                                    getOutput().addAll((Collection<? extends Transition>)newValue);
333                                    return;
334                            case FlowPackage.PIN__INPUT:
335                                    getInput().clear();
336                                    getInput().addAll((Collection<? extends Transition>)newValue);
337                                    return;
338                            case FlowPackage.PIN__NODE:
339                                    setNode((Node)newValue);
340                                    return;
341                            case FlowPackage.PIN__PIN_CONFIG:
342                                    setPinConfig((Factory)newValue);
343                                    return;
344                            case FlowPackage.PIN__NAME:
345                                    setName((String)newValue);
346                                    return;
347                    }
348                    super.eSet(featureID, newValue);
349            }
350    
351            /**
352             * <!-- begin-user-doc -->
353             * <!-- end-user-doc -->
354             * @generated
355             */
356            @Override
357            public void eUnset(int featureID) {
358                    switch (featureID) {
359                            case FlowPackage.PIN__OUTPUT:
360                                    getOutput().clear();
361                                    return;
362                            case FlowPackage.PIN__INPUT:
363                                    getInput().clear();
364                                    return;
365                            case FlowPackage.PIN__NODE:
366                                    setNode((Node)null);
367                                    return;
368                            case FlowPackage.PIN__PIN_CONFIG:
369                                    setPinConfig((Factory)null);
370                                    return;
371                            case FlowPackage.PIN__NAME:
372                                    setName(NAME_EDEFAULT);
373                                    return;
374                    }
375                    super.eUnset(featureID);
376            }
377    
378            /**
379             * <!-- begin-user-doc -->
380             * <!-- end-user-doc -->
381             * @generated
382             */
383            @Override
384            public boolean eIsSet(int featureID) {
385                    switch (featureID) {
386                            case FlowPackage.PIN__OUTPUT:
387                                    return output != null && !output.isEmpty();
388                            case FlowPackage.PIN__INPUT:
389                                    return input != null && !input.isEmpty();
390                            case FlowPackage.PIN__NODE:
391                                    return getNode() != null;
392                            case FlowPackage.PIN__PIN_CONFIG:
393                                    return pinConfig != null;
394                            case FlowPackage.PIN__NAME:
395                                    return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
396                    }
397                    return super.eIsSet(featureID);
398            }
399    
400            /**
401             * <!-- begin-user-doc -->
402             * <!-- end-user-doc -->
403             * @generated
404             */
405            @Override
406            public String toString() {
407                    if (eIsProxy()) return super.toString();
408    
409                    StringBuffer result = new StringBuffer(super.toString());
410                    result.append(" (name: ");
411                    result.append(name);
412                    result.append(')');
413                    return result.toString();
414            }
415    
416    } //PinImpl