KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > ecore > genmodel > impl > GenParameterImpl


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: GenParameterImpl.java,v 1.6 2005/06/08 06:18:44 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.impl;
18
19
20 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
21 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
22 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
23 import org.eclipse.emf.codegen.ecore.genmodel.GenParameter;
24 import org.eclipse.emf.common.notify.Notification;
25 import org.eclipse.emf.common.notify.NotificationChain;
26 import org.eclipse.emf.ecore.EClass;
27 import org.eclipse.emf.ecore.EClassifier;
28 import org.eclipse.emf.ecore.EDataType;
29 import org.eclipse.emf.ecore.EEnum;
30 import org.eclipse.emf.ecore.EParameter;
31 import org.eclipse.emf.ecore.EStructuralFeature;
32 import org.eclipse.emf.ecore.ETypedElement;
33 import org.eclipse.emf.ecore.InternalEObject;
34 import org.eclipse.emf.ecore.impl.ENotificationImpl;
35 import org.eclipse.emf.ecore.util.EcoreUtil;
36
37
38 /**
39  * <!-- begin-user-doc -->
40  * An implementation of the model object '<em><b>Gen Parameter</b></em>'.
41  * <!-- end-user-doc -->
42  * <p>
43  * The following features are implemented:
44  * <ul>
45  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenParameterImpl#getGenOperation <em>Gen Operation</em>}</li>
46  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenParameterImpl#getEcoreParameter <em>Ecore Parameter</em>}</li>
47  * </ul>
48  * </p>
49  *
50  * @generated
51  */

52 public class GenParameterImpl extends GenTypedElementImpl implements GenParameter
53 {
54   /**
55    * The cached value of the '{@link #getEcoreParameter() <em>Ecore Parameter</em>}' reference.
56    * <!-- begin-user-doc -->
57    * <!-- end-user-doc -->
58    * @see #getEcoreParameter()
59    * @generated
60    * @ordered
61    */

62   protected EParameter ecoreParameter = null;
63
64   /**
65    * <!-- begin-user-doc -->
66    * <!-- end-user-doc -->
67    * @generated modifiable
68    */

69   protected GenParameterImpl()
70   {
71     super();
72   }
73
74   /**
75    * <!-- begin-user-doc -->
76    * <!-- end-user-doc -->
77    * @generated
78    */

79   protected EClass eStaticClass()
80   {
81     return GenModelPackage.eINSTANCE.getGenParameter();
82   }
83
84   /**
85    * <!-- begin-user-doc -->
86    * <!-- end-user-doc -->
87    * @generated
88    */

89   public GenOperation getGenOperation()
90   {
91     if (eContainerFeatureID != GenModelPackage.GEN_PARAMETER__GEN_OPERATION) return null;
92     return (GenOperation)eContainer;
93   }
94
95   /**
96    * <!-- begin-user-doc -->
97    * <!-- end-user-doc -->
98    * @generated
99    */

100   public void setGenOperation(GenOperation newGenOperation)
101   {
102     if (newGenOperation != eContainer || (eContainerFeatureID != GenModelPackage.GEN_PARAMETER__GEN_OPERATION && newGenOperation != null))
103     {
104       if (EcoreUtil.isAncestor(this, newGenOperation))
105         throw new IllegalArgumentException JavaDoc("Recursive containment not allowed for " + toString());
106       NotificationChain msgs = null;
107       if (eContainer != null)
108         msgs = eBasicRemoveFromContainer(msgs);
109       if (newGenOperation != null)
110         msgs = ((InternalEObject)newGenOperation).eInverseAdd(this, GenModelPackage.GEN_OPERATION__GEN_PARAMETERS, GenOperation.class, msgs);
111       msgs = eBasicSetContainer((InternalEObject)newGenOperation, GenModelPackage.GEN_PARAMETER__GEN_OPERATION, msgs);
112       if (msgs != null) msgs.dispatch();
113     }
114     else if (eNotificationRequired())
115       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PARAMETER__GEN_OPERATION, newGenOperation, newGenOperation));
116   }
117
118   /**
119    * <!-- begin-user-doc -->
120    * <!-- end-user-doc -->
121    * @generated
122    */

