KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2005 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: GenOperationImpl.java,v 1.15 2005/06/22 19:56:46 davidms Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.impl;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
26 import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
27 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
28 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
29 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
30 import org.eclipse.emf.codegen.ecore.genmodel.GenParameter;
31 import org.eclipse.emf.common.notify.Notification;
32 import org.eclipse.emf.common.notify.NotificationChain;
33 import org.eclipse.emf.common.util.EList;
34 import org.eclipse.emf.ecore.EAnnotation;
35 import org.eclipse.emf.ecore.EClass;
36 import org.eclipse.emf.ecore.EClassifier;
37 import org.eclipse.emf.ecore.EDataType;
38 import org.eclipse.emf.ecore.EEnum;
39 import org.eclipse.emf.ecore.EOperation;
40 import org.eclipse.emf.ecore.EParameter;
41 import org.eclipse.emf.ecore.EStructuralFeature;
42 import org.eclipse.emf.ecore.ETypedElement;
43 import org.eclipse.emf.ecore.InternalEObject;
44 import org.eclipse.emf.ecore.impl.ENotificationImpl;
45 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
46 import org.eclipse.emf.ecore.util.EcoreUtil;
47 import org.eclipse.emf.ecore.util.InternalEList;
48
49
50 /**
51  * <!-- begin-user-doc -->
52  * An implementation of the model object '<em><b>Gen Operation</b></em>'.
53  * <!-- end-user-doc -->
54  * <p>
55  * The following features are implemented:
56  * <ul>
57  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenOperationImpl#getGenClass <em>Gen Class</em>}</li>
58  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenOperationImpl#getEcoreOperation <em>Ecore Operation</em>}</li>
59  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenOperationImpl#getGenParameters <em>Gen Parameters</em>}</li>
60  * </ul>
61  * </p>
62  *
63  * @generated
64  */

65 public class GenOperationImpl extends GenTypedElementImpl implements GenOperation
66 {
67   /**
68    * The cached value of the '{@link #getEcoreOperation() <em>Ecore Operation</em>}' reference.
69    * <!-- begin-user-doc -->
70    * <!-- end-user-doc -->
71    * @see #getEcoreOperation()
72    * @generated
73    * @ordered
74    */

75   protected EOperation ecoreOperation = null;
76
77   /**
78    * The cached value of the '{@link #getGenParameters() <em>Gen Parameters</em>}' containment reference list.
79    * <!-- begin-user-doc -->
80    * <!-- end-user-doc -->
81    * @see #getGenParameters()
82    * @generated
83    * @ordered
84    */

85   protected EList genParameters = null;
86
87   /**
88    * <!-- begin-user-doc -->
89    * <!-- end-user-doc -->
90    * @generated modifiable
91    */

92   protected GenOperationImpl()
93   {
94     super();
95   }
96
97   /**
98    * <!-- begin-user-doc -->
99    * <!-- end-user-doc -->
100    * @generated
101    */

102   protected EClass eStaticClass()
103   {
104     return GenModelPackage.eINSTANCE.getGenOperation();
105   }
106
107   /**
108    * <!-- begin-user-doc -->
109    * <!-- end-user-doc -->
110    * @generated
111    */

112   public GenClass getGenClass()
113   {
114     if (eContainerFeatureID != GenModelPackage.GEN_OPERATION__GEN_CLASS) return null;
115     return (GenClass)eContainer;
116   }
117
118   /**
119    * <!-- begin-user-doc -->
120    * <!-- end-user-doc -->
121    * @generated
122    */

123   public void setGenClass(GenClass newGenClass)
124   {
125     if (newGenClass != eContainer || (eContainerFeatureID != GenModelPackage.GEN_OPERATION__GEN_CLASS && newGenClass != null))
126     {
127       if (EcoreUtil.isAncestor(this, newGenClass))
128         throw new IllegalArgumentException JavaDoc("Recursive containment not allowed for " + toString());
129       NotificationChain msgs = null;
130       if (eContainer != null)
131         msgs = eBasicRemoveFromContainer(msgs);
132       if (newGenClass != null)
133         msgs = ((InternalEObject)newGenClass).eInverseAdd(this, GenModelPackage.GEN_CLASS__GEN_OPERATIONS, GenClass.class, msgs);
134       msgs = eBasicSetContainer((InternalEObject)newGenClass, GenModelPackage.GEN_OPERATION__GEN_CLASS, msgs);
135       if (msgs != null) msgs.dispatch();
136     }
137     else if (eNotificationRequired())
138       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_OPERATION__GEN_CLASS, newGenClass, newGenClass));
139   }
140
141   /**
142    * <!-- begin-user-doc -->
143    * <!-- end-user-doc -->
144    * @generated
145    */

