KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > EReferenceImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: EReferenceImpl.java,v 1.5 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.notify.Notification;
23 import org.eclipse.emf.common.notify.NotificationChain;
24 import org.eclipse.emf.ecore.EClass;
25 import org.eclipse.emf.ecore.EClassifier;
26 import org.eclipse.emf.ecore.EReference;
27 import org.eclipse.emf.ecore.EStructuralFeature;
28 import org.eclipse.emf.ecore.EcorePackage;
29 import org.eclipse.emf.ecore.InternalEObject;
30 import org.eclipse.emf.ecore.util.InternalEList;
31
32
33 /**
34  * <!-- begin-user-doc -->
35  * An implementation of the model object '<em><b>EReference</b></em>'.
36  * <!-- end-user-doc -->
37  * <p>
38  * The following features are implemented:
39  * <ul>
40  * <li>{@link org.eclipse.emf.ecore.impl.EReferenceImpl#isContainment <em>Containment</em>}</li>
41  * <li>{@link org.eclipse.emf.ecore.impl.EReferenceImpl#isContainer <em>Container</em>}</li>
42  * <li>{@link org.eclipse.emf.ecore.impl.EReferenceImpl#isResolveProxies <em>Resolve Proxies</em>}</li>
43  * <li>{@link org.eclipse.emf.ecore.impl.EReferenceImpl#getEOpposite <em>EOpposite</em>}</li>
44  * <li>{@link org.eclipse.emf.ecore.impl.EReferenceImpl#getEReferenceType <em>EReference Type</em>}</li>
45  * </ul>
46  * </p>
47  *
48  * @generated
49  */

