1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import org.eclipse.emf.common.notify.NotificationChain; 24 import org.eclipse.emf.common.util.EList; 25 import org.eclipse.emf.ecore.EClass; 26 import org.eclipse.emf.ecore.EEnum; 27 import org.eclipse.emf.ecore.EEnumLiteral; 28 import org.eclipse.emf.ecore.EPackage; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 import org.eclipse.emf.ecore.EcorePackage; 31 import org.eclipse.emf.ecore.InternalEObject; 32 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; 33 import org.eclipse.emf.ecore.util.InternalEList; 34 35 36 49 public class EEnumImpl extends EDataTypeImpl implements EEnum 50 { 51 59 protected EList eLiterals = null; 60 61 66 protected EEnumImpl() 67 { 68 super(); 69 } 70 71 protected void setDataTypeGeneratedInstanceClass(boolean isGenerated) 72 { 73 } 74 75 public Object getDefaultValue() 76 { 77 EList eLiterals = getELiterals(); 78 if (!eLiterals.isEmpty()) 79 { 80 return ((EEnumLiteral)eLiterals.get(0)).getInstance(); 81 } 82 return null; 83 } 84 85 88 public boolean isInstance(Object object) 89 { 90 if (object != null) 91 { 92 Class instanceClass = getInstanceClass(); 93 if (instanceClass != null) 94 { 95 return instanceClass.isInstance(object); 96 } 97 else 98 { 99 return getELiterals().contains(object); 100 } 101 } 102 return false; 103 } 104 105 110 protected EClass eStaticClass() 111 { 112 return EcorePackage.eINSTANCE.getEEnum(); 113 } 114 115 120 public EList getELiterals() 121 { 122 if (eLiterals == null) 123 { 124 eLiterals = new EObjectContainmentWithInverseEList(EEnumLiteral.class, this, EcorePackage.EENUM__ELITERALS, EcorePackage.EENUM_LITERAL__EENUM); 125 } 126 return eLiterals; 127 } 128 129 134 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 135 { 136 if (featureID >= 0) 137 { 138 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 139 { 140 case EcorePackage.EENUM__EANNOTATIONS: 141 return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs); 142 case EcorePackage.EENUM__EPACKAGE: 143 return eBasicSetContainer(null, EcorePackage.EENUM__EPACKAGE, msgs); 144 case EcorePackage.EENUM__ELITERALS: 145 return ((InternalEList)getELiterals()).basicRemove(otherEnd, msgs); 146 default: 147 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 148 } 149 } 150 return eBasicSetContainer(null, featureID, msgs); 151 } 152 153 158 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 159 { 160 if (eContainerFeatureID >= 0) 161 { 162 switch (eContainerFeatureID) 163 { 164 case EcorePackage.EENUM__EPACKAGE: 165 return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ECLASSIFIERS, EPackage.class, msgs); 166 default: 167 return eDynamicBasicRemoveFromContainer(msgs); 168 } 169 } 170 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 171 } 172 173 178 public Object eGet(EStructuralFeature eFeature, boolean resolve) 179 { 180 switch (eDerivedStructuralFeatureID(eFeature)) 181 { 182 case EcorePackage.EENUM__EANNOTATIONS: 183 return getEAnnotations(); 184 case EcorePackage.EENUM__NAME: 185 return getName(); 186 case EcorePackage.EENUM__INSTANCE_CLASS_NAME: 187 return getInstanceClassName(); 188 case EcorePackage.EENUM__INSTANCE_CLASS: 189 return getInstanceClass(); 190 case EcorePackage.EENUM__DEFAULT_VALUE: 191 return getDefaultValue(); 192 case EcorePackage.EENUM__EPACKAGE: 193 return getEPackage(); 194 case EcorePackage.EENUM__SERIALIZABLE: 195 return isSerializable() ? Boolean.TRUE : Boolean.FALSE; 196 case EcorePackage.EENUM__ELITERALS: 197 return getELiterals(); 198 } 199 return eDynamicGet(eFeature, resolve); 200 } 201 202 207 public boolean eIsSet(EStructuralFeature eFeature) 208 { 209 switch (eDerivedStructuralFeatureID(eFeature)) 210 { 211 case EcorePackage.EENUM__EANNOTATIONS: 212 return eAnnotations != null && !eAnnotations.isEmpty(); 213 case EcorePackage.EENUM__NAME: 214 return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); 215 case EcorePackage.EENUM__INSTANCE_CLASS_NAME: 216 return INSTANCE_CLASS_NAME_EDEFAULT == null ? instanceClassName != null : !INSTANCE_CLASS_NAME_EDEFAULT.equals(instanceClassName); 217 case EcorePackage.EENUM__INSTANCE_CLASS: 218 return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass()); 219 case EcorePackage.EENUM__DEFAULT_VALUE: 220 return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue()); 221 case EcorePackage.EENUM__EPACKAGE: 222 return getEPackage() != null; 223 case EcorePackage.EENUM__SERIALIZABLE: 224 return ((eFlags & SERIALIZABLE_EFLAG) != 0) != SERIALIZABLE_EDEFAULT; 225 case EcorePackage.EENUM__ELITERALS: 226 return eLiterals != null && !eLiterals.isEmpty(); 227 } 228 return eDynamicIsSet(eFeature); 229 } 230 231 236 public void eSet(EStructuralFeature eFeature, Object newValue) 237 { 238 switch (eDerivedStructuralFeatureID(eFeature)) 239 { 240 case EcorePackage.EENUM__EANNOTATIONS: 241 getEAnnotations().clear(); 242 getEAnnotations().addAll((Collection )newValue); 243 return; 244 case EcorePackage.EENUM__NAME: 245 setName((String )newValue); 246 return; 247 case EcorePackage.EENUM__INSTANCE_CLASS_NAME: 248 setInstanceClassName((String )newValue); 249 return; 250 case EcorePackage.EENUM__SERIALIZABLE: 251 setSerializable(((Boolean )newValue).booleanValue()); 252 return; 253 case EcorePackage.EENUM__ELITERALS: 254 getELiterals().clear(); 255 getELiterals().addAll((Collection )newValue); 256 return; 257 } 258 eDynamicSet(eFeature, newValue); 259 } 260 261 266 public void eUnset(EStructuralFeature eFeature) 267 { 268 switch (eDerivedStructuralFeatureID(eFeature)) 269 { 270 case EcorePackage.EENUM__EANNOTATIONS: 271 getEAnnotations().clear(); 272 return; 273 case EcorePackage.EENUM__NAME: 274 setName(NAME_EDEFAULT); 275 return; 276 case EcorePackage.EENUM__INSTANCE_CLASS_NAME: 277 setInstanceClassName(INSTANCE_CLASS_NAME_EDEFAULT); 278 return; 279 case EcorePackage.EENUM__SERIALIZABLE: 280 setSerializable(SERIALIZABLE_EDEFAULT); 281 return; 282 case EcorePackage.EENUM__ELITERALS: 283 getELiterals().clear(); 284 return; 285 } 286 eDynamicUnset(eFeature); 287 } 288 289 292 public EEnumLiteral getEEnumLiteral(String stringValue) 293 { 294 for (Iterator i = getELiterals().iterator(); i.hasNext(); ) 295 { 296 EEnumLiteral eEnumLiteral = (EEnumLiteral) i.next(); 297 if (eEnumLiteral.getName().equals(stringValue)) 298 { 299 return eEnumLiteral; 300 } 301 } 302 return null; 303 } 304 305 308 public EEnumLiteral getEEnumLiteral(int intValue) 309 { 310 for (Iterator i = getELiterals().iterator(); i.hasNext(); ) 311 { 312 EEnumLiteral eEnumLiteral = (EEnumLiteral) i.next(); 313 if (eEnumLiteral.getValue() == intValue) 314 { 315 return eEnumLiteral; 316 } 317 } 318 return null; 319 } 320 321 326 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 327 { 328 if (featureID >= 0) 329 { 330 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 331 { 332 case EcorePackage.EENUM__EANNOTATIONS: 333 return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs); 334 case EcorePackage.EENUM__EPACKAGE: 335 if (eContainer != null) 336 msgs = eBasicRemoveFromContainer(msgs); 337 return eBasicSetContainer(otherEnd, EcorePackage.EENUM__EPACKAGE, msgs); 338 case EcorePackage.EENUM__ELITERALS: 339 return ((InternalEList)getELiterals()).basicAdd(otherEnd, msgs); 340 default: 341 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 342 } 343 } 344 if (eContainer != null) 345 msgs = eBasicRemoveFromContainer(msgs); 346 return eBasicSetContainer(otherEnd, featureID, msgs); 347 } 348 349 } 350 | Popular Tags |