146   public EOperation getEcoreOperation()
147   {
148     if (ecoreOperation != null && ecoreOperation.eIsProxy())
149     {
150       EOperation oldEcoreOperation = ecoreOperation;
151       ecoreOperation = (EOperation)eResolveProxy((InternalEObject)ecoreOperation);
152       if (ecoreOperation != oldEcoreOperation)
153       {
154         if (eNotificationRequired())
155           eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_OPERATION__ECORE_OPERATION, oldEcoreOperation, ecoreOperation));
156       }
157     }
158     return ecoreOperation;
159   }
160
161   /**
162    * <!-- begin-user-doc -->
163    * <!-- end-user-doc -->
164    * @generated
165    */

166   public EOperation basicGetEcoreOperation()
167   {
168     return ecoreOperation;
169   }
170
171   /**
172    * <!-- begin-user-doc -->
173    * <!-- end-user-doc -->
174    * @generated
175    */

176   public void setEcoreOperation(EOperation newEcoreOperation)
177   {
178     EOperation oldEcoreOperation = ecoreOperation;
179     ecoreOperation = newEcoreOperation;
180     if (eNotificationRequired())
181       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_OPERATION__ECORE_OPERATION, oldEcoreOperation, ecoreOperation));
182   }
183
184   /**
185    * <!-- begin-user-doc -->
186    * <!-- end-user-doc -->
187    * @generated
188    */

189   public EList getGenParameters()
190   {
191     if (genParameters == null)
192     {
193       genParameters = new EObjectContainmentWithInverseEList(GenParameter.class, this, GenModelPackage.GEN_OPERATION__GEN_PARAMETERS, GenModelPackage.GEN_PARAMETER__GEN_OPERATION);
194     }
195     return genParameters;
196   }
197
198   /**
199    * <!-- begin-user-doc -->
200    * <!-- end-user-doc -->
201    * @generated
202    */

203   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
204   {
205     if (featureID >= 0)
206     {
207       switch (eDerivedStructuralFeatureID(featureID, baseClass))
208       {
209         case GenModelPackage.GEN_OPERATION__GEN_CLASS:
210           if (eContainer != null)
211             msgs = eBasicRemoveFromContainer(msgs);
212           return eBasicSetContainer(otherEnd, GenModelPackage.GEN_OPERATION__GEN_CLASS, msgs);
213         case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
214           return ((InternalEList)getGenParameters()).basicAdd(otherEnd, msgs);
215         default:
216           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
217       }
218     }
219     if (eContainer != null)
220       msgs = eBasicRemoveFromContainer(msgs);
221     return eBasicSetContainer(otherEnd, featureID, msgs);
222   }
223
224   /**
225    * <!-- begin-user-doc -->
226    * <!-- end-user-doc -->
227    * @generated
228    */

229   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
230   {
231     if (featureID >= 0)
232     {
233       switch (eDerivedStructuralFeatureID(featureID, baseClass))
234       {
235         case GenModelPackage.GEN_OPERATION__GEN_CLASS:
236           return eBasicSetContainer(null, GenModelPackage.GEN_OPERATION__GEN_CLASS, msgs);
237         case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
238           return ((InternalEList)getGenParameters()).basicRemove(otherEnd, msgs);
239         default:
240           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
241       }
242     }
243     return eBasicSetContainer(null, featureID, msgs);
244   }
245
246   /**
247    * <!-- begin-user-doc -->
248    * <!-- end-user-doc -->
249    * @generated
250    */

