KickJava   Java API By Example, From Geeks To Geeks.

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


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: EDataTypeImpl.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.EClass;
25 import org.eclipse.emf.ecore.EDataType;
26 import org.eclipse.emf.ecore.EPackage;
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>EData Type</b></em>'.
36  * <!-- end-user-doc -->
37  * <p>
38  * The following features are implemented:
39  * <ul>
40  * <li>{@link org.eclipse.emf.ecore.impl.EDataTypeImpl#isSerializable <em>Serializable</em>}</li>
41  * </ul>
42  * </p>
43  *
44  * @generated
45  */

46 public class EDataTypeImpl extends EClassifierImpl implements EDataType
47 {
48   /**
49    * The default value of the '{@link #isSerializable() <em>Serializable</em>}' attribute.
50    * <!-- begin-user-doc -->
51    * <!-- end-user-doc -->
52    * @see #isSerializable()
53    * @generated
54    * @ordered
55    */

56   protected static final boolean SERIALIZABLE_EDEFAULT = true;
57
58   /**
59    * The flag representing the value of the '{@link #isSerializable() <em>Serializable</em>}' attribute.
60    * <!-- begin-user-doc -->
61    * <!-- end-user-doc -->
62    * @see #isSerializable()
63    * @generated
64    * @ordered
65    */

66   protected static final int SERIALIZABLE_EFLAG = 1 << 8;
67
68   /**
69    * <!-- begin-user-doc -->
70    * <!-- end-user-doc -->
71    * @generated
72    */

73   protected EDataTypeImpl()
74   {
75     super();
76     eFlags |= SERIALIZABLE_EFLAG;
77   }
78
79   protected Object JavaDoc defaultValue = null;
80   protected boolean defaultValueIsSet = false;
81
82   public Object JavaDoc getDefaultValue()
83   {
84     if (!defaultValueIsSet)
85     {
86       Class JavaDoc instanceClass = null;
87       try
88       {
89         instanceClass = getInstanceClass();
90       }
91       catch (Exception JavaDoc e) {}
92
93       defaultValue = null;
94       if (instanceClass != null && instanceClass.isPrimitive())
95       {
96         if (instanceClass == Boolean.TYPE)
97           defaultValue = Boolean.FALSE;
98         else if (instanceClass == Integer.TYPE)
99           defaultValue = new Integer JavaDoc(0);
100         else if (instanceClass == Float.TYPE)
101           defaultValue = new Float JavaDoc(0.0F);
102         else if (instanceClass == Double.TYPE)
103           defaultValue = new Double JavaDoc(0.0);
104         else if (instanceClass == Long.TYPE)
105           defaultValue = new Long JavaDoc(0);
106         else if (instanceClass == Short.TYPE)
107           defaultValue = new Short JavaDoc((short)0);
108         else if (instanceClass == Byte.TYPE)
109           defaultValue = new Byte JavaDoc((byte)0);
110         else // if (instanceClass == Character.TYPE)
111
defaultValue = new Character JavaDoc('\u0000');
112       }
113       defaultValueIsSet = true;
114     }
115     return defaultValue;
116   }
117
118   public void setInstanceClassGen(Class JavaDoc instanceClass)
119   {
120     super.setInstanceClassGen(instanceClass);
121     defaultValueIsSet = false;
122   }
123
124   public void setGeneratedInstanceClass(boolean isGenerated)
125   {
126     super.setGeneratedInstanceClass(isGenerated);
127
128     setDataTypeGeneratedInstanceClass(isGenerated);
129
130   }
131
132   protected void setDataTypeGeneratedInstanceClass(boolean isGenerated)
133   {
134     // EEnumImpl overrides this to do nothing.
135
// The only case that is special is when a more specific instance of AbstractEnumerator is generated/reused.
136
//
137
if (isGenerated)
138     {
139       instanceClassName = "org.eclipse.emf.common.util.AbstractEnumerator";
140     }
141   }
142
143   /**
144    * <!-- begin-user-doc -->
145    * <!-- end-user-doc -->
146    * @generated
147    */

148   protected EClass eStaticClass()
149   {
150     return EcorePackage.eINSTANCE.getEDataType();
151   }
152
153   /**
154    * <!-- begin-user-doc -->
155    * <!-- end-user-doc -->
156    * @generated
157    */

158   public boolean isSerializable()
159   {
160     return (eFlags & SERIALIZABLE_EFLAG) != 0;
161   }
162
163   /**
164    * <!-- begin-user-doc -->
165    * <!-- end-user-doc -->
166    * @generated
167    */

168   public void setSerializable(boolean newSerializable)
169   {
170     boolean oldSerializable = (eFlags & SERIALIZABLE_EFLAG) != 0;
171     if (newSerializable) eFlags |= SERIALIZABLE_EFLAG; else eFlags &= ~SERIALIZABLE_EFLAG;
172     if (eNotificationRequired())
173       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EDATA_TYPE__SERIALIZABLE, oldSerializable, newSerializable));
174   }
175
176   /**
177    * <!-- begin-user-doc -->
178    * <!-- end-user-doc -->
179    * @generated
180    */

181   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
182   {
183     if (featureID >= 0)
184     {
185       switch (eDerivedStructuralFeatureID(featureID, baseClass))
186       {
187         case EcorePackage.EDATA_TYPE__EANNOTATIONS:
188           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
189         case EcorePackage.EDATA_TYPE__EPACKAGE:
190           if (eContainer != null)
191             msgs = eBasicRemoveFromContainer(msgs);
192           return eBasicSetContainer(otherEnd, EcorePackage.EDATA_TYPE__EPACKAGE, msgs);
193         default:
194           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
195       }
196     }
197     if (eContainer != null)
198       msgs = eBasicRemoveFromContainer(msgs);
199     return eBasicSetContainer(otherEnd, featureID, msgs);
200   }
201
202   /**
203    * <!-- begin-user-doc -->
204    * <!-- end-user-doc -->
205    * @generated
206    */

