KickJava   Java API By Example, From Geeks To Geeks.

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


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: EAttributeImpl.java,v 1.6 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.EAttribute;
25 import org.eclipse.emf.ecore.EClass;
26 import org.eclipse.emf.ecore.EClassifier;
27 import org.eclipse.emf.ecore.EDataType;
28 import org.eclipse.emf.ecore.EStructuralFeature;
29 import org.eclipse.emf.ecore.EcorePackage;
30 import org.eclipse.emf.ecore.InternalEObject;
31 import org.eclipse.emf.ecore.util.InternalEList;
32 import org.eclipse.emf.ecore.util.FeatureMapUtil;
33
34
35 /**
36  * <!-- begin-user-doc -->
37  * An implementation of the model object '<em><b>EAttribute</b></em>'.
38  * <!-- end-user-doc -->
39  * <p>
40  * The following features are implemented:
41  * <ul>
42  * <li>{@link org.eclipse.emf.ecore.impl.EAttributeImpl#isID <em>ID</em>}</li>
43  * <li>{@link org.eclipse.emf.ecore.impl.EAttributeImpl#getEAttributeType <em>EAttribute Type</em>}</li>
44  * </ul>
45  * </p>
46  *
47  * @generated
48  */

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

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

69   protected static final int ID_EFLAG = 1 << 15;
70
71   /**
72    * <!-- begin-user-doc -->
73    * <!-- end-user-doc -->
74    * @generated
75    */

76   protected EAttributeImpl()
77   {
78     super();
79   }
80
81   /**
82    * <!-- begin-user-doc -->
83    * <!-- end-user-doc -->
84    * @generated
85    */

86   protected EClass eStaticClass()
87   {
88     return EcorePackage.eINSTANCE.getEAttribute();
89   }
90
91   /**
92    * <!-- begin-user-doc -->
93    * <!-- end-user-doc -->
94    * @generated
95    */

96   public boolean isID()
97   {
98     return (eFlags & ID_EFLAG) != 0;
99   }
100
101   protected byte effectiveIsMany;
102
103   public boolean isMany()
104   {
105     switch (effectiveIsMany)
106     {
107       case -1:
108       {
109         return true;
110       }
111       case 0:
112       {
113         int upper = getUpperBound();
114         if (upper > 1 || upper == UNBOUNDED_MULTIPLICITY)
115         {
116           effectiveIsMany = -1;
117           return true;
118         }
119         else
120         {
121           EClassifier eType = getEType();
122           if (eType != null && FeatureMapUtil.isFeatureMapEntry(eType))
123           {
124             effectiveIsMany = -1;
125             return true;
126           }
127           else
128           {
129             effectiveIsMany = 1;
130             return false;
131           }
132         }
133       }
134       default:
135       case 1:
136       {
137         return false;
138       }
139     }
140   }
141
142   public void setUpperBound(int upperBound)
143   {
144     effectiveIsMany = 0;
145     super.setUpperBound(upperBound);
146   }
147
148   public void setEType(EClassifier eType)
149   {
150     effectiveIsMany = 0;
151     super.setEType(eType);
152   }
153
154   /**
155    * <!-- begin-user-doc -->
156    * <!-- end-user-doc -->
157    * @generated
158    */

159   public void setID(boolean newID)
160   {
161     boolean oldID = (eFlags & ID_EFLAG) != 0;
162     if (newID) eFlags |= ID_EFLAG; else eFlags &= ~ID_EFLAG;
163     if (eNotificationRequired())
164       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EATTRIBUTE__ID, oldID, newID));
165   }
166
167   /**
168    * <!-- begin-user-doc -->
169    * <!-- end-user-doc -->
170    * @generated modifiable
171    */

172   public EDataType getEAttributeType()
173   {
174     return (EDataType)getEType();
175   }
176
177   /**
178    * <!-- begin-user-doc -->
179    * <!-- end-user-doc -->
180    * @generated modifiable
181    */

182   public EDataType basicGetEAttributeType()
183   {
184     return (EDataType)eType;
185   }
186
187   /**
188    * <!-- begin-user-doc -->
189    * <!-- end-user-doc -->
190    * @generated
191    */