251   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
252   {
253     if (eContainerFeatureID >= 0)
254     {
255       switch (eContainerFeatureID)
256       {
257         case GenModelPackage.GEN_OPERATION__GEN_CLASS:
258           return eContainer.eInverseRemove(this, GenModelPackage.GEN_CLASS__GEN_OPERATIONS, GenClass.class, msgs);
259         default:
260           return eDynamicBasicRemoveFromContainer(msgs);
261       }
262     }
263     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
264   }
265
266   /**
267    * <!-- begin-user-doc -->
268    * <!-- end-user-doc -->
269    * @generated
270    */

271   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
272   {
273     switch (eDerivedStructuralFeatureID(eFeature))
274     {
275       case GenModelPackage.GEN_OPERATION__GEN_CLASS:
276         return getGenClass();
277       case GenModelPackage.GEN_OPERATION__ECORE_OPERATION:
278         if (resolve) return getEcoreOperation();
279         return basicGetEcoreOperation();
280       case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
281         return getGenParameters();
282     }
283     return eDynamicGet(eFeature, resolve);
284   }
285
286   /**
287    * <!-- begin-user-doc -->
288    * <!-- end-user-doc -->
289    * @generated
290    */

291   public boolean eIsSet(EStructuralFeature eFeature)
292   {
293     switch (eDerivedStructuralFeatureID(eFeature))
294     {
295       case GenModelPackage.GEN_OPERATION__GEN_CLASS:
296         return getGenClass() != null;
297       case GenModelPackage.GEN_OPERATION__ECORE_OPERATION:
298         return ecoreOperation != null;
299       case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
300         return genParameters != null && !genParameters.isEmpty();
301     }
302     return eDynamicIsSet(eFeature);
303   }
304
305   /**
306    * <!-- begin-user-doc -->
307    * <!-- end-user-doc -->
308    * @generated
309    */

310   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
311   {
312     switch (eDerivedStructuralFeatureID(eFeature))
313     {
314       case GenModelPackage.GEN_OPERATION__GEN_CLASS:
315         setGenClass((GenClass)newValue);
316         return;
317       case GenModelPackage.GEN_OPERATION__ECORE_OPERATION:
318         setEcoreOperation((EOperation)newValue);
319         return;
320       case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
321         getGenParameters().clear();
322         getGenParameters().addAll((Collection JavaDoc)newValue);
323         return;
324     }
325     eDynamicSet(eFeature, newValue);
326   }
327
328   /**
329    * <!-- begin-user-doc -->
330    * <!-- end-user-doc -->
331    * @generated
332    */

333   public void eUnset(EStructuralFeature eFeature)
334   {
335     switch (eDerivedStructuralFeatureID(eFeature))
336     {
337       case GenModelPackage.GEN_OPERATION__GEN_CLASS:
338         setGenClass((GenClass)null);
339         return;
340       case GenModelPackage.GEN_OPERATION__ECORE_OPERATION:
341         setEcoreOperation((EOperation)null);
342         return;
343       case GenModelPackage.GEN_OPERATION__GEN_PARAMETERS:
344         getGenParameters().clear();
345         return;
346     }
347     eDynamicUnset(eFeature);
348   }
349
350   public ETypedElement getEcoreTypedElement()
351   {
352     return getEcoreOperation();
353   }
354
355   public String JavaDoc getName()
356   {
357     return getEcoreOperation().getName();
358   }
359
360   public String JavaDoc getCapName()
361   {
362     return capName(getName());
363   }
364
365   public String JavaDoc getFormattedName()
366   {
367     return format(getCapName(), ' ', null, false);
368   }
369
370   // Many inherited methods must be overridden to handle this case.
371
//
372
public boolean isVoid()
373   {
374     return getEcoreOperation().getEType() == null;
375   }
376
377   /**
378    * @deprecated As of EMF 2.1, simply call <code>getEcoreTypedElement().getEType()</code>.
379    */