50 public class EReferenceImpl extends EStructuralFeatureImpl implements EReference
51 {
52   /**
53    * The default value of the '{@link #isContainment() <em>Containment</em>}' attribute.
54    * <!-- begin-user-doc -->
55    * <!-- end-user-doc -->
56    * @see #isContainment()
57    * @generated
58    * @ordered
59    */

60   protected static final boolean CONTAINMENT_EDEFAULT = false;
61
62   /**
63    * The flag representing the value of the '{@link #isContainment() <em>Containment</em>}' attribute.
64    * <!-- begin-user-doc -->
65    * <!-- end-user-doc -->
66    * @see #isContainment()
67    * @generated
68    * @ordered
69    */

70   protected static final int CONTAINMENT_EFLAG = 1 << 15;
71
72   /**
73    * The default value of the '{@link #isContainer() <em>Container</em>}' attribute.
74    * <!-- begin-user-doc -->
75    * <!-- end-user-doc -->
76    * @see #isContainer()
77    * @generated
78    * @ordered
79    */

80   protected static final boolean CONTAINER_EDEFAULT = false;
81
82   /**
83    * The default value of the '{@link #isResolveProxies() <em>Resolve Proxies</em>}' attribute.
84    * <!-- begin-user-doc -->
85    * <!-- end-user-doc -->
86    * @see #isResolveProxies()
87    * @generated
88    * @ordered
89    */

90   protected static final boolean RESOLVE_PROXIES_EDEFAULT = true;
91
92   /**
93    * The flag representing the value of the '{@link #isResolveProxies() <em>Resolve Proxies</em>}' attribute.
94    * <!-- begin-user-doc -->
95    * <!-- end-user-doc -->
96    * @see #isResolveProxies()
97    * @generated
98    * @ordered
99    */

100   protected static final int RESOLVE_PROXIES_EFLAG = 1 << 16;
101
102   /**
103    * The cached value of the '{@link #getEOpposite() <em>EOpposite</em>}' reference.
104    * <!-- begin-user-doc -->
105    * <!-- end-user-doc -->
106    * @see #getEOpposite()
107    * @generated
108    * @ordered
109    */

110   protected EReference eOpposite = null;
111
112   /**
113    * <!-- begin-user-doc -->
114    * <!-- end-user-doc -->
115    * @generated
116    */

117   protected EReferenceImpl()
118   {
119     super();
120     eFlags |= RESOLVE_PROXIES_EFLAG;
121   }
122
123   /**
124    * <!-- begin-user-doc -->
125    * <!-- end-user-doc -->
126    * @generated
127    */

128   protected EClass eStaticClass()
129   {
130     return EcorePackage.eINSTANCE.getEReference();
131   }
132
133   public boolean isBidirectional()
134   {
135     return getEOpposite() != null;
136   }
137
138
139   /**
140    * <!-- begin-user-doc -->
141    * <!-- end-user-doc -->
142    * @generated
143    */

144   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
145   {
146     switch (eDerivedStructuralFeatureID(eFeature))
147     {
148       case EcorePackage.EREFERENCE__EANNOTATIONS:
149         return getEAnnotations();
150       case EcorePackage.EREFERENCE__NAME:
151         return getName();
152       case EcorePackage.EREFERENCE__ORDERED:
153         return isOrdered() ? Boolean.TRUE : Boolean.FALSE;
154       case EcorePackage.EREFERENCE__UNIQUE:
155         return isUnique() ? Boolean.TRUE : Boolean.FALSE;
156       case EcorePackage.EREFERENCE__LOWER_BOUND:
157         return new Integer JavaDoc(getLowerBound());
158       case EcorePackage.EREFERENCE__UPPER_BOUND:
159         return new Integer JavaDoc(getUpperBound());
160       case EcorePackage.EREFERENCE__MANY:
161         return isMany() ? Boolean.TRUE : Boolean.FALSE;
162       case EcorePackage.EREFERENCE__REQUIRED:
163         return isRequired() ? Boolean.TRUE : Boolean.FALSE;
164       case EcorePackage.EREFERENCE__ETYPE:
165         if (resolve) return getEType();
166         return basicGetEType();
167       case EcorePackage.EREFERENCE__CHANGEABLE:
168         return isChangeable() ? Boolean.TRUE : Boolean.FALSE;
169       case EcorePackage.EREFERENCE__VOLATILE:
170         return isVolatile() ? Boolean.TRUE : Boolean.FALSE;
171       case EcorePackage.EREFERENCE__TRANSIENT:
172         return isTransient() ? Boolean.TRUE : Boolean.FALSE;
173       case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL:
174         return getDefaultValueLiteral();
175       case EcorePackage.EREFERENCE__DEFAULT_VALUE:
176         return getDefaultValue();
177       case EcorePackage.EREFERENCE__UNSETTABLE:
178         return isUnsettable() ? Boolean.TRUE : Boolean.FALSE;
179       case EcorePackage.EREFERENCE__DERIVED:
180         return isDerived() ? Boolean.TRUE : Boolean.FALSE;
181       case EcorePackage.EREFERENCE__ECONTAINING_CLASS:
182         return getEContainingClass();
183       case EcorePackage.EREFERENCE__CONTAINMENT:
184         return isContainment() ? Boolean.TRUE : Boolean.FALSE;
185       case EcorePackage.EREFERENCE__CONTAINER:
186         return isContainer() ? Boolean.TRUE : Boolean.FALSE;
187       case EcorePackage.EREFERENCE__RESOLVE_PROXIES:
188         return isResolveProxies() ? Boolean.TRUE : Boolean.FALSE;
189       case EcorePackage.EREFERENCE__EOPPOSITE:
190         if (resolve) return getEOpposite();
191         return basicGetEOpposite();
192       case EcorePackage.EREFERENCE__EREFERENCE_TYPE:
193         if (resolve) return getEReferenceType();
194         return basicGetEReferenceType();
195     }
196     return eDynamicGet(eFeature, resolve);
197   }
198
199   /**
200    * <!-- begin-user-doc -->
201    * <!-- end-user-doc -->
202    * @generated
203    */

204   public boolean eIsSet(EStructuralFeature eFeature)
205   {
206     switch (eDerivedStructuralFeatureID(eFeature))
207     {
208       case EcorePackage.EREFERENCE__EANNOTATIONS:
209         return eAnnotations != null && !eAnnotations.isEmpty();
210       case EcorePackage.EREFERENCE__NAME:
211         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
212       case EcorePackage.EREFERENCE__ORDERED:
213         return ((eFlags & ORDERED_EFLAG) != 0) != ORDERED_EDEFAULT;
214       case EcorePackage.EREFERENCE__UNIQUE:
215         return ((eFlags & UNIQUE_EFLAG) != 0) != UNIQUE_EDEFAULT;
216       case EcorePackage.EREFERENCE__LOWER_BOUND:
217         return lowerBound != LOWER_BOUND_EDEFAULT;
218       case EcorePackage.EREFERENCE__UPPER_BOUND:
219         return upperBound != UPPER_BOUND_EDEFAULT;
220       case EcorePackage.EREFERENCE__MANY:
221         return isMany() != MANY_EDEFAULT;
222       case EcorePackage.EREFERENCE__REQUIRED:
223         return isRequired() != REQUIRED_EDEFAULT;
224       case EcorePackage.EREFERENCE__ETYPE:
225         return eType != null;
226       case EcorePackage.EREFERENCE__CHANGEABLE:
227         return ((eFlags & CHANGEABLE_EFLAG) != 0) != CHANGEABLE_EDEFAULT;
228       case EcorePackage.EREFERENCE__VOLATILE:
229         return ((eFlags & VOLATILE_EFLAG) != 0) != VOLATILE_EDEFAULT;
230       case EcorePackage.EREFERENCE__TRANSIENT:
231         return ((eFlags & TRANSIENT_EFLAG) != 0) != TRANSIENT_EDEFAULT;
232       case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL:
233         return DEFAULT_VALUE_LITERAL_EDEFAULT == null ? defaultValueLiteral != null : !DEFAULT_VALUE_LITERAL_EDEFAULT.equals(defaultValueLiteral);
234       case EcorePackage.EREFERENCE__DEFAULT_VALUE:
235         return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue());
236       case EcorePackage.EREFERENCE__UNSETTABLE:
237         return ((eFlags & UNSETTABLE_EFLAG) != 0) != UNSETTABLE_EDEFAULT;
238       case EcorePackage.EREFERENCE__DERIVED:
239         return ((eFlags & DERIVED_EFLAG) != 0) != DERIVED_EDEFAULT;
240       case EcorePackage.EREFERENCE__ECONTAINING_CLASS:
241         return getEContainingClass() != null;
242       case EcorePackage.EREFERENCE__CONTAINMENT:
243         return ((eFlags & CONTAINMENT_EFLAG) != 0) != CONTAINMENT_EDEFAULT;
244       case EcorePackage.EREFERENCE__CONTAINER:
245         return isContainer() != CONTAINER_EDEFAULT;
246       case EcorePackage.EREFERENCE__RESOLVE_PROXIES:
247         return ((eFlags & RESOLVE_PROXIES_EFLAG) != 0) != RESOLVE_PROXIES_EDEFAULT;
248       case EcorePackage.EREFERENCE__EOPPOSITE:
249         return eOpposite != null;
250       case EcorePackage.EREFERENCE__EREFERENCE_TYPE:
251         return basicGetEReferenceType() != null;
252     }
253     return eDynamicIsSet(eFeature);
254   }
255
256   /**
257    * <!-- begin-user-doc -->
258    * <!-- end-user-doc -->
259    * @generated
260    */