123   public EParameter getEcoreParameter()
124   {
125     if (ecoreParameter != null && ecoreParameter.eIsProxy())
126     {
127       EParameter oldEcoreParameter = ecoreParameter;
128       ecoreParameter = (EParameter)eResolveProxy((InternalEObject)ecoreParameter);
129       if (ecoreParameter != oldEcoreParameter)
130       {
131         if (eNotificationRequired())
132           eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER, oldEcoreParameter, ecoreParameter));
133       }
134     }
135     return ecoreParameter;
136   }
137
138   /**
139    * <!-- begin-user-doc -->
140    * <!-- end-user-doc -->
141    * @generated
142    */

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

153   public void setEcoreParameter(EParameter newEcoreParameter)
154   {
155     EParameter oldEcoreParameter = ecoreParameter;
156     ecoreParameter = newEcoreParameter;
157     if (eNotificationRequired())
158       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER, oldEcoreParameter, ecoreParameter));
159   }
160
161   /**
162    * <!-- begin-user-doc -->
163    * <!-- end-user-doc -->
164    * @generated
165    */

166   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
167   {
168     if (featureID >= 0)
169     {
170       switch (eDerivedStructuralFeatureID(featureID, baseClass))
171       {
172         case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
173           if (eContainer != null)
174             msgs = eBasicRemoveFromContainer(msgs);
175           return eBasicSetContainer(otherEnd, GenModelPackage.GEN_PARAMETER__GEN_OPERATION, msgs);
176         default:
177           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
178       }
179     }
180     if (eContainer != null)
181       msgs = eBasicRemoveFromContainer(msgs);
182     return eBasicSetContainer(otherEnd, featureID, msgs);
183   }
184
185   /**
186    * <!-- begin-user-doc -->
187    * <!-- end-user-doc -->
188    * @generated
189    */

190   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
191   {
192     if (featureID >= 0)
193     {
194       switch (eDerivedStructuralFeatureID(featureID, baseClass))
195       {
196         case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
197           return eBasicSetContainer(null, GenModelPackage.GEN_PARAMETER__GEN_OPERATION, msgs);
198         default:
199           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
200       }
201     }
202     return eBasicSetContainer(null, featureID, msgs);
203   }
204
205   /**
206    * <!-- begin-user-doc -->
207    * <!-- end-user-doc -->
208    * @generated
209    */

210   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
211   {
212     if (eContainerFeatureID >= 0)
213     {
214       switch (eContainerFeatureID)
215       {
216         case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
217           return eContainer.eInverseRemove(this, GenModelPackage.GEN_OPERATION__GEN_PARAMETERS, GenOperation.class, msgs);
218         default:
219           return eDynamicBasicRemoveFromContainer(msgs);
220       }
221     }
222     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
223   }
224
225   /**
226    * <!-- begin-user-doc -->
227    * <!-- end-user-doc -->
228    * @generated
229    */

230   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
231   {
232     switch (eDerivedStructuralFeatureID(eFeature))
233     {
234       case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
235         return getGenOperation();
236       case GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER:
237         if (resolve) return getEcoreParameter();
238         return basicGetEcoreParameter();
239     }
240     return eDynamicGet(eFeature, resolve);
241   }
242
243   /**
244    * <!-- begin-user-doc -->
245    * <!-- end-user-doc -->
246    * @generated
247    */

248   public boolean eIsSet(EStructuralFeature eFeature)
249   {
250     switch (eDerivedStructuralFeatureID(eFeature))
251     {
252       case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
253         return getGenOperation() != null;
254       case GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER:
255         return ecoreParameter != null;
256     }
257     return eDynamicIsSet(eFeature);
258   }
259
260   /**
261    * <!-- begin-user-doc -->
262    * <!-- end-user-doc -->
263    * @generated
264    */