192   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
193   {
194     if (featureID >= 0)
195     {
196       switch (eDerivedStructuralFeatureID(featureID, baseClass))
197       {
198         case EcorePackage.EATTRIBUTE__EANNOTATIONS:
199           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
200         case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS:
201           if (eContainer != null)
202             msgs = eBasicRemoveFromContainer(msgs);
203           return eBasicSetContainer(otherEnd, EcorePackage.EATTRIBUTE__ECONTAINING_CLASS, msgs);
204         default:
205           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
206       }
207     }
208     if (eContainer != null)
209       msgs = eBasicRemoveFromContainer(msgs);
210     return eBasicSetContainer(otherEnd, featureID, msgs);
211   }
212
213   /**
214    * <!-- begin-user-doc -->
215    * <!-- end-user-doc -->
216    * @generated
217    */

218   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
219   {
220     if (featureID >= 0)
221     {
222       switch (eDerivedStructuralFeatureID(featureID, baseClass))
223       {
224         case EcorePackage.EATTRIBUTE__EANNOTATIONS:
225           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
226         case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS:
227           return eBasicSetContainer(null, EcorePackage.EATTRIBUTE__ECONTAINING_CLASS, msgs);
228         default:
229           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
230       }
231     }
232     return eBasicSetContainer(null, featureID, msgs);
233   }
234
235   /**
236    * <!-- begin-user-doc -->
237    * <!-- end-user-doc -->
238    * @generated
239    */

240   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
241   {
242     if (eContainerFeatureID >= 0)
243     {
244       switch (eContainerFeatureID)
245       {
246         case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS:
247           return eContainer.eInverseRemove(this, EcorePackage.ECLASS__ESTRUCTURAL_FEATURES, EClass.class, msgs);
248         default:
249           return eDynamicBasicRemoveFromContainer(msgs);
250       }
251     }
252     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
253   }
254
255   /**
256    * <!-- begin-user-doc -->
257    * <!-- end-user-doc -->
258    * @generated
259    */

260   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
261   {
262     switch (eDerivedStructuralFeatureID(eFeature))
263     {
264       case EcorePackage.EATTRIBUTE__EANNOTATIONS:
265         return getEAnnotations();
266       case EcorePackage.EATTRIBUTE__NAME:
267         return getName();
268       case EcorePackage.EATTRIBUTE__ORDERED:
269         return isOrdered() ? Boolean.TRUE : Boolean.FALSE;
270       case EcorePackage.EATTRIBUTE__UNIQUE:
271         return isUnique() ? Boolean.TRUE : Boolean.FALSE;
272       case EcorePackage.EATTRIBUTE__LOWER_BOUND:
273         return new Integer JavaDoc(getLowerBound());
274       case EcorePackage.EATTRIBUTE__UPPER_BOUND:
275         return new Integer JavaDoc(getUpperBound());
276       case EcorePackage.EATTRIBUTE__MANY:
277         return isMany() ? Boolean.TRUE : Boolean.FALSE;
278       case EcorePackage.EATTRIBUTE__REQUIRED:
279         return isRequired() ? Boolean.TRUE : Boolean.FALSE;
280       case EcorePackage.EATTRIBUTE__ETYPE:
281         if (resolve) return getEType();
282         return basicGetEType();
283       case EcorePackage.EATTRIBUTE__CHANGEABLE:
284         return isChangeable() ? Boolean.TRUE : Boolean.FALSE;
285       case EcorePackage.EATTRIBUTE__VOLATILE:
286         return isVolatile() ? Boolean.TRUE : Boolean.FALSE;
287       case EcorePackage.EATTRIBUTE__TRANSIENT:
288         return isTransient() ? Boolean.TRUE : Boolean.FALSE;
289       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL:
290         return getDefaultValueLiteral();
291       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE:
292         return getDefaultValue();
293       case EcorePackage.EATTRIBUTE__UNSETTABLE:
294         return isUnsettable() ? Boolean.TRUE : Boolean.FALSE;
295       case EcorePackage.EATTRIBUTE__DERIVED:
296         return isDerived() ? Boolean.TRUE : Boolean.FALSE;
297       case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS:
298         return getEContainingClass();
299       case EcorePackage.EATTRIBUTE__ID:
300         return isID() ? Boolean.TRUE : Boolean.FALSE;
301       case EcorePackage.EATTRIBUTE__EATTRIBUTE_TYPE:
302         if (resolve) return getEAttributeType();
303         return basicGetEAttributeType();
304     }
305     return eDynamicGet(eFeature, resolve);
306   }
307
308   /**
309    * <!-- begin-user-doc -->
310    * <!-- end-user-doc -->
311    * @generated
312    */