261   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
262   {
263     switch (eDerivedStructuralFeatureID(eFeature))
264     {
265       case EcorePackage.EREFERENCE__EANNOTATIONS:
266         getEAnnotations().clear();
267         getEAnnotations().addAll((Collection JavaDoc)newValue);
268         return;
269       case EcorePackage.EREFERENCE__NAME:
270         setName((String JavaDoc)newValue);
271         return;
272       case EcorePackage.EREFERENCE__ORDERED:
273         setOrdered(((Boolean JavaDoc)newValue).booleanValue());
274         return;
275       case EcorePackage.EREFERENCE__UNIQUE:
276         setUnique(((Boolean JavaDoc)newValue).booleanValue());
277         return;
278       case EcorePackage.EREFERENCE__LOWER_BOUND:
279         setLowerBound(((Integer JavaDoc)newValue).intValue());
280         return;
281       case EcorePackage.EREFERENCE__UPPER_BOUND:
282         setUpperBound(((Integer JavaDoc)newValue).intValue());
283         return;
284       case EcorePackage.EREFERENCE__ETYPE:
285         setEType((EClassifier)newValue);
286         return;
287       case EcorePackage.EREFERENCE__CHANGEABLE:
288         setChangeable(((Boolean JavaDoc)newValue).booleanValue());
289         return;
290       case EcorePackage.EREFERENCE__VOLATILE:
291         setVolatile(((Boolean JavaDoc)newValue).booleanValue());
292         return;
293       case EcorePackage.EREFERENCE__TRANSIENT:
294         setTransient(((Boolean JavaDoc)newValue).booleanValue());
295         return;
296       case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL:
297         setDefaultValueLiteral((String JavaDoc)newValue);
298         return;
299       case EcorePackage.EREFERENCE__UNSETTABLE:
300         setUnsettable(((Boolean JavaDoc)newValue).booleanValue());
301         return;
302       case EcorePackage.EREFERENCE__DERIVED:
303         setDerived(((Boolean JavaDoc)newValue).booleanValue());
304         return;
305       case EcorePackage.EREFERENCE__CONTAINMENT:
306         setContainment(((Boolean JavaDoc)newValue).booleanValue());
307         return;
308       case EcorePackage.EREFERENCE__RESOLVE_PROXIES:
309         setResolveProxies(((Boolean JavaDoc)newValue).booleanValue());
310         return;
311       case EcorePackage.EREFERENCE__EOPPOSITE:
312         setEOpposite((EReference)newValue);
313         return;
314     }
315     eDynamicSet(eFeature, newValue);
316   }
317
318   /**
319    * <!-- begin-user-doc -->
320    * <!-- end-user-doc -->
321    * @generated
322    */

