KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > impl > MappingImpl


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: MappingImpl.java,v 1.3 2005/06/08 06:21:43 nickb Exp $
16  */

17 package org.eclipse.emf.mapping.impl;
18
19
20 import java.util.Collection JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
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 /**
46  * <!-- begin-user-doc -->
47  * An implementation of the model object '<em><b>Mapping</b></em>'.
48  * <!-- end-user-doc -->
49  * <p>
50  * The following features are implemented:
51  * <ul>
52  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getHelper <em>Helper</em>}</li>
53  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getNested <em>Nested</em>}</li>
54  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getNestedIn <em>Nested In</em>}</li>
55  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getInputs <em>Inputs</em>}</li>
56  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getOutputs <em>Outputs</em>}</li>
57  * <li>{@link org.eclipse.emf.mapping.impl.MappingImpl#getTypeMapping <em>Type Mapping</em>}</li>
58  * </ul>
59  * </p>
60  *
61  * @generated
62  */

63 public class MappingImpl extends EObjectImpl implements Mapping
64 {
65   /**
66    * The cached value of the '{@link #getHelper() <em>Helper</em>}' containment reference.
67    * <!-- begin-user-doc -->
68    * <!-- end-user-doc -->
69    * @see #getHelper()
70    * @generated
71    * @ordered
72    */

73   protected MappingHelper helper = null;
74
75   /**
76    * The cached value of the '{@link #getNested() <em>Nested</em>}' containment reference list.
77    * <!-- begin-user-doc -->
78    * <!-- end-user-doc -->
79    * @see #getNested()
80    * @generated
81    * @ordered
82    */

83   protected EList nested = null;
84
85   /**
86    * The cached value of the '{@link #getInputs() <em>Inputs</em>}' reference list.
87    * <!-- begin-user-doc -->
88    * <!-- end-user-doc -->
89    * @see #getInputs()
90    * @generated
91    * @ordered
92    */

93   protected EList inputs = null;
94
95   /**
96    * The cached value of the '{@link #getOutputs() <em>Outputs</em>}' reference list.
97    * <!-- begin-user-doc -->
98    * <!-- end-user-doc -->
99    * @see #getOutputs()
100    * @generated
101    * @ordered
102    */

103   protected EList outputs = null;
104
105   /**
106    * The cached value of the '{@link #getTypeMapping() <em>Type Mapping</em>}' reference.
107    * <!-- begin-user-doc -->
108    * <!-- end-user-doc -->
109    * @see #getTypeMapping()
110    * @generated
111    * @ordered
112    */

113   protected Mapping typeMapping = null;
114
115   /**
116    * <!-- begin-user-doc -->
117    * <!-- end-user-doc -->
118    * @generated
119    */

120   protected MappingImpl()
121   {
122     super();
123   }
124
125   /**
126    * <!-- begin-user-doc -->
127    * <!-- end-user-doc -->
128    * @generated
129    */

130   protected EClass eStaticClass()
131   {
132     return MappingPackage.eINSTANCE.getMapping();
133   }
134
135   /**
136    * <!-- begin-user-doc -->
137    * <!-- end-user-doc -->
138    * @generated
139    */

140   public MappingHelper getHelper()
141   {
142     return helper;
143   }
144
145   /**
146    * <!-- begin-user-doc -->
147    * <!-- end-user-doc -->
148    * @generated
149    */

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   /**
163    * <!-- begin-user-doc -->
164    * <!-- end-user-doc -->
165    * @generated
166    */

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   /**
184    * <!-- begin-user-doc -->
185    * <!-- end-user-doc -->
186    * @generated
187    */

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   /**
198    * <!-- begin-user-doc -->
199    * <!-- end-user-doc -->
200    * @generated
201    */

202   public Mapping getNestedIn()
203   {
204     if (eContainerFeatureID != MappingPackage.MAPPING__NESTED_IN) return null;
205     return (Mapping)eContainer;
206   }
207
208   /**
209    * <!-- begin-user-doc -->
210    * <!-- end-user-doc -->
211    * @generated
212    */

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 JavaDoc("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   /**
232    * <!-- begin-user-doc -->
233    * <!-- end-user-doc -->
234    * @generated
235    */

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   /**
246    * <!-- begin-user-doc -->
247    * <!-- end-user-doc -->
248    * @generated
249    */

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   /**
260    * <!-- begin-user-doc -->
261    * <!-- end-user-doc -->
262    * @generated
263    */

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   /**
280    * <!-- begin-user-doc -->
281    * <!-- end-user-doc -->
282    * @generated
283    */

284   public Mapping basicGetTypeMapping()
285   {
286     return typeMapping;
287   }
288
289   /**
290    * <!-- begin-user-doc -->
291    * <!-- end-user-doc -->
292    * @generated
293    */

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   /**
303    * <!-- begin-user-doc -->
304    * <!-- end-user-doc -->
305    * @generated
306    */

307   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc 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   /**
333    * <!-- begin-user-doc -->
334    * <!-- end-user-doc -->
335    * @generated
336    */

337   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc 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   /**
357    * <!-- begin-user-doc -->
358    * <!-- end-user-doc -->
359    * @generated
360    */

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   /**
377    * <!-- begin-user-doc -->
378    * <!-- end-user-doc -->
379    * @generated
380    */

381   public Object JavaDoc 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   /**
403    * <!-- begin-user-doc -->
404    * <!-- end-user-doc -->
405    * @generated
406    */

407   public void eSet(EStructuralFeature eFeature, Object JavaDoc 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 JavaDoc)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 JavaDoc)newValue);
424         return;
425       case MappingPackage.MAPPING__OUTPUTS:
426         getOutputs().clear();
427         getOutputs().addAll((Collection JavaDoc)newValue);
428         return;
429       case MappingPackage.MAPPING__TYPE_MAPPING:
430         setTypeMapping((Mapping)newValue);
431         return;
432     }
433     eDynamicSet(eFeature, newValue);
434   }
435
436   /**
437    * <!-- begin-user-doc -->
438    * <!-- end-user-doc -->
439    * @generated
440    */

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   /**
468    * <!-- begin-user-doc -->
469    * <!-- end-user-doc -->
470    * @generated
471    */

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 JavaDoc getMappedObjects()
493   {
494     Collection JavaDoc result = new HashSet JavaDoc();
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   /**
565    * This implements a tree iterator that will iterate over a mapping, all it's nested mappings, all their nested mappings, and so on.
566    */

567   public static class MappingTreeIterator extends AbstractTreeIterator
568   {
569     /**
570      * This creates a tree iterator that will iterate over a mapping, all it's nested mappings, all their nested mappings, and so on.
571      */

572     public MappingTreeIterator(Mapping mapping)
573     {
574       super(mapping);
575     }
576
577     /**
578      * This creates a tree iterator that will iterate over a mapping (but only if includeRoot is true),
579      * all it's nested mappings, all their nested mappings, and so on.
580      */

581     public MappingTreeIterator(Mapping mapping, boolean includeRoot)
582     {
583       super(mapping, includeRoot);
584     }
585
586     protected Iterator JavaDoc getChildren(Object JavaDoc o)
587     {
588       return ((Mapping)o).getNested().iterator();
589     }
590
591     public void remove()
592     {
593       // We either remove the root mapping or we use the iterator that returned the most recent next mapping.
594
//
595
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 JavaDoc toString()
617   {
618     StringBuffer JavaDoc result = new StringBuffer JavaDoc(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 } //MappingImpl
627

628
629
Popular Tags