1 17 package org.eclipse.emf.mapping.impl; 18 19 20 import java.util.Collection ; 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 24 import org.eclipse.emf.common.notify.Notification; 25 import org.eclipse.emf.common.notify.NotificationChain; 26 import org.eclipse.emf.common.util.AbstractTreeIterator; 27 import org.eclipse.emf.common.util.EList; 28 import org.eclipse.emf.common.util.TreeIterator; 29 import org.eclipse.emf.ecore.EClass; 30 import org.eclipse.emf.ecore.EObject; 31 import org.eclipse.emf.ecore.EStructuralFeature; 32 import org.eclipse.emf.ecore.InternalEObject; 33 import org.eclipse.emf.ecore.impl.ENotificationImpl; 34 import org.eclipse.emf.ecore.impl.EObjectImpl; 35 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; 36 import org.eclipse.emf.ecore.util.EObjectResolvingEList; 37 import org.eclipse.emf.ecore.util.EcoreUtil; 38 import org.eclipse.emf.ecore.util.InternalEList; 39 import org.eclipse.emf.mapping.Mapping; 40 import org.eclipse.emf.mapping.MappingHelper; 41 import org.eclipse.emf.mapping.MappingPackage; 42 import org.eclipse.emf.mapping.MappingRoot; 43 44 45 63 public class MappingImpl extends EObjectImpl implements Mapping 64 { 65 73 protected MappingHelper helper = null; 74 75 83 protected EList nested = null; 84 85 93 protected EList inputs = null; 94 95 103 protected EList outputs = null; 104 105 113 protected Mapping typeMapping = null; 114 115 120 protected MappingImpl() 121 { 122 super(); 123 } 124 125 130 protected EClass eStaticClass() 131 { 132 return MappingPackage.eINSTANCE.getMapping(); 133 } 134 135 140 public MappingHelper getHelper() 141 { 142 return helper; 143 } 144 145 150 public NotificationChain basicSetHelper(MappingHelper newHelper, NotificationChain msgs) 151 { 152 MappingHelper oldHelper = helper; 153 helper = newHelper; 154 if (eNotificationRequired()) 155 { 156 ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MappingPackage.MAPPING__HELPER, oldHelper, newHelper); 157 if (msgs == null) msgs = notification; else msgs.add(notification); 158 } 159 return msgs; 160 } 161 162 167 public void setHelper(MappingHelper newHelper) 168 { 169 if (newHelper != helper) 170 { 171 NotificationChain msgs = null; 172 if (helper != null) 173 msgs = ((InternalEObject)helper).eInverseRemove(this, MappingPackage.MAPPING_HELPER__MAPPER, MappingHelper.class, msgs); 174 if (newHelper != null) 175 msgs = ((InternalEObject)newHelper).eInverseAdd(this, MappingPackage.MAPPING_HELPER__MAPPER, MappingHelper.class, msgs); 176 msgs = basicSetHelper(newHelper, msgs); 177 if (msgs != null) msgs.dispatch(); 178 } 179 else if (eNotificationRequired()) 180 eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.MAPPING__HELPER, newHelper, newHelper)); 181 } 182 183 188 public EList getNested() 189 { 190 if (nested == null) 191 { 192 nested = new EObjectContainmentWithInverseEList(Mapping.class, this, MappingPackage.MAPPING__NESTED, MappingPackage.MAPPING__NESTED_IN); 193 } 194 return nested; 195 } 196 197 202 public Mapping getNestedIn() 203 { 204 if (eContainerFeatureID != MappingPackage.MAPPING__NESTED_IN) return null; 205 return (Mapping)eContainer; 206 } 207 208 213 public void setNestedIn(Mapping newNestedIn) 214 { 215 if (newNestedIn != eContainer || (eContainerFeatureID != MappingPackage.MAPPING__NESTED_IN && newNestedIn != null)) 216 { 217 if (EcoreUtil.isAncestor(this, newNestedIn)) 218 throw new IllegalArgumentException ("Recursive containment not allowed for " + toString()); 219 NotificationChain msgs = null; 220 if (eContainer != null) 221 msgs = eBasicRemoveFromContainer(msgs); 222 if (newNestedIn != null) 223 msgs = ((InternalEObject)newNestedIn).eInverseAdd(this, MappingPackage.MAPPING__NESTED, Mapping.class, msgs); 224 msgs = eBasicSetContainer((InternalEObject)newNestedIn, MappingPackage.MAPPING__NESTED_IN, msgs); 225 if (msgs != null) msgs.dispatch(); 226 } 227 else if (eNotificationRequired()) 228 eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.MAPPING__NESTED_IN, newNestedIn, newNestedIn)); 229 } 230 231 236 public EList getInputs() 237 { 238 if (inputs == null) 239 { 240 inputs = new EObjectResolvingEList(EObject.class, this, MappingPackage.MAPPING__INPUTS); 241 } 242 return inputs; 243 } 244 245 250 public EList getOutputs() 251 { 252 if (outputs == null) 253 { 254 outputs = new EObjectResolvingEList(EObject.class, this, MappingPackage.MAPPING__OUTPUTS); 255 } 256 return outputs; 257 } 258 259 264 public Mapping getTypeMapping() 265 { 266 if (typeMapping != null && typeMapping.eIsProxy()) 267 { 268 Mapping oldTypeMapping = typeMapping; 269 typeMapping = (Mapping)eResolveProxy((InternalEObject)typeMapping); 270 if (typeMapping != oldTypeMapping) 271 { 272 if (eNotificationRequired()) 273 eNotify(new ENotificationImpl(this, Notification.RESOLVE, MappingPackage.MAPPING__TYPE_MAPPING, oldTypeMapping, typeMapping)); 274 } 275 } 276 return typeMapping; 277 } 278 279 284 public Mapping basicGetTypeMapping() 285 { 286 return typeMapping; 287 } 288 289 294 public void setTypeMapping(Mapping newTypeMapping) 295 { 296 Mapping oldTypeMapping = typeMapping; 297 typeMapping = newTypeMapping; 298 if (eNotificationRequired()) 299 eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.MAPPING__TYPE_MAPPING, oldTypeMapping, typeMapping)); 300 } 301 302 307 public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 308 { 309 if (featureID >= 0) 310 { 311 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 312 { 313 case MappingPackage.MAPPING__HELPER: 314 if (helper != null) 315 msgs = ((InternalEObject)helper).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MappingPackage.MAPPING__HELPER, null, msgs); 316 return basicSetHelper((MappingHelper)otherEnd, msgs); 317 case MappingPackage.MAPPING__NESTED: 318 return ((InternalEList)getNested()).basicAdd(otherEnd, msgs); 319 case MappingPackage.MAPPING__NESTED_IN: 320 if (eContainer != null) 321 msgs = eBasicRemoveFromContainer(msgs); 322 return eBasicSetContainer(otherEnd, MappingPackage.MAPPING__NESTED_IN, msgs); 323 default: 324 return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); 325 } 326 } 327 if (eContainer != null) 328 msgs = eBasicRemoveFromContainer(msgs); 329 return eBasicSetContainer(otherEnd, featureID, msgs); 330 } 331 332 337 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 338 { 339 if (featureID >= 0) 340 { 341 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 342 { 343 case MappingPackage.MAPPING__HELPER: 344 return basicSetHelper(null, msgs); 345 case MappingPackage.MAPPING__NESTED: 346 return ((InternalEList)getNested()).basicRemove(otherEnd, msgs); 347 case MappingPackage.MAPPING__NESTED_IN: 348 return eBasicSetContainer(null, MappingPackage.MAPPING__NESTED_IN, msgs); 349 default: 350 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 351 } 352 } 353 return eBasicSetContainer(null, featureID, msgs); 354 } 355 356 361 public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) 362 { 363 if (eContainerFeatureID >= 0) 364 { 365 switch (eContainerFeatureID) 366 { 367 case MappingPackage.MAPPING__NESTED_IN: 368 return eContainer.eInverseRemove(this, MappingPackage.MAPPING__NESTED, Mapping.class, msgs); 369 default: 370 return eDynamicBasicRemoveFromContainer(msgs); 371 } 372 } 373 return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); 374 } 375 376 381 public Object eGet(EStructuralFeature eFeature, boolean resolve) 382 { 383 switch (eDerivedStructuralFeatureID(eFeature)) 384 { 385 case MappingPackage.MAPPING__HELPER: 386 return getHelper(); 387 case MappingPackage.MAPPING__NESTED: 388 return getNested(); 389 case MappingPackage.MAPPING__NESTED_IN: 390 return getNestedIn(); 391 case MappingPackage.MAPPING__INPUTS: 392 return getInputs(); 393 case MappingPackage.MAPPING__OUTPUTS: 394 return getOutputs(); 395 case MappingPackage.MAPPING__TYPE_MAPPING: 396 if (resolve) return getTypeMapping(); 397 return basicGetTypeMapping(); 398 } 399 return eDynamicGet(eFeature, resolve); 400 } 401 402 407 public void eSet(EStructuralFeature eFeature, Object newValue) 408 { 409 switch (eDerivedStructuralFeatureID(eFeature)) 410 { 411 case MappingPackage.MAPPING__HELPER: 412 setHelper((MappingHelper)newValue); 413 return; 414 case MappingPackage.MAPPING__NESTED: 415 getNested().clear(); 416 getNested().addAll((Collection )newValue); 417 return; 418 case MappingPackage.MAPPING__NESTED_IN: 419 setNestedIn((Mapping)newValue); 420 return; 421 case MappingPackage.MAPPING__INPUTS: 422 getInputs().clear(); 423 getInputs().addAll((Collection )newValue); 424 return; 425 case MappingPackage.MAPPING__OUTPUTS: 426 getOutputs().clear(); 427 getOutputs().addAll((Collection )newValue); 428 return; 429 case MappingPackage.MAPPING__TYPE_MAPPING: 430 setTypeMapping((Mapping)newValue); 431 return; 432 } 433 eDynamicSet(eFeature, newValue); 434 } 435 436 441 public void eUnset(EStructuralFeature eFeature) 442 { 443 switch (eDerivedStructuralFeatureID(eFeature)) 444 { 445 case MappingPackage.MAPPING__HELPER: 446 setHelper((MappingHelper)null); 447 return; 448 case MappingPackage.MAPPING__NESTED: 449 getNested().clear(); 450 return; 451 case MappingPackage.MAPPING__NESTED_IN: 452 setNestedIn((Mapping)null); 453 return; 454 case MappingPackage.MAPPING__INPUTS: 455 getInputs().clear(); 456 return; 457 case MappingPackage.MAPPING__OUTPUTS: 458 getOutputs().clear(); 459 return; 460 case MappingPackage.MAPPING__TYPE_MAPPING: 461 setTypeMapping((Mapping)null); 462 return; 463 } 464 eDynamicUnset(eFeature); 465 } 466 467 472 public boolean eIsSet(EStructuralFeature eFeature) 473 { 474 switch (eDerivedStructuralFeatureID(eFeature)) 475 { 476 case MappingPackage.MAPPING__HELPER: 477 return helper != null; 478 case MappingPackage.MAPPING__NESTED: 479 return nested != null && !nested.isEmpty(); 480 case MappingPackage.MAPPING__NESTED_IN: 481 return getNestedIn() != null; 482 case MappingPackage.MAPPING__INPUTS: 483 return inputs != null && !inputs.isEmpty(); 484 case MappingPackage.MAPPING__OUTPUTS: 485 return outputs != null && !outputs.isEmpty(); 486 case MappingPackage.MAPPING__TYPE_MAPPING: 487 return typeMapping != null; 488 } 489 return eDynamicIsSet(eFeature); 490 } 491 492 public Collection getMappedObjects() 493 { 494 Collection result = new HashSet (); 495 result.addAll(getInputs()); 496 result.addAll(getOutputs()); 497 return result; 498 } 499 500 public MappingRoot getMappingRoot() 501 { 502 Mapping mapping = this; 503 while (mapping != null && !(mapping instanceof MappingRoot)) 504 { 505 mapping = mapping.getNestedIn(); 506 } 507 return (MappingRoot)mapping; 508 } 509 510 public MappingHelper getEffectiveHelper() 511 { 512 MappingHelper helper = getHelper(); 513 if (helper == null && getTypeMapping() != null) 514 { 515 helper = getTypeMapping().getHelper(); 516 } 517 return helper; 518 } 519 520 public boolean isReverse() 521 { 522 Mapping mapping = getNestedIn(); 523 if (mapping != null) 524 { 525 return mapping.isReverse(); 526 } 527 return false; 528 } 529 530 public EList getSenders() 531 { 532 return 533 isReverse() ? 534 getOutputs() : 535 getInputs(); 536 } 537 538 public EList getReceivers() 539 { 540 return 541 isReverse() ? 542 getInputs() : 543 getOutputs(); 544 } 545 546 public EList getTops() 547 { 548 MappingRoot mappingRoot = getMappingRoot(); 549 return 550 mappingRoot == null || mappingRoot.isTopToBottom() ? 551 getInputs() : 552 getOutputs(); 553 } 554 555 public EList getBottoms() 556 { 557 MappingRoot mappingRoot = getMappingRoot(); 558 return 559 mappingRoot == null || mappingRoot.isTopToBottom() ? 560 getOutputs() : 561 getInputs(); 562 } 563 564 567 public static class MappingTreeIterator extends AbstractTreeIterator 568 { 569 572 public MappingTreeIterator(Mapping mapping) 573 { 574 super(mapping); 575 } 576 577 581 public MappingTreeIterator(Mapping mapping, boolean includeRoot) 582 { 583 super(mapping, includeRoot); 584 } 585 586 protected Iterator getChildren(Object o) 587 { 588 return ((Mapping)o).getNested().iterator(); 589 } 590 591 public void remove() 592 { 593 if (nextRemoveIterator == null) 596 { 597 ((Mapping)object).setNestedIn(null); 598 } 599 else 600 { 601 super.remove(); 602 } 603 } 604 } 605 606 public TreeIterator treeIterator() 607 { 608 return new MappingTreeIterator(this); 609 } 610 611 public TreeIterator treeIterator(boolean includeRoot) 612 { 613 return new MappingTreeIterator(this, includeRoot); 614 } 615 616 public String toString() 617 { 618 StringBuffer result = new StringBuffer (super.toString()); 619 result.append("(inputs: "); 620 result.append(getInputs()); 621 result.append(", outputs: "); 622 result.append(getOutputs()); 623 result.append(")"); 624 return result.toString(); 625 } 626 } 628 629 | Popular Tags |