380   protected EClassifier getReturn()
381   {
382     return getEcoreOperation().getEType();
383   }
384
385   public String JavaDoc getTypeClassifierAccessorName()
386   {
387     return isVoid() ? "null" : super.getTypeClassifierAccessorName();
388   }
389
390   public GenPackage getTypeGenPackage()
391   {
392     return isVoid() ? null : super.getTypeGenPackage();
393   }
394
395   public String JavaDoc getType()
396   {
397     return isVoid() ? "void" : super.getType();
398   }
399
400   public String JavaDoc getImportedType()
401   {
402     return isVoid() ? "void" : super.getImportedType();
403   }
404
405   public String JavaDoc getObjectType()
406   {
407     return isVoid() ? "void" : super.getObjectType();
408   }
409
410   public String JavaDoc getImportedInternalType()
411   {
412     return isVoid() ? "void" : super.getImportedInternalType();
413   }
414
415   public boolean isFeatureMapType()
416   {
417     return !isVoid() && super.isFeatureMapType();
418   }
419
420   public String JavaDoc getListItemType()
421   {
422     return isVoid() ? "void" : super.getListItemType();
423   }
424
425   public String JavaDoc getQualifiedListItemType()
426   {
427     return isVoid() ? "void" : super.getQualifiedListItemType();
428   }
429
430   public boolean isPrimitiveType()
431   {
432     return !isVoid() && super.isPrimitiveType();
433   }
434
435   public String JavaDoc getPrimitiveValueFunction()
436   {
437     return isVoid() ? null : super.getPrimitiveValueFunction();
438   }
439
440   public boolean isStringType()
441   {
442     return !isVoid() && super.isStringType();
443   }
444
445   public boolean isStringBasedType()
446   {
447     return !isVoid() && super.isStringBasedType();
448   }
449
450   /**
451    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#getTypeClassifierAccessorName() getTypeClassifierAccessorName} instead.
452    */

453   public String JavaDoc getReturnTypeClassifier()
454   {
455     return getTypeClassifierAccessorName();
456   }
457
458   /**
459    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#getTypeGenPackage getTypeGenPackage} instead.
460    */

461   public GenPackage getReturnTypeGenPackage()
462   {
463     return getTypeGenPackage();
464   }
465
466   /**
467    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#getType getType} instead.
468    */

469   public String JavaDoc getReturnType()
470   {
471     return getType();
472   }
473
474   /**
475    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#getImporterType getImportedType} instead.
476    */

477   public String JavaDoc getImportedReturnType()
478   {
479     return getImportedType();
480   }
481
482   /**
483    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#getObjectType getObjectType} instead.
484    */

485   public String JavaDoc getObjectReturnType()
486   {
487     return getObjectType();
488   }
489
490   /**
491    * @deprecated As of EMF 2.1, use {@link GenTypedElementImpl#isPrimitiveType isPrimitiveType} instead.
492    */

