KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * <copyright>
3  * </copyright>
4  *
5  * $Id: GenTypedElementImpl.java,v 1.3 2005/06/07 21:20:50 davidms Exp $
6  */

7 package org.eclipse.emf.codegen.ecore.genmodel.impl;
8
9 import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
10 import org.eclipse.emf.codegen.ecore.genmodel.GenDataType;
11 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum;
12 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
13 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
14 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
15 import org.eclipse.emf.codegen.ecore.genmodel.GenTypedElement;
16
17 import org.eclipse.emf.ecore.EClass;
18 import org.eclipse.emf.ecore.EClassifier;
19 import org.eclipse.emf.ecore.EDataType;
20 import org.eclipse.emf.ecore.EEnum;
21 import org.eclipse.emf.ecore.EModelElement;
22 import org.eclipse.emf.ecore.ETypedElement;
23
24 /**
25  * <!-- begin-user-doc -->
26  * An implementation of the model object '<em><b>Gen Typed Element</b></em>'.
27  * <!-- end-user-doc -->
28  * <p>
29  * </p>
30  *
31  * @generated
32  */

33 public abstract class GenTypedElementImpl extends GenBaseImpl implements GenTypedElement
34 {
35   /**
36    * <!-- begin-user-doc -->
37    * <!-- end-user-doc -->
38    * @generated
39    */

40   protected GenTypedElementImpl()
41   {
42     super();
43   }
44
45   /**
46    * <!-- begin-user-doc -->
47    * <!-- end-user-doc -->
48    * @generated
49    */

50   protected EClass eStaticClass()
51   {
52     return GenModelPackage.eINSTANCE.getGenTypedElement();
53   }
54
55   public abstract ETypedElement getEcoreTypedElement();
56
57   public EModelElement getEcoreModelElement()
58   {
59     return getEcoreTypedElement();
60   }
61
62   public GenPackage getTypeGenPackage()
63   {
64     return findGenPackage(getEcoreTypedElement().getEType().getEPackage());
65   }
66
67   public String JavaDoc getTypeClassifierAccessorName()
68   {
69     return findGenClassifier(getEcoreTypedElement().getEType()).getClassifierAccessorName();
70   }
71
72   /**
73    * @deprecated As of EMF 2.1, replaced by {@link #getTypeClassifierAccessorName}.
74    */

75   public String JavaDoc getTypeClassifier()
76   {
77     return getTypeClassifierAccessorName();
78   }
79
80   public String JavaDoc getType()
81   {
82     if (isFeatureMapType()) return getEffectiveFeatureMapWrapperInterface();
83     if (isMapType()) return getEffectiveMapType();
84     if (isListType()) return getEffectiveListType();
85     if (isEObjectType()) return getEffectiveEObjectType();
86     return getType(getEcoreTypedElement().getEType(), false);
87   }
88
89   public String JavaDoc getImportedType()
90   {
91     if (isFeatureMapType()) return getGenModel().getImportedName(getEffectiveFeatureMapWrapperInterface());
92     if (isMapType()) return getGenModel().getImportedName(getEffectiveMapType());
93     if (isListType()) return getGenModel().getImportedName(getEffectiveListType());
94     if (isEObjectType()) return getGenModel().getImportedName(getEffectiveEObjectType());
95     return getImportedType(getEcoreTypedElement().getEType(), false);
96   }
97
98   public String JavaDoc getObjectType()
99   {
100     if (isFeatureMapType()) return getGenModel().getImportedName(getEffectiveFeatureMapWrapperInterface());
101     if (isMapType()) return getGenModel().getImportedName(getEffectiveMapType());
102     if (isListType()) return getGenModel().getImportedName(getEffectiveListType());
103     if (isEObjectType()) return getGenModel().getImportedName(getEffectiveEObjectType());
104     return getImportedType(getEcoreTypedElement().getEType(), true);
105   }
106
107   public String JavaDoc getImportedInternalType()
108   {
109     if (isFeatureMapType()) return getImportedEffectiveFeatureMapWrapperInternalInterface();
110     if (isMapType()) return getGenModel().getImportedName("org.eclipse.emf.common.util.EMap");
111     if (isListType()) return getGenModel().getImportedName("org.eclipse.emf.common.util.EList");
112     return getImportedType(getEcoreTypedElement().getEType(), false);
113   }
114
115   public boolean isFeatureMapType()
116   {
117     EClassifier type = getEcoreTypedElement().getEType();
118     return type != null && isFeatureMapEntry(getEcoreTypedElement().getEType().getInstanceClassName());
119   }
120
121   protected static boolean isFeatureMapEntry(String JavaDoc name)
122   {
123     return "org.eclipse.emf.ecore.util.FeatureMap.Entry".equals(name) || "org.eclipse.emf.ecore.util.FeatureMap$Entry".equals(name);
124   }
125
126   public boolean isWrappedFeatureMapType()
127   {
128     return isFeatureMapType() &&
129     !isBlank(getGenModel().getFeatureMapWrapperInterface()) &&
130     !isBlank(getGenModel().getFeatureMapWrapperInternalInterface()) &&
131     !isBlank(getGenModel().getFeatureMapWrapperClass());
132   }
133
134   /**
135    * @deprecated As of EMF 2.1, replaced by {@link #isWrappedFeatureMapType}.
136    */

137   public boolean isFeatureMapWrapped()
138   {
139     return isWrappedFeatureMapType();
140   }
141
142   public boolean isEffectiveSuppressEMFTypes()
143   {
144     return super.isEffectiveSuppressEMFTypes();
145   }
146
147   public String JavaDoc getImportedEffectiveFeatureMapWrapperInternalInterface()
148   {
149     return super.getImportedEffectiveFeatureMapWrapperInternalInterface();
150   }
151
152   public String JavaDoc getImportedEffectiveFeatureMapWrapperClass()
153   {
154     return super.getImportedEffectiveFeatureMapWrapperClass();
155   }
156
157   public boolean isListType()
158   {
159     return getEcoreTypedElement().isMany() || isFeatureMapType();
160   }
161
162   public String JavaDoc getListItemType()
163   {
164     return getImportedType(getEcoreTypedElement().getEType(), true);
165   }
166
167   public String JavaDoc getQualifiedListItemType()
168   {
169     return getType(getEcoreTypedElement().getEType(), true).replace('$', '.');
170   }
171
172   public boolean isMapType()
173   {
174     return isListType() && getMapGenClass() != null;
175   }
176
177   public GenClass getMapEntryTypeGenClass()
178   {
179     EClassifier eType = getEcoreTypedElement().getEType();
180     if (eType instanceof EClass && isJavaUtilMapEntry(eType.getInstanceClassName()))
181     {
182       GenClass genClass = findGenClass((EClass)eType);
183       if (genClass.isMapEntry())
184       {
185         return genClass;
186       }
187     }
188     return null;
189   }
190
191   public String JavaDoc getImportedMapEntryType()
192   {
193     GenClass genClass = getMapEntryTypeGenClass();
194     return genClass == null ? null : genClass.getImportedClassName();
195   }
196
197   /**
198    * @deprecated As of EMF 2.1, replaced by {@link #getMapEntryTypeGenClass}.
199    */

200   public GenClass getMapGenClass()
201   {
202     return getMapEntryTypeGenClass();
203   }
204
205   /**
206    * @deprecated As of EMF 2.1, replaced by {@link #getImportedMapEntryType}.
207    */

208   public String JavaDoc getMapItemType()
209   {
210     return getImportedMapEntryType();
211   }
212
213   protected boolean isEObjectType()
214   {
215     EClassifier type = getEcoreTypedElement().getEType();
216     return type instanceof EClass && findGenClass((EClass)type).isEObject();
217   }
218
219   protected boolean isEObjectExtensionType()
220   {
221     EClassifier type = getEcoreTypedElement().getEType();
222     return type instanceof EClass && findGenClass((EClass)type).isEObjectExtension();
223   }
224
225   public String JavaDoc getEObjectCast()
226   {
227     return isEObjectExtensionType() && !isEffectiveSuppressEMFTypes() ?
228       "" : "(" + getGenModel().getImportedName("org.eclipse.emf.ecore.EObject") + ")";
229   }
230
231   public String JavaDoc getInternalTypeCast()
232   {
233     return isEObjectType() && isEffectiveSuppressEMFTypes() ?
234       "(" + getGenModel().getImportedName("org.eclipse.emf.ecore.EObject") + ")" : "";
235   }
236
237   public boolean isPrimitiveType()
238   {
239     return !isListType() && isPrimitiveType(getEcoreTypedElement().getEType());
240   }
241
242   public String JavaDoc getPrimitiveValueFunction()
243   {
244     Class JavaDoc instanceClass = getInstanceClass(getEcoreTypedElement().getEType());
245     if (instanceClass == java.lang.Boolean.TYPE)
246       return "booleanValue";
247     if (instanceClass == java.lang.Byte.TYPE)
248       return "byteValue";
249     if (instanceClass == java.lang.Character.TYPE)
250       return "charValue";
251     if (instanceClass == java.lang.Double.TYPE)
252       return "doubleValue";
253     if (instanceClass == java.lang.Float.TYPE)
254       return "floatValue";
255     if (instanceClass == java.lang.Integer.TYPE)
256       return "intValue";
257     if (instanceClass == java.lang.Long.TYPE)
258       return "longValue";
259     if (instanceClass == java.lang.Short.TYPE)
260       return "shortValue";
261     return null;
262   }
263
264   public boolean isBooleanType()
265   {
266     return isPrimitiveType() && getInstanceClass(getEcoreTypedElement().getEType()) == java.lang.Boolean.TYPE;
267   }
268
269   public boolean isStringType()
270   {
271     return !isListType() && getInstanceClass(getEcoreTypedElement().getEType()) == java.lang.String JavaDoc.class;
272   }
273
274   // Like isStringType(), but still returns true even if multiplicity-many.
275
//
276
public boolean isStringBasedType()
277   {
278     return getInstanceClass(getEcoreTypedElement().getEType()) == java.lang.String JavaDoc.class;
279   }
280
281   public boolean isEnumType()
282   {
283     return !isListType() && getEcoreTypedElement().getEType() instanceof EEnum;
284   }
285
286   public boolean isEnumBasedType()
287   {
288     return getEcoreTypedElement().getEType() instanceof EEnum;
289   }
290
291   public GenEnum getTypeGenEnum()
292   {
293     EClassifier eType = getEcoreTypedElement().getEType();
294     return eType instanceof EEnum ? findGenEnum((EEnum)eType) : null;
295   }
296
297   public GenDataType getTypeGenDataType()
298   {
299     EClassifier eType = getEcoreTypedElement().getEType();
300     return eType instanceof EDataType ? findGenDataType((EDataType)eType) : null;
301   }
302
303   public GenClass getTypeGenClass()
304   {
305     EClassifier eType = getEcoreTypedElement().getEType();
306     return eType instanceof EClass ? findGenClass((EClass)eType) : null;
307   }
308
309   /**
310    * @deprecated As of EMF 2.1, replaced by {@link #getTypeGenEnum}.
311    */

312   public GenEnum getGenEnumType()
313   {
314     return getTypeGenEnum();
315   }
316
317   /**
318    * @deprecated As of EMF 2.1, replaced by {@link #getTypeGenDataType}.
319    */

320   public GenDataType getGenDataTypeType()
321   {
322     return getTypeGenDataType();
323   }
324
325   /**
326    * @deprecated As of EMF 2.1, replaced by {@link #getTypeGenClass}.
327    */

328   public GenClass getGenClassType()
329   {
330     return getTypeGenClass();
331   }
332
333   public String JavaDoc getLowerBound()
334   {
335     return String.valueOf(getEcoreTypedElement().getLowerBound());
336   }
337
338   public String JavaDoc getUpperBound()
339   {
340     return String.valueOf(getEcoreTypedElement().getUpperBound());
341   }
342
343   public boolean isUnique()
344   {
345     return getEcoreTypedElement().isUnique();
346   }
347
348   public String JavaDoc getUniqueFlag()
349   {
350     String JavaDoc result = !isUnique() ? "!" : "";
351     return result + "IS_UNIQUE";
352   }
353
354   public String JavaDoc getOrderedFlag()
355   {
356     String JavaDoc result = !getEcoreTypedElement().isOrdered() ? "!" : "";
357     return result + "IS_ORDERED";
358   }
359
360   protected void appendModelSetting(StringBuffer JavaDoc result, boolean qualified, String JavaDoc name, String JavaDoc value)
361   {
362     appendModelSetting(result, qualified ? getEcoreTypedElement().getName() : null, name, value);
363   }
364
365   protected String JavaDoc getMapModelInfo(boolean qualified, boolean includeFeatures)
366   {
367     GenClass mapGenClass = getMapEntryTypeGenClass();
368     if (mapGenClass != null)
369     {
370       StringBuffer JavaDoc result = new StringBuffer JavaDoc();
371
372       appendModelSetting(result, qualified, "mapType",
373         mapGenClass.getGenPackage().getInterfacePackageName() + '.' + mapGenClass.getEcoreClass().getName());
374
375       if (includeFeatures)
376       {
377         GenFeature keyFeature = mapGenClass.getMapEntryKeyFeature();
378         appendModelSetting(result, qualified, "keyType", getType(keyFeature.getEcoreFeature().getEType(), false));
379   
380         GenFeature valueFeature = mapGenClass.getMapEntryValueFeature();
381         appendModelSetting(result, qualified, "valueType", getType(valueFeature.getEcoreFeature().getEType(), false));
382       }
383
384       return result.toString();
385     }
386
387     return null;
388   }
389
390   protected String JavaDoc getMultiplicityModelInfo(boolean qualified)
391   {
392     ETypedElement eTypedElement = getEcoreTypedElement();
393     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
394
395     int lowerBound = eTypedElement.getLowerBound();
396     if (lowerBound == 1)
397     {
398       appendModelSetting(result, qualified, "required", "true");
399     }
400     else if (lowerBound > 1)
401     {
402       appendModelSetting(result, qualified, "lower", Integer.toString(lowerBound));
403     }
404     
405     int upperBound = eTypedElement.getUpperBound();
406     if (upperBound > 1 || upperBound < -1)
407     {
408       appendModelSetting(result, qualified, "upper", Integer.toString(eTypedElement.getUpperBound()));
409     }
410     else if (upperBound == 1)
411     {
412       String JavaDoc typeName = getType(eTypedElement.getEType(), false);
413       if ("org.eclipse.emf.common.util.EList".equals(typeName) || "java.util.List".equals(typeName))
414       {
415         appendModelSetting(result, qualified, "many", "false");
416       }
417     }
418     else if ((qualified || isFeatureMapType()) && upperBound == -1)
419     {
420       appendModelSetting(result, qualified, "many", "true");
421     }
422
423     return result.toString();
424   }
425
426 } //GenTypedElementImpl
427
Popular Tags