323   public void eUnset(EStructuralFeature eFeature)
324   {
325     switch (eDerivedStructuralFeatureID(eFeature))
326     {
327       case EcorePackage.EREFERENCE__EANNOTATIONS:
328         getEAnnotations().clear();
329         return;
330       case EcorePackage.EREFERENCE__NAME:
331         setName(NAME_EDEFAULT);
332         return;
333       case EcorePackage.EREFERENCE__ORDERED:
334         setOrdered(ORDERED_EDEFAULT);
335         return;
336       case EcorePackage.EREFERENCE__UNIQUE:
337         setUnique(UNIQUE_EDEFAULT);
338         return;
339       case EcorePackage.EREFERENCE__LOWER_BOUND:
340         setLowerBound(LOWER_BOUND_EDEFAULT);
341         return;
342       case EcorePackage.EREFERENCE__UPPER_BOUND:
343         setUpperBound(UPPER_BOUND_EDEFAULT);
344         return;
345       case EcorePackage.EREFERENCE__ETYPE:
346         setEType((EClassifier)null);
347         return;
348       case EcorePackage.EREFERENCE__CHANGEABLE:
349         setChangeable(CHANGEABLE_EDEFAULT);
350         return;
351       case EcorePackage.EREFERENCE__VOLATILE:
352         setVolatile(VOLATILE_EDEFAULT);
353         return;
354       case EcorePackage.EREFERENCE__TRANSIENT:
355         setTransient(TRANSIENT_EDEFAULT);
356         return;
357       case EcorePackage.EREFERENCE__DEFAULT_VALUE_LITERAL:
358         setDefaultValueLiteral(DEFAULT_VALUE_LITERAL_EDEFAULT);
359         return;
360       case EcorePackage.EREFERENCE__UNSETTABLE:
361         setUnsettable(UNSETTABLE_EDEFAULT);
362         return;
363       case EcorePackage.EREFERENCE__DERIVED:
364         setDerived(DERIVED_EDEFAULT);
365         return;
366       case EcorePackage.EREFERENCE__CONTAINMENT:
367         setContainment(CONTAINMENT_EDEFAULT);
368         return;
369       case EcorePackage.EREFERENCE__RESOLVE_PROXIES:
370         setResolveProxies(RESOLVE_PROXIES_EDEFAULT);
371         return;
372       case EcorePackage.EREFERENCE__EOPPOSITE:
373         setEOpposite((EReference)null);
374         return;
375     }
376     eDynamicUnset(eFeature);
377   }
378
379   /**
380    * <!-- begin-user-doc -->
381    * <!-- end-user-doc -->
382    * @generated
383    */

384   public boolean isContainment()
385   {
386     return (eFlags & CONTAINMENT_EFLAG) != 0;
387   }
388
389   /**
390    * <!-- begin-user-doc -->
391    * <!-- end-user-doc -->
392    * @generated
393    */

394   public void setContainment(boolean newContainment)
395   {
396     boolean oldContainment = (eFlags & CONTAINMENT_EFLAG) != 0;
397     if (newContainment) eFlags |= CONTAINMENT_EFLAG; else eFlags &= ~CONTAINMENT_EFLAG;
398     if (eNotificationRequired())
399       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__CONTAINMENT, oldContainment, newContainment));
400   }
401
402   /**
403    * <!-- begin-user-doc -->
404    * <!-- end-user-doc -->
405    * @generated modifiable
406    */

407   public boolean isContainer()
408   {
409     EReference theOpposite = getEOpposite();
410     return theOpposite != null && theOpposite.isContainment();
411   }
412
413   /**
414    * <!-- begin-user-doc -->
415    * <!-- end-user-doc -->
416    * @generated
417    */

418   public boolean isResolveProxies()
419   {
420     return (eFlags & RESOLVE_PROXIES_EFLAG) != 0;
421   }
422
423   /**
424    * <!-- begin-user-doc -->
425    * <!-- end-user-doc -->
426    * @generated
427    */

428   public void setResolveProxies(boolean newResolveProxies)
429   {
430     boolean oldResolveProxies = (eFlags & RESOLVE_PROXIES_EFLAG) != 0;
431     if (newResolveProxies) eFlags |= RESOLVE_PROXIES_EFLAG; else eFlags &= ~RESOLVE_PROXIES_EFLAG;
432     if (eNotificationRequired())
433       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__RESOLVE_PROXIES, oldResolveProxies, newResolveProxies));
434   }
435
436   /**
437    * <!-- begin-user-doc -->
438    * <!-- end-user-doc -->
439    * @generated
440    */

