KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > change > impl > ResourceChangeImpl


1 /**
2  * <copyright>
3  * </copyright>
4  *
5  * $Id: ResourceChangeImpl.java,v 1.3 2004/11/08 18:06:32 marcelop Exp $
6  */

7 package org.eclipse.emf.ecore.change.impl;
8
9 import java.util.Collection JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import org.eclipse.emf.common.notify.Notification;
13 import org.eclipse.emf.common.notify.NotificationChain;
14 import org.eclipse.emf.common.util.BasicEList;
15 import org.eclipse.emf.common.util.ECollections;
16 import org.eclipse.emf.common.util.EList;
17 import org.eclipse.emf.common.util.URI;
18 import org.eclipse.emf.ecore.EClass;
19 import org.eclipse.emf.ecore.EStructuralFeature;
20 import org.eclipse.emf.ecore.InternalEObject;
21 import org.eclipse.emf.ecore.change.ChangePackage;
22 import org.eclipse.emf.ecore.change.ListChange;
23 import org.eclipse.emf.ecore.change.ResourceChange;
24 import org.eclipse.emf.ecore.impl.ENotificationImpl;
25 import org.eclipse.emf.ecore.impl.EObjectImpl;
26 import org.eclipse.emf.ecore.resource.Resource;
27 import org.eclipse.emf.ecore.resource.ResourceSet;
28 import org.eclipse.emf.ecore.util.EObjectContainmentEList;
29 import org.eclipse.emf.ecore.util.InternalEList;
30
31 /**
32  * <!-- begin-user-doc -->
33  * An implementation of the model object '<em><b>Resource Change</b></em>'.
34  * <!-- end-user-doc -->
35  * <p>
36  * The following features are implemented:
37  * <ul>
38  * <li>{@link org.eclipse.emf.ecore.change.impl.ResourceChangeImpl#getResourceURI <em>Resource URI</em>}</li>
39  * <li>{@link org.eclipse.emf.ecore.change.impl.ResourceChangeImpl#getResource <em>Resource</em>}</li>
40  * <li>{@link org.eclipse.emf.ecore.change.impl.ResourceChangeImpl#getValue <em>Value</em>}</li>
41  * <li>{@link org.eclipse.emf.ecore.change.impl.ResourceChangeImpl#getListChanges <em>List Changes</em>}</li>
42  * </ul>
43  * </p>
44  *
45  * @generated
46  */

47 public class ResourceChangeImpl extends EObjectImpl implements ResourceChange
48 {
49   /**
50    * The default value of the '{@link #getResourceURI() <em>Resource URI</em>}' attribute.
51    * <!-- begin-user-doc -->
52    * <!-- end-user-doc -->
53    * @see #getResourceURI()
54    * @generated
55    * @ordered
56    */

57   protected static final String JavaDoc RESOURCE_URI_EDEFAULT = null;
58
59   /**
60    * The cached value of the '{@link #getResourceURI() <em>Resource URI</em>}' attribute.
61    * <!-- begin-user-doc -->
62    * <!-- end-user-doc -->
63    * @see #getResourceURI()
64    * @generated
65    * @ordered
66    */

67   protected String JavaDoc resourceURI = RESOURCE_URI_EDEFAULT;
68
69   /**
70    * The default value of the '{@link #getResource() <em>Resource</em>}' attribute.
71    * <!-- begin-user-doc -->
72    * <!-- end-user-doc -->
73    * @see #getResource()
74    * @generated
75    * @ordered
76    */

77   protected static final Resource RESOURCE_EDEFAULT = null;
78
79   /**
80    * The cached value of the '{@link #getResource() <em>Resource</em>}' attribute.
81    * <!-- begin-user-doc -->
82    * <!-- end-user-doc -->
83    * @see #getResource()
84    * @generated
85    * @ordered
86    */

87   protected Resource resource = RESOURCE_EDEFAULT;
88
89   /**
90    * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
91    * <!-- begin-user-doc -->
92    * <!-- end-user-doc -->
93    * @see #getValue()
94    * @generated
95    * @ordered
96    */

97   protected static final EList VALUE_EDEFAULT = null;
98
99   /**
100    * The cached value of the '{@link #getListChanges() <em>List Changes</em>}' containment reference list.
101    * <!-- begin-user-doc -->
102    * <!-- end-user-doc -->
103    * @see #getListChanges()
104    * @generated
105    * @ordered
106    */

107   protected EList listChanges = null;
108
109   protected EList valueField = null;
110
111   /**
112    * <!-- begin-user-doc -->
113    * <!-- end-user-doc -->
114    * @generated
115    */

116   protected ResourceChangeImpl()
117   {
118     super();
119   }
120
121   protected ResourceChangeImpl(Resource resource, EList value)
122   {
123     this();
124     setResource(resource);
125     setValue(value);
126   }
127
128   /**
129    * <!-- begin-user-doc -->
130    * <!-- end-user-doc -->
131    * @generated
132    */

133   protected EClass eStaticClass()
134   {
135     return ChangePackage.eINSTANCE.getResourceChange();
136   }
137
138   /**
139    * <!-- begin-user-doc -->
140    * <!-- end-user-doc -->
141    * @generated
142    */

143   public String JavaDoc getResourceURI()
144   {
145     return resourceURI;
146   }
147
148   /**
149    * <!-- begin-user-doc -->
150    * <!-- end-user-doc -->
151    * @generated
152    */

153   public void setResourceURI(String JavaDoc newResourceURI)
154   {
155     String JavaDoc oldResourceURI = resourceURI;
156     resourceURI = newResourceURI;
157     if (eNotificationRequired())
158       eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.RESOURCE_CHANGE__RESOURCE_URI, oldResourceURI, resourceURI));
159   }
160
161   /**
162    * <!-- begin-user-doc -->
163    * <!-- end-user-doc -->
164    * @generated NOT
165    */