493   public boolean isPrimitiveReturnType()
494   {
495     return isPrimitiveType();
496   }
497
498   public String JavaDoc getParameters()
499   {
500     return getParameters(true);
501   }
502
503   protected String JavaDoc getParameters(boolean formal)
504   {
505     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
506     for (Iterator JavaDoc iter = getGenParameters().iterator(); iter.hasNext(); )
507     {
508       GenParameter genParameter = (GenParameter)iter.next();
509       if (formal)
510       {
511         result.append(genParameter.getImportedType());
512         result.append(' ');
513       }
514       result.append(genParameter.getName());
515       
516       if (iter.hasNext()) result.append(", ");
517     }
518     return result.toString();
519   }
520
521   public String JavaDoc getParameterTypes(String JavaDoc separator)
522   {
523     return getParameterTypes(separator, true);
524   }
525
526   public String JavaDoc getParameterTypes(String JavaDoc separator, boolean qualified)
527   {
528     StringBuffer JavaDoc parameterTypes = new StringBuffer JavaDoc();
529
530     for (Iterator JavaDoc genParameters = getGenParameters().iterator(); genParameters.hasNext();)
531     {
532       GenParameter genParameter = (GenParameter)genParameters.next();
533       String JavaDoc type = genParameter.getType();
534
535       if (!qualified)
536       {
537         int firstBracket = type.indexOf("[");
538         if (firstBracket != -1)
539         {
540           type = type.substring(0, firstBracket);
541         }
542
543         type = type.substring(type.lastIndexOf(".") + 1);
544
545         int firstDollar = type.indexOf("$");
546         if (firstDollar != -1)
547         {
548           type = type.substring(0, firstDollar);
549         }
550       }
551
552       parameterTypes.append(type);
553
554       if (genParameters.hasNext())
555       {
556         parameterTypes.append(separator);
557       }
558     }
559
560     return parameterTypes.toString();
561   }
562
563   public String JavaDoc getImportedMetaType()
564   {
565     return getGenModel().getImportedName("org.eclipse.emf.ecore.EOperation");
566   }
567
568   public GenPackage getGenPackage()
569   {
570     return getGenClass().getGenPackage();
571   }
572
573   public void initialize(EOperation eOperation)
574   {
575     setEcoreOperation(eOperation);
576
577     List JavaDoc parameters = eOperation.getEParameters();
578     LOOP:
579     for (int i = 0; i < parameters.size(); ++i)
580     {
581       EParameter parameter = (EParameter)parameters.get(i);
582
583       for (int j = 0; j < getGenParameters().size(); ++j)
584       {
585         GenParameter genParameter = (GenParameter)getGenParameters().get(j);
586         if (genParameter.getEcoreParameter() == parameter)
587         {
588           genParameter.initialize(parameter);
589           if (i != j)
590           {
591             getGenParameters().move(i, j);
592           }
593
594           continue LOOP;
595         }
596       }
597
598       GenParameter genParameter = getGenModel().createGenParameter();
599       getGenParameters().add(genParameter);
600       genParameter.initialize(parameter);
601     }
602   }
603
604   public String JavaDoc getModelInfo()
605   {
606     EOperation eOperation = getEcoreOperation();
607     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
608
609     // If this looks like a feature getter, a kind property will allow it to be recognized properly.
610
//
611
if (getGenParameters().isEmpty() &&
612         ((getName().startsWith("get") && getName().length() > 3 && Character.isUpperCase(getName().charAt(3))) ||
613          (getName().startsWith("is") && getName().length() > 2 && Character.isUpperCase(getName().charAt(2)))))
614     {
615       appendModelSetting(result, "kind", "operation");
616     }
617
618     if (!isVoid())
619     {
620       // Since we only use this right on an operation, we always want to include the keyType and valueType, and we never
621
// want to qualify the property names.
622
//
623
String JavaDoc mapModelInfo = getMapModelInfo(false, true);
624       if (mapModelInfo != null)
625       {
626         result.append(mapModelInfo);
627       }
628       else
629       {
630         if (eOperation.isMany() && !isFeatureMapType())
631         {
632           appendModelSetting(result, "type", getType(eOperation.getEType(), false));
633         }
634
635         EClassifier type = eOperation.getEType();
636         if (type instanceof EDataType && !(type instanceof EEnum))
637         {
638           GenPackage genPackage = findGenPackage(type.getEPackage());
639           if (genPackage != null && (isFeatureMapType() || !genPackage.isEcorePackage()))
640           {
641             appendModelSetting(result, "dataType", genPackage.getInterfacePackageName() + '.' + type.getName());
642           }
643         }
644         
645         if (!eOperation.isUnique())
646         {
647           appendModelSetting(result, "unique", "false");
648         }
649
650         result.append(getMultiplicityModelInfo(false));
651       }
652
653       if (!eOperation.isOrdered())
654       {
655         appendModelSetting(result, "ordered", "false");
656       }
657     }
658
659     for (Iterator JavaDoc i = getGenParameters().iterator(); i.hasNext(); )
660     {
661       String JavaDoc parameterResult = ((GenParameter)i.next()).getQualifiedModelInfo();
662       if (parameterResult.length() > 0)
663       {
664         result.append(parameterResult);
665         result.append(' ');
666       }
667     }
668
669     appendAnnotationInfo(result, eOperation);
670     return result.toString().trim();
671   }
672
673   public boolean reconcile(GenOperation oldGenOperationVersion)
674   {
675     if (getEcoreOperation().getName().equals(oldGenOperationVersion.getEcoreOperation().getName()))
676     {
677       for (Iterator JavaDoc i = getGenParameters().iterator(); i.hasNext(); )
678       {
679         GenParameter genParameter = (GenParameter)i.next();
680         for (Iterator JavaDoc j = oldGenOperationVersion.getGenParameters().iterator(); j.hasNext(); )
681         {
682           GenParameter oldGenParameterVersion = (GenParameter)j.next();
683           if (genParameter.reconcile(oldGenParameterVersion))
684           {
685             break;
686           }
687         }
688       }
689       reconcileSettings(oldGenOperationVersion);
690       return true;
691     }
692     else
693     {
694       return false;
695     }
696   }
697
698   protected void reconcileSettings(GenOperation oldGenOperationVersion)
699   {
700   }
701
702   public boolean reconcile()
703   {
704     EOperation eOperation = getEcoreOperation();
705     if (eOperation == null || eOperation.eIsProxy() || eOperation.eResource() == null)
706     {
707       return false;
708     }
709     else
710     {
711       for (Iterator JavaDoc i = getGenParameters().iterator(); i.hasNext(); )
712       {
713         GenParameter genParameter = (GenParameter)i.next();
714         if (!genParameter.reconcile())
715         {
716           i.remove();
717         }
718       }
719
720       return true;
721     }
722   }
723
724   protected String JavaDoc getBody()
725   {
726     EOperation eOperation = getEcoreOperation();
727     EAnnotation eAnnotation = eOperation.getEAnnotation(GenModelPackage.eNS_URI);
728     return eAnnotation == null ? null : (String JavaDoc)eAnnotation.getDetails().get("body");
729   }
730
731   public boolean hasBody()
732   {
733     return getBody() != null;
734   }
735
736   public String JavaDoc getBody(String JavaDoc indentation)
737   {
738     String JavaDoc body = getBody();
739     if (body != null)
740     {
741       StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc(indent(body, indentation));
742
743       for (int i = 0; i < stringBuffer.length(); )
744       {
745         // EATM in JDK 1.4 there will be an indexOf on StringBuffer.
746
//
747
String JavaDoc string = stringBuffer.toString();
748         int start = string.indexOf("<%", i);
749         if (start == -1)
750         {
751           break;
752         }
753         else
754         {
755           int end = string.indexOf("%>", start + 2);
756           if (end == -1)
757           {
758             break;
759           }
760           else
761           {
762             String JavaDoc qualifiedName = stringBuffer.substring(start + 2, end);
763             String JavaDoc importedName = getGenModel().getImportedName(qualifiedName);
764             stringBuffer.replace(start, end + 2, importedName);
765             i += importedName.length();
766           }
767         }
768       }
769
770       return stringBuffer.toString();
771     }
772     else
773     {
774       return null;
775     }
776   }
777
778   public List JavaDoc getGenExceptions()
779   {
780     List JavaDoc result = new ArrayList JavaDoc();
781     for (Iterator JavaDoc i = getEcoreOperation().getEExceptions().iterator(); i.hasNext(); )
782     {
783       result.add(findGenClassifier((EClassifier)i.next()));
784     }
785     return result;
786   }
787
788   public String JavaDoc getThrows()
789   {
790     List JavaDoc genExceptions = getGenExceptions();
791     if (genExceptions.isEmpty())
792     {
793       return "";
794     }
795     else
796     {
797       StringBuffer JavaDoc result = new StringBuffer JavaDoc(" throws ");
798       for (Iterator JavaDoc i = genExceptions.iterator(); i.hasNext(); )
799       {
800         GenClassifier genClassifier = (GenClassifier)i.next();
801         result.append(genClassifier.getImportedInstanceClassName());
802         if (i.hasNext())
803         {
804           result.append(", ");
805         }
806       }
807       return result.toString();
808     }
809   }
810
811   public boolean isInvariant()
812   {
813     return
814       getReturnType() != null &&
815         "boolean".equals(getReturnType()) &&
816         getGenParameters().size() == 2 &&
817         "org.eclipse.emf.common.util.DiagnosticChain".equals
818           (((GenParameter)getGenParameters().get(0)).getEcoreParameter().getEType().getInstanceClassName()) &&
819         "java.util.Map".equals
820           (((GenParameter)getGenParameters().get(1)).getEcoreParameter().getEType().getInstanceClassName());
821   }
822
823   public String JavaDoc getParameterNames(String JavaDoc separator)
824   {
825     StringBuffer JavaDoc parameterNames = new StringBuffer JavaDoc();
826     for (Iterator JavaDoc genParameters = getGenParameters().iterator(); genParameters.hasNext();)
827     {
828       parameterNames.append(((GenParameter)genParameters.next()).getName());
829       if (genParameters.hasNext())
830       {
831         parameterNames.append(separator);
832       }
833     }
834
835     return parameterNames.toString();
836   }
837 }
838
Popular Tags