265   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
266   {
267     switch (eDerivedStructuralFeatureID(eFeature))
268     {
269       case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
270         setGenOperation((GenOperation)newValue);
271         return;
272       case GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER:
273         setEcoreParameter((EParameter)newValue);
274         return;
275     }
276     eDynamicSet(eFeature, newValue);
277   }
278
279   /**
280    * <!-- begin-user-doc -->
281    * <!-- end-user-doc -->
282    * @generated
283    */

284   public void eUnset(EStructuralFeature eFeature)
285   {
286     switch (eDerivedStructuralFeatureID(eFeature))
287     {
288       case GenModelPackage.GEN_PARAMETER__GEN_OPERATION:
289         setGenOperation((GenOperation)null);
290         return;
291       case GenModelPackage.GEN_PARAMETER__ECORE_PARAMETER:
292         setEcoreParameter((EParameter)null);
293         return;
294     }
295     eDynamicUnset(eFeature);
296   }
297
298   public ETypedElement getEcoreTypedElement()
299   {
300     return getEcoreParameter();
301   }
302
303   public String JavaDoc getName()
304   {
305     return getEcoreParameter().getName();
306   }
307
308   public GenPackage getGenPackage()
309   {
310     return getGenOperation().getGenPackage();
311   }
312
313   public void initialize(EParameter eParameter)
314   {
315     setEcoreParameter(eParameter);
316   }
317
318   public boolean reconcile(GenParameter oldGenParameterVersion)
319   {
320     if (getEcoreParameter().getName().equals(oldGenParameterVersion.getEcoreParameter().getName()))
321     {
322       reconcileSettings(oldGenParameterVersion);
323       return true;
324     }
325     else
326     {
327       return false;
328     }
329   }
330
331   public String JavaDoc getQualifiedModelInfo()
332   {
333     return getModelInfo(true);
334   }
335
336   protected String JavaDoc getModelInfo(boolean qualified)
337   {
338     EParameter eParameter = getEcoreParameter();
339     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
340
341     String JavaDoc mapModelInfo = getMapModelInfo(qualified, true);
342     if (mapModelInfo != null)
343     {
344       result.append(mapModelInfo);
345     }
346     else
347     {
348       if (eParameter.isMany() && !isFeatureMapType())
349       {
350         appendModelSetting(result, qualified, "type", getType(eParameter.getEType(), false));
351       }
352
353       EClassifier type = eParameter.getEType();
354       if (type instanceof EDataType && !(type instanceof EEnum))
355       {
356         GenPackage genPackage = findGenPackage(type.getEPackage());
357         if (genPackage != null && (isFeatureMapType() || !genPackage.isEcorePackage()))
358         {
359           appendModelSetting(result, qualified, "dataType", genPackage.getInterfacePackageName() + '.' + type.getName());
360         }
361       }
362       
363       if (!eParameter.isUnique())
364       {
365         appendModelSetting(result, qualified, "unique", "false");
366       }
367
368       result.append(getMultiplicityModelInfo(qualified));
369
370       if (!eParameter.isOrdered())
371       {
372         appendModelSetting(result, qualified, "ordered", "false");
373       }
374     }
375
376     appendAnnotationInfo(result, qualified, eParameter, DEFAULT_ANNOTATION_FILTER);
377     return result.toString().trim();
378   }
379
380   protected void reconcileSettings(GenParameter oldGenParameterVersion)
381   {
382   }
383
384   public boolean reconcile()
385   {
386     EParameter eParameter = getEcoreParameter();
387     if (eParameter == null || eParameter.eIsProxy() || eParameter.eResource() == null)
388     {
389       return false;
390     }
391     else
392     {
393       return true;
394     }
395   }
396 }
397
Popular Tags