1 17 package org.eclipse.emf.ecore.impl; 18 19 20 import java.util.Collection ; 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 46 public class EDataTypeImpl extends EClassifierImpl implements EDataType 47 { 48 56 protected static final boolean SERIALIZABLE_EDEFAULT = true; 57 58 66 protected static final int SERIALIZABLE_EFLAG = 1 << 8; 67 68 73 protected EDataTypeImpl() 74 { 75 super(); 76 eFlags |= SERIALIZABLE_EFLAG; 77 } 78 79 protected Object defaultValue = null; 80 protected boolean defaultValueIsSet = false; 81 82 public Object getDefaultValue() 83 { 84 if (!defaultValueIsSet) 85 { 86 Class instanceClass = null; 87 try 88 { 89 instanceClass = getInstanceClass(); 90 } 91 catch (Exception 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 (0); 100 else if (instanceClass == Float.TYPE) 101 defaultValue = new Float (0.0F); 102 else if (instanceClass == Double.TYPE) 103 defaultValue = new Double (0.0); 104 else if (instanceClass == Long.TYPE) 105 defaultValue = new Long (0); 106 else if (instanceClass == Short.TYPE) 107 defaultValue = new Short ((short)0); 108 else if (instanceClass == Byte.TYPE) 109 defaultValue = new Byte ((byte)0); 110 else defaultValue = new Character ('\u0000'); 112 } 113 defaultValueIsSet = true; 114 } 115 return defaultValue; 116 } 117 118 public void setInstanceClassGen(Class 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 if (isGenerated) 138 { 139 instanceClassName = "org.eclipse.emf.common.util.AbstractEnumerator"; 140 } 141 } 142 143 148 protected EClass eStaticClass() 149 { 150 return EcorePackage.eINSTANCE.getEDataType(); 151 } 152 153 158 public boolean isSerializable() 159 { 160 return (eFlags & SERIALIZABLE_EFLAG) != 0; 161 } 162 163 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 181 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class 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 207 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class 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 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 249 public Object 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 276 public String toString() 277 { 278 if (eIsProxy()) return super.toString(); 279 280 StringBuffer result = new StringBuffer (super.toString()); 281 result.append(" (serializable: "); 282 result.append((eFlags & SERIALIZABLE_EFLAG) != 0); 283 result.append(')'); 284 return result.toString(); 285 } 286 287 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 319 public void eSet(EStructuralFeature eFeature, Object newValue) 320 { 321 switch (eDerivedStructuralFeatureID(eFeature)) 322 { 323 case EcorePackage.EDATA_TYPE__EANNOTATIONS: 324 getEAnnotations().clear(); 325 getEAnnotations().addAll((Collection )newValue); 326 return; 327 case EcorePackage.EDATA_TYPE__NAME: 328 setName((String )newValue); 329 return; 330 case EcorePackage.EDATA_TYPE__INSTANCE_CLASS_NAME: 331 setInstanceClassName((String )newValue); 332 return; 333 case EcorePackage.EDATA_TYPE__SERIALIZABLE: 334 setSerializable(((Boolean )newValue).booleanValue()); 335 return; 336 } 337 eDynamicSet(eFeature, newValue); 338 } 339 340 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 |