166   public Resource getResource()
167   {
168     if (resource == null)
169     {
170       if (getResourceURI() != null)
171       {
172         Resource changeResource = eResource();
173         if (changeResource != null)
174         {
175           ResourceSet resourceSet = changeResource.getResourceSet();
176           if (resourceSet != null)
177           {
178             resource = resourceSet.getResource(URI.createURI(getResourceURI()), false);
179           }
180         }
181       }
182     }
183     return resource;
184   }
185
186   /**
187    * <!-- begin-user-doc -->
188    * <!-- end-user-doc -->
189    * @generated
190    */

191   public void setResourceGen(Resource newResource)
192   {
193     Resource oldResource = resource;
194     resource = newResource;
195     if (eNotificationRequired())
196       eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.RESOURCE_CHANGE__RESOURCE, oldResource, resource));
197   }
198
199   public void setResource(Resource newResource)
200   {
201     setResourceGen(newResource);
202     setResourceURI(newResource.getURI() == null ? null : newResource.getURI().toString());
203   }
204
205   /**
206    * <!-- begin-user-doc -->
207    * <!-- end-user-doc -->
208    * @generated NOT
209    */

210   public EList getValue()
211   {
212     if (valueField == null)
213     {
214       Resource resource = getResource();
215       if (resource != null)
216       {
217         EList changedList = new BasicEList(resource.getContents());
218         apply(changedList);
219         valueField = changedList; // cache result
220
return changedList;
221       }
222       return ECollections.EMPTY_ELIST;
223     }
224     return valueField;
225   }
226
227   protected void setValue(EList value)
228   {
229     valueField = value;
230   }
231
232   /**
233    * <!-- begin-user-doc -->
234    * <!-- end-user-doc -->
235    * @generated
236    */

237   public EList getListChanges()
238   {
239     if (listChanges == null)
240     {
241       listChanges = new EObjectContainmentEList(ListChange.class, this, ChangePackage.RESOURCE_CHANGE__LIST_CHANGES);
242     }
243     return listChanges;
244   }
245
246   /**
247    * <!-- begin-user-doc -->
248    * <!-- end-user-doc -->
249    * @generated NOT
250    */

251   public void apply()
252   {
253     Resource resource = getResource();
254     if (resource != null && listChanges != null)
255     {
256       apply(resource.getContents());
257     }
258   }
259
260   /**
261    * <!-- begin-user-doc -->
262    * <!-- end-user-doc -->
263    * @generated NOT
264    */

265   public void applyAndReverse()
266   {
267     Resource resource = getResource();
268     if (resource != null && listChanges != null)
269     {
270       EList applyToList = resource.getContents();
271       for (Iterator JavaDoc iter = getListChanges().iterator(); iter.hasNext(); )
272       {
273         ListChange listChange = (ListChange)iter.next();
274         listChange.applyAndReverse(applyToList);
275       }
276       ECollections.reverse(getListChanges());
277       setValue(null);
278     }
279   }
280
281   protected void apply(EList toList)
282   {
283     for (Iterator JavaDoc iter = getListChanges().iterator(); iter.hasNext(); )
284     {
285       ListChange listChange = (ListChange)iter.next();
286       listChange.apply(toList);
287     }
288   }
289
290   /**
291    * <!-- begin-user-doc -->
292    * <!-- end-user-doc -->
293    * @generated
294    */