313   public boolean eIsSet(EStructuralFeature eFeature)
314   {
315     switch (eDerivedStructuralFeatureID(eFeature))
316     {
317       case EcorePackage.EATTRIBUTE__EANNOTATIONS:
318         return eAnnotations != null && !eAnnotations.isEmpty();
319       case EcorePackage.EATTRIBUTE__NAME:
320         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
321       case EcorePackage.EATTRIBUTE__ORDERED:
322         return ((eFlags & ORDERED_EFLAG) != 0) != ORDERED_EDEFAULT;
323       case EcorePackage.EATTRIBUTE__UNIQUE:
324         return ((eFlags & UNIQUE_EFLAG) != 0) != UNIQUE_EDEFAULT;
325       case EcorePackage.EATTRIBUTE__LOWER_BOUND:
326         return lowerBound != LOWER_BOUND_EDEFAULT;
327       case EcorePackage.EATTRIBUTE__UPPER_BOUND:
328         return upperBound != UPPER_BOUND_EDEFAULT;
329       case EcorePackage.EATTRIBUTE__MANY:
330         return isMany() != MANY_EDEFAULT;
331       case EcorePackage.EATTRIBUTE__REQUIRED:
332         return isRequired() != REQUIRED_EDEFAULT;
333       case EcorePackage.EATTRIBUTE__ETYPE:
334         return eType != null;
335       case EcorePackage.EATTRIBUTE__CHANGEABLE:
336         return ((eFlags & CHANGEABLE_EFLAG) != 0) != CHANGEABLE_EDEFAULT;
337       case EcorePackage.EATTRIBUTE__VOLATILE:
338         return ((eFlags & VOLATILE_EFLAG) != 0) != VOLATILE_EDEFAULT;
339       case EcorePackage.EATTRIBUTE__TRANSIENT:
340         return ((eFlags & TRANSIENT_EFLAG) != 0) != TRANSIENT_EDEFAULT;
341       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL:
342         return DEFAULT_VALUE_LITERAL_EDEFAULT == null ? defaultValueLiteral != null : !DEFAULT_VALUE_LITERAL_EDEFAULT.equals(defaultValueLiteral);
343       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE:
344         return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue());
345       case EcorePackage.EATTRIBUTE__UNSETTABLE:
346         return ((eFlags & UNSETTABLE_EFLAG) != 0) != UNSETTABLE_EDEFAULT;
347       case EcorePackage.EATTRIBUTE__DERIVED:
348         return ((eFlags & DERIVED_EFLAG) != 0) != DERIVED_EDEFAULT;
349       case EcorePackage.EATTRIBUTE__ECONTAINING_CLASS:
350         return getEContainingClass() != null;
351       case EcorePackage.EATTRIBUTE__ID:
352         return ((eFlags & ID_EFLAG) != 0) != ID_EDEFAULT;
353       case EcorePackage.EATTRIBUTE__EATTRIBUTE_TYPE:
354         return basicGetEAttributeType() != null;
355     }
356     return eDynamicIsSet(eFeature);
357   }
358
359   /**
360    * <!-- begin-user-doc -->
361    * <!-- end-user-doc -->
362    * @generated
363    */