207   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
208   {
209     if (featureID >= 0)
210     {
211       switch (eDerivedStructuralFeatureID(featureID, baseClass))
212       {
213         case EcorePackage.EDATA_TYPE__EANNOTATIONS:
214           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
215         case EcorePackage.EDATA_TYPE__EPACKAGE:
216           return eBasicSetContainer(null, EcorePackage.EDATA_TYPE__EPACKAGE, msgs);
217         default:
218           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
219       }
220     }
221     return eBasicSetContainer(null, featureID, msgs);
222   }
223
224   /**
225    * <!-- begin-user-doc -->
226    * <!-- end-user-doc -->
227    * @generated
228    */

229   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
230   {
231     if (eContainerFeatureID >= 0)
232     {
233       switch (eContainerFeatureID)
234       {
235         case EcorePackage.EDATA_TYPE__EPACKAGE:
236           return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ECLASSIFIERS, EPackage.class, msgs);
237         default:
238           return eDynamicBasicRemoveFromContainer(msgs);
239       }
240     }
241     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
242   }
243
244   /**
245    * <!-- begin-user-doc -->
246    * <!-- end-user-doc -->
247    * @generated
248    */

249   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
250   {
251     switch (eDerivedStructuralFeatureID(eFeature))
252     {
253       case EcorePackage.EDATA_TYPE__EANNOTATIONS:
254         return getEAnnotations();
255       case EcorePackage.EDATA_TYPE__NAME:
256         return getName();
257       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS_NAME:
258         return getInstanceClassName();
259       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS:
260         return getInstanceClass();
261       case EcorePackage.EDATA_TYPE__DEFAULT_VALUE:
262         return getDefaultValue();
263       case EcorePackage.EDATA_TYPE__EPACKAGE:
264         return getEPackage();
265       case EcorePackage.EDATA_TYPE__SERIALIZABLE:
266         return isSerializable() ? Boolean.TRUE : Boolean.FALSE;
267     }
268     return eDynamicGet(eFeature, resolve);
269   }
270
271   /**
272    * <!-- begin-user-doc -->
273    * <!-- end-user-doc -->
274    * @generated
275    */

276   public String JavaDoc toString()
277   {
278     if (eIsProxy()) return super.toString();
279
280     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
281     result.append(" (serializable: ");
282     result.append((eFlags & SERIALIZABLE_EFLAG) != 0);
283     result.append(')');
284     return result.toString();
285   }
286
287   /**
288    * <!-- begin-user-doc -->
289    * <!-- end-user-doc -->
290    * @generated
291    */

292   public boolean eIsSet(EStructuralFeature eFeature)
293   {
294     switch (eDerivedStructuralFeatureID(eFeature))
295     {
296       case EcorePackage.EDATA_TYPE__EANNOTATIONS:
297         return eAnnotations != null && !eAnnotations.isEmpty();
298       case EcorePackage.EDATA_TYPE__NAME:
299         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
300       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS_NAME:
301         return INSTANCE_CLASS_NAME_EDEFAULT == null ? instanceClassName != null : !INSTANCE_CLASS_NAME_EDEFAULT.equals(instanceClassName);
302       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS:
303         return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass());
304       case EcorePackage.EDATA_TYPE__DEFAULT_VALUE:
305         return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue());
306       case EcorePackage.EDATA_TYPE__EPACKAGE:
307         return getEPackage() != null;
308       case EcorePackage.EDATA_TYPE__SERIALIZABLE:
309         return ((eFlags & SERIALIZABLE_EFLAG) != 0) != SERIALIZABLE_EDEFAULT;
310     }
311     return eDynamicIsSet(eFeature);
312   }
313
314   /**
315    * <!-- begin-user-doc -->
316    * <!-- end-user-doc -->
317    * @generated
318    */

319   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
320   {
321     switch (eDerivedStructuralFeatureID(eFeature))
322     {
323       case EcorePackage.EDATA_TYPE__EANNOTATIONS:
324         getEAnnotations().clear();
325         getEAnnotations().addAll((Collection JavaDoc)newValue);
326         return;
327       case EcorePackage.EDATA_TYPE__NAME:
328         setName((String JavaDoc)newValue);
329         return;
330       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS_NAME:
331         setInstanceClassName((String JavaDoc)newValue);
332         return;
333       case EcorePackage.EDATA_TYPE__SERIALIZABLE:
334         setSerializable(((Boolean JavaDoc)newValue).booleanValue());
335         return;
336     }
337     eDynamicSet(eFeature, newValue);
338   }
339
340   /**
341    * <!-- begin-user-doc -->
342    * <!-- end-user-doc -->
343    * @generated
344    */

345   public void eUnset(EStructuralFeature eFeature)
346   {
347     switch (eDerivedStructuralFeatureID(eFeature))
348     {
349       case EcorePackage.EDATA_TYPE__EANNOTATIONS:
350         getEAnnotations().clear();
351         return;
352       case EcorePackage.EDATA_TYPE__NAME:
353         setName(NAME_EDEFAULT);
354         return;
355       case EcorePackage.EDATA_TYPE__INSTANCE_CLASS_NAME:
356         setInstanceClassName(INSTANCE_CLASS_NAME_EDEFAULT);
357         return;
358       case EcorePackage.EDATA_TYPE__SERIALIZABLE:
359         setSerializable(SERIALIZABLE_EDEFAULT);
360         return;
361     }
362     eDynamicUnset(eFeature);
363   }
364
365 }
366
Popular Tags