295   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
296   {
297     if (featureID >= 0)
298     {
299       switch (eDerivedStructuralFeatureID(featureID, baseClass))
300       {
301         case ChangePackage.RESOURCE_CHANGE__LIST_CHANGES:
302           return ((InternalEList)getListChanges()).basicRemove(otherEnd, msgs);
303         default:
304           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
305       }
306     }
307     return eBasicSetContainer(null, featureID, msgs);
308   }
309
310   /**
311    * <!-- begin-user-doc -->
312    * <!-- end-user-doc -->
313    * @generated
314    */

315   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
316   {
317     switch (eDerivedStructuralFeatureID(eFeature))
318     {
319       case ChangePackage.RESOURCE_CHANGE__RESOURCE_URI:
320         return getResourceURI();
321       case ChangePackage.RESOURCE_CHANGE__RESOURCE:
322         return getResource();
323       case ChangePackage.RESOURCE_CHANGE__VALUE:
324         return getValue();
325       case ChangePackage.RESOURCE_CHANGE__LIST_CHANGES:
326         return getListChanges();
327     }
328     return eDynamicGet(eFeature, resolve);
329   }
330
331   /**
332    * <!-- begin-user-doc -->
333    * <!-- end-user-doc -->
334    * @generated
335    */

336   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
337   {
338     switch (eDerivedStructuralFeatureID(eFeature))
339     {
340       case ChangePackage.RESOURCE_CHANGE__RESOURCE_URI:
341         setResourceURI((String JavaDoc)newValue);
342         return;
343       case ChangePackage.RESOURCE_CHANGE__RESOURCE:
344         setResource((Resource)newValue);
345         return;
346       case ChangePackage.RESOURCE_CHANGE__LIST_CHANGES:
347         getListChanges().clear();
348         getListChanges().addAll((Collection JavaDoc)newValue);
349         return;
350     }
351     eDynamicSet(eFeature, newValue);
352   }
353
354   /**
355    * <!-- begin-user-doc -->
356    * <!-- end-user-doc -->
357    * @generated
358    */

359   public void eUnset(EStructuralFeature eFeature)
360   {
361     switch (eDerivedStructuralFeatureID(eFeature))
362     {
363       case ChangePackage.RESOURCE_CHANGE__RESOURCE_URI:
364         setResourceURI(RESOURCE_URI_EDEFAULT);
365         return;
366       case ChangePackage.RESOURCE_CHANGE__RESOURCE:
367         setResource(RESOURCE_EDEFAULT);
368         return;
369       case ChangePackage.RESOURCE_CHANGE__LIST_CHANGES:
370         getListChanges().clear();
371         return;
372     }
373     eDynamicUnset(eFeature);
374   }
375
376   /**
377    * <!-- begin-user-doc -->
378    * <!-- end-user-doc -->
379    * @generated
380    */

381   public boolean eIsSet(EStructuralFeature eFeature)
382   {
383     switch (eDerivedStructuralFeatureID(eFeature))
384     {
385       case ChangePackage.RESOURCE_CHANGE__RESOURCE_URI:
386         return RESOURCE_URI_EDEFAULT == null ? resourceURI != null : !RESOURCE_URI_EDEFAULT.equals(resourceURI);
387       case ChangePackage.RESOURCE_CHANGE__RESOURCE:
388         return RESOURCE_EDEFAULT == null ? resource != null : !RESOURCE_EDEFAULT.equals(resource);
389       case ChangePackage.RESOURCE_CHANGE__VALUE:
390         return VALUE_EDEFAULT == null ? getValue() != null : !VALUE_EDEFAULT.equals(getValue());
391       case ChangePackage.RESOURCE_CHANGE__LIST_CHANGES:
392         return listChanges != null && !listChanges.isEmpty();
393     }
394     return eDynamicIsSet(eFeature);
395   }
396
397   /**
398    * <!-- begin-user-doc -->
399    * <!-- end-user-doc -->
400    * @generated
401    */

402   public String JavaDoc toString()
403   {
404     if (eIsProxy()) return super.toString();
405
406     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
407     result.append(" (resourceURI: ");
408     result.append(resourceURI);
409     result.append(", resource: ");
410     result.append(resource);
411     result.append(')');
412     return result.toString();
413   }
414
415 } //ResourceChangeImpl
416
Popular Tags