364   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
365   {
366     switch (eDerivedStructuralFeatureID(eFeature))
367     {
368       case EcorePackage.EATTRIBUTE__EANNOTATIONS:
369         getEAnnotations().clear();
370         getEAnnotations().addAll((Collection JavaDoc)newValue);
371         return;
372       case EcorePackage.EATTRIBUTE__NAME:
373         setName((String JavaDoc)newValue);
374         return;
375       case EcorePackage.EATTRIBUTE__ORDERED:
376         setOrdered(((Boolean JavaDoc)newValue).booleanValue());
377         return;
378       case EcorePackage.EATTRIBUTE__UNIQUE:
379         setUnique(((Boolean JavaDoc)newValue).booleanValue());
380         return;
381       case EcorePackage.EATTRIBUTE__LOWER_BOUND:
382         setLowerBound(((Integer JavaDoc)newValue).intValue());
383         return;
384       case EcorePackage.EATTRIBUTE__UPPER_BOUND:
385         setUpperBound(((Integer JavaDoc)newValue).intValue());
386         return;
387       case EcorePackage.EATTRIBUTE__ETYPE:
388         setEType((EClassifier)newValue);
389         return;
390       case EcorePackage.EATTRIBUTE__CHANGEABLE:
391         setChangeable(((Boolean JavaDoc)newValue).booleanValue());
392         return;
393       case EcorePackage.EATTRIBUTE__VOLATILE:
394         setVolatile(((Boolean JavaDoc)newValue).booleanValue());
395         return;
396       case EcorePackage.EATTRIBUTE__TRANSIENT:
397         setTransient(((Boolean JavaDoc)newValue).booleanValue());
398         return;
399       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL:
400         setDefaultValueLiteral((String JavaDoc)newValue);
401         return;
402       case EcorePackage.EATTRIBUTE__UNSETTABLE:
403         setUnsettable(((Boolean JavaDoc)newValue).booleanValue());
404         return;
405       case EcorePackage.EATTRIBUTE__DERIVED:
406         setDerived(((Boolean JavaDoc)newValue).booleanValue());
407         return;
408       case EcorePackage.EATTRIBUTE__ID:
409         setID(((Boolean JavaDoc)newValue).booleanValue());
410         return;
411     }
412     eDynamicSet(eFeature, newValue);
413   }
414
415   /**
416    * <!-- begin-user-doc -->
417    * <!-- end-user-doc -->
418    * @generated
419    */

420   public void eUnset(EStructuralFeature eFeature)
421   {
422     switch (eDerivedStructuralFeatureID(eFeature))
423     {
424       case EcorePackage.EATTRIBUTE__EANNOTATIONS:
425         getEAnnotations().clear();
426         return;
427       case EcorePackage.EATTRIBUTE__NAME:
428         setName(NAME_EDEFAULT);
429         return;
430       case EcorePackage.EATTRIBUTE__ORDERED:
431         setOrdered(ORDERED_EDEFAULT);
432         return;
433       case EcorePackage.EATTRIBUTE__UNIQUE:
434         setUnique(UNIQUE_EDEFAULT);
435         return;
436       case EcorePackage.EATTRIBUTE__LOWER_BOUND:
437         setLowerBound(LOWER_BOUND_EDEFAULT);
438         return;
439       case EcorePackage.EATTRIBUTE__UPPER_BOUND:
440         setUpperBound(UPPER_BOUND_EDEFAULT);
441         return;
442       case EcorePackage.EATTRIBUTE__ETYPE:
443         setEType((EClassifier)null);
444         return;
445       case EcorePackage.EATTRIBUTE__CHANGEABLE:
446         setChangeable(CHANGEABLE_EDEFAULT);
447         return;
448       case EcorePackage.EATTRIBUTE__VOLATILE:
449         setVolatile(VOLATILE_EDEFAULT);
450         return;
451       case EcorePackage.EATTRIBUTE__TRANSIENT:
452         setTransient(TRANSIENT_EDEFAULT);
453         return;
454       case EcorePackage.EATTRIBUTE__DEFAULT_VALUE_LITERAL:
455         setDefaultValueLiteral(DEFAULT_VALUE_LITERAL_EDEFAULT);
456         return;
457       case EcorePackage.EATTRIBUTE__UNSETTABLE:
458         setUnsettable(UNSETTABLE_EDEFAULT);
459         return;
460       case EcorePackage.EATTRIBUTE__DERIVED:
461         setDerived(DERIVED_EDEFAULT);
462         return;
463       case EcorePackage.EATTRIBUTE__ID:
464         setID(ID_EDEFAULT);
465         return;
466     }
467     eDynamicUnset(eFeature);
468   }
469
470   /**
471    * <!-- begin-user-doc -->
472    * <!-- end-user-doc -->
473    * @generated
474    */

475   public String JavaDoc toString()
476   {
477     if (eIsProxy()) return super.toString();
478
479     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
480     result.append(" (iD: ");
481     result.append((eFlags & ID_EFLAG) != 0);
482     result.append(')');
483     return result.toString();
484   }
485
486 }
487
Popular Tags