1 17 package org.eclipse.emf.ecore.sdo.impl; 18 19 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.eclipse.emf.common.notify.Adapter; 26 import org.eclipse.emf.common.notify.Notification; 27 import org.eclipse.emf.common.notify.NotificationChain; 28 import org.eclipse.emf.common.notify.Notifier; 29 import org.eclipse.emf.common.util.EList; 30 import org.eclipse.emf.ecore.EClass; 31 import org.eclipse.emf.ecore.EClassifier; 32 import org.eclipse.emf.ecore.EStructuralFeature; 33 import org.eclipse.emf.ecore.InternalEObject; 34 import org.eclipse.emf.ecore.impl.ENotificationImpl; 35 import org.eclipse.emf.ecore.impl.EObjectImpl; 36 import org.eclipse.emf.ecore.sdo.EProperty; 37 import org.eclipse.emf.ecore.sdo.EType; 38 import org.eclipse.emf.ecore.sdo.SDOPackage; 39 import org.eclipse.emf.ecore.sdo.util.SDOUtil; 40 import org.eclipse.emf.ecore.util.EcoreEList; 41 import org.eclipse.emf.ecore.util.ExtendedMetaData; 42 import org.eclipse.emf.ecore.util.InternalEList; 43 44 import commonj.sdo.Property; 45 46 47 65 public class ETypeImpl extends EObjectImpl implements EType, Adapter 66 { 67 75 protected static final String NAME_EDEFAULT = null; 76 77 85 protected static final String URI_EDEFAULT = null; 86 87 95 protected static final Class INSTANCE_CLASS_EDEFAULT = null; 96 97 105 protected EClassifier eClassifier = null; 106 107 112 protected ETypeImpl() 113 { 114 super(); 115 } 116 117 122 protected EClass eStaticClass() 123 { 124 return SDOPackage.eINSTANCE.getEType(); 125 } 126 127 132 public String getName() 133 { 134 return eClassifier.getName(); 135 } 136 137 142 public String getURI() 143 { 144 return eClassifier.getEPackage().getNsURI(); 145 } 146 147 152 public Class getInstanceClass() 153 { 154 return eClassifier.getInstanceClass(); 155 } 156 157 protected EList properties; 158 protected EList eAllStructuralFeatures; 159 160 165 public EList getPropertiesGen() 166 { 167 if (eAllStructuralFeatures == null) 168 { 169 if (eClassifier instanceof EClass) 170 { 171 EList eAllStructuralFeatures = ((EClass)eClassifier).getEAllStructuralFeatures(); 172 properties = adaptProperties(eAllStructuralFeatures); 173 this.eAllStructuralFeatures = eAllStructuralFeatures; 174 } 175 else 176 { 177 properties = new EcoreEList.UnmodifiableEList.FastCompare(this, SDOPackage.eINSTANCE.getType_Properties(), 0, null); 178 } 179 } 180 else 181 { 182 EList eAllStructuralFeatures = ((EClass)eClassifier).getEAllStructuralFeatures(); 183 if (this.eAllStructuralFeatures != eAllStructuralFeatures) 184 { 185 properties = adaptProperties(eAllStructuralFeatures); 186 this.eAllStructuralFeatures = eAllStructuralFeatures; 187 } 188 } 189 return properties; 190 } 191 192 protected EList adaptProperties(List eStructuralFeatures) 193 { 194 EProperty [] properties = new EProperty [eStructuralFeatures.size()]; 195 for (int i = 0; i < properties.length; ++i) 196 { 197 properties[i] = SDOUtil.adaptProperty((EStructuralFeature)eStructuralFeatures.get(i)); 198 } 199 200 return 201 new EcoreEList.UnmodifiableEList.FastCompare 202 (this, SDOPackage.eINSTANCE.getType_Properties(), properties.length, properties); 203 } 204 205 public List getProperties() 206 { 207 return getPropertiesGen(); 208 } 209 210 215 public EClassifier getEClassifier() 216 { 217 return eClassifier; 218 } 219 220 225 public void setEClassifier(EClassifier newEClassifier) 226 { 227 EClassifier oldEClassifier = eClassifier; 228 eClassifier = newEClassifier; 229 if (eNotificationRequired()) 230 eNotify(new ENotificationImpl(this, Notification.SET, SDOPackage.ETYPE__ECLASSIFIER, oldEClassifier, eClassifier)); 231 } 232 233 238 public boolean isInstance(Object object) 239 { 240 return eClassifier.isInstance(object); 241 } 242 243 248 public Property getProperty(String propertyName) 249 { 250 return getEProperty(propertyName); 251 } 252 253 protected Map propertyNameToPropertyMap; 254 255 260 public EProperty getEProperty(String propertyName) 261 { 262 if (propertyNameToPropertyMap == null) 263 { 264 Map result = new HashMap (); 265 for (Iterator i = getProperties().iterator(); i.hasNext(); ) 266 { 267 EProperty eProperty = (EProperty)i.next(); 268 result.put(eProperty.getName(), eProperty); 269 String xmlName = ExtendedMetaData.INSTANCE.getName(eProperty.getEStructuralFeature()); 270 if (!result.containsKey(xmlName)) 271 { 272 result.put(xmlName, eProperty); 273 } 274 } 275 propertyNameToPropertyMap = result; 276 } 277 278 return (EProperty)propertyNameToPropertyMap.get(propertyName); 279 } 280 281 public boolean isAdapterForType(Object type) 282 { 283 return type == EType.class; 284 } 285 286 public void notifyChanged(Notification msg) 287 { 288 } 289 290 public Notifier getTarget() 291 { 292 return getEClassifier(); 293 } 294 295 public void setTarget(Notifier newTarget) 296 { 297 setEClassifier((EClassifier)newTarget); 298 } 299 300 305 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 306 { 307 if (featureID >= 0) 308 { 309 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 310 { 311 case SDOPackage.ETYPE__PROPERTIES: 312 return ((InternalEList)getProperties()).basicRemove(otherEnd, msgs); 313 default: 314 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 315 } 316 } 317 return eBasicSetContainer(null, featureID, msgs); 318 } 319 320 325 public Object eGet(EStructuralFeature eFeature, boolean resolve) 326 { 327 switch (eDerivedStructuralFeatureID(eFeature)) 328 { 329 case SDOPackage.ETYPE__NAME: 330 return getName(); 331 case SDOPackage.ETYPE__URI: 332 return getURI(); 333 case SDOPackage.ETYPE__INSTANCE_CLASS: 334 return getInstanceClass(); 335 case SDOPackage.ETYPE__PROPERTIES: 336 return getProperties(); 337 case SDOPackage.ETYPE__ECLASSIFIER: 338 return getEClassifier(); 339 } 340 return eDynamicGet(eFeature, resolve); 341 } 342 343 348 public void eSet(EStructuralFeature eFeature, Object newValue) 349 { 350 switch (eDerivedStructuralFeatureID(eFeature)) 351 { 352 case SDOPackage.ETYPE__ECLASSIFIER: 353 setEClassifier((EClassifier)newValue); 354 return; 355 } 356 eDynamicSet(eFeature, newValue); 357 } 358 359 364 public void eUnset(EStructuralFeature eFeature) 365 { 366 switch (eDerivedStructuralFeatureID(eFeature)) 367 { 368 case SDOPackage.ETYPE__ECLASSIFIER: 369 setEClassifier((EClassifier)null); 370 return; 371 } 372 eDynamicUnset(eFeature); 373 } 374 375 380 public boolean eIsSet(EStructuralFeature eFeature) 381 { 382 switch (eDerivedStructuralFeatureID(eFeature)) 383 { 384 case SDOPackage.ETYPE__NAME: 385 return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName()); 386 case SDOPackage.ETYPE__URI: 387 return URI_EDEFAULT == null ? getURI() != null : !URI_EDEFAULT.equals(getURI()); 388 case SDOPackage.ETYPE__INSTANCE_CLASS: 389 return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass()); 390 case SDOPackage.ETYPE__PROPERTIES: 391 return !getProperties().isEmpty(); 392 case SDOPackage.ETYPE__ECLASSIFIER: 393 return eClassifier != null; 394 } 395 return eDynamicIsSet(eFeature); 396 } 397 398 } | Popular Tags |