441   public EReference getEOpposite()
442   {
443     if (eOpposite != null && eOpposite.eIsProxy())
444     {
445       EReference oldEOpposite = eOpposite;
446       eOpposite = (EReference)eResolveProxy((InternalEObject)eOpposite);
447       if (eOpposite != oldEOpposite)
448       {
449         if (eNotificationRequired())
450           eNotify(new ENotificationImpl(this, Notification.RESOLVE, EcorePackage.EREFERENCE__EOPPOSITE, oldEOpposite, eOpposite));
451       }
452     }
453     return eOpposite;
454   }
455
456   /**
457    * <!-- begin-user-doc -->
458    * <!-- end-user-doc -->
459    * @generated
460    */

461   public EReference basicGetEOpposite()
462   {
463     return eOpposite;
464   }
465
466   /**
467    * <!-- begin-user-doc -->
468    * <!-- end-user-doc -->
469    * @generated
470    */

471   public void setEOpposite(EReference newEOpposite)
472   {
473     EReference oldEOpposite = eOpposite;
474     eOpposite = newEOpposite;
475     if (eNotificationRequired())
476       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EREFERENCE__EOPPOSITE, oldEOpposite, eOpposite));
477   }
478
479   /**
480    * <!-- begin-user-doc -->
481    * <!-- end-user-doc -->
482    * @generated modifiable
483    */

484   public EClass getEReferenceType()
485   {
486     return (EClass)getEType();
487   }
488
489   /**
490    * <!-- begin-user-doc -->
491    * <!-- end-user-doc -->
492    * @generated modifiable
493    */

494   public EClass basicGetEReferenceType()
495   {
496     return (EClass)eType;
497   }
498
499   /**
500    * <!-- begin-user-doc -->
501    * <!-- end-user-doc -->
502    * @generated
503    */

504   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
505   {
506     if (featureID >= 0)
507     {
508       switch (eDerivedStructuralFeatureID(featureID, baseClass))
509       {
510         case EcorePackage.EREFERENCE__EANNOTATIONS:
511           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
512         case EcorePackage.EREFERENCE__ECONTAINING_CLASS:
513           if (eContainer != null)
514             msgs = eBasicRemoveFromContainer(msgs);
515           return eBasicSetContainer(otherEnd, EcorePackage.EREFERENCE__ECONTAINING_CLASS, msgs);
516         default:
517           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
518       }
519     }
520     if (eContainer != null)
521       msgs = eBasicRemoveFromContainer(msgs);
522     return eBasicSetContainer(otherEnd, featureID, msgs);
523   }
524
525   /**
526    * <!-- begin-user-doc -->
527    * <!-- end-user-doc -->
528    * @generated
529    */

530   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
531   {
532     if (featureID >= 0)
533     {
534       switch (eDerivedStructuralFeatureID(featureID, baseClass))
535       {
536         case EcorePackage.EREFERENCE__EANNOTATIONS:
537           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
538         case EcorePackage.EREFERENCE__ECONTAINING_CLASS:
539           return eBasicSetContainer(null, EcorePackage.EREFERENCE__ECONTAINING_CLASS, msgs);
540         default:
541           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
542       }
543     }
544     return eBasicSetContainer(null, featureID, msgs);
545   }
546
547   /**
548    * <!-- begin-user-doc -->
549    * <!-- end-user-doc -->
550    * @generated
551    */

552   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
553   {
554     if (eContainerFeatureID >= 0)
555     {
556       switch (eContainerFeatureID)
557       {
558         case EcorePackage.EREFERENCE__ECONTAINING_CLASS:
559           return eContainer.eInverseRemove(this, EcorePackage.ECLASS__ESTRUCTURAL_FEATURES, EClass.class, msgs);
560         default:
561           return eDynamicBasicRemoveFromContainer(msgs);
562       }
563     }
564     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
565   }
566
567   /**
568    * <!-- begin-user-doc -->
569    * <!-- end-user-doc -->
570    * @generated
571    */

572   public String JavaDoc toString()
573   {
574     if (eIsProxy()) return super.toString();
575
576     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
577     result.append(" (containment: ");
578     result.append((eFlags & CONTAINMENT_EFLAG) != 0);
579     result.append(", resolveProxies: ");
580     result.append((eFlags & RESOLVE_PROXIES_EFLAG) != 0);
581     result.append(')');
582     return result.toString();
583   }
584
585 }
586
Popular Tags