KickJava   Java API By Example, From Geeks To Geeks.

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


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: GenPackageImpl.java,v 1.35 2005/06/29 21:23:56 emerks Exp $
16  */

17 package org.eclipse.emf.codegen.ecore.genmodel.impl;
18
19
20 import java.io.IOException JavaDoc;
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.LinkedList JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Set JavaDoc;
32
33 import org.osgi.framework.Bundle;
34
35 import org.eclipse.core.runtime.IPath;
36 import org.eclipse.core.runtime.IProgressMonitor;
37 import org.eclipse.core.runtime.NullProgressMonitor;
38 import org.eclipse.core.runtime.Path;
39 import org.eclipse.core.runtime.Platform;
40 import org.eclipse.core.runtime.SubProgressMonitor;
41
42 import org.eclipse.emf.codegen.ecore.CodeGenEcorePlugin;
43 import org.eclipse.emf.codegen.ecore.Generator;
44 import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
45 import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
46 import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier;
47 import org.eclipse.emf.codegen.ecore.genmodel.GenDataType;
48 import org.eclipse.emf.codegen.ecore.genmodel.GenEnum;
49 import org.eclipse.emf.codegen.ecore.genmodel.GenFeature;
50 import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
51 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
52 import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
53 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
54 import org.eclipse.emf.codegen.ecore.genmodel.GenParameter;
55 import org.eclipse.emf.codegen.ecore.genmodel.GenProviderKind;
56 import org.eclipse.emf.codegen.ecore.genmodel.GenResourceKind;
57 import org.eclipse.emf.codegen.util.CodeGenUtil;
58 import org.eclipse.emf.common.notify.Notification;
59 import org.eclipse.emf.common.notify.NotificationChain;
60 import org.eclipse.emf.common.util.BasicEList;
61 import org.eclipse.emf.common.util.EList;
62 import org.eclipse.emf.common.util.TreeIterator;
63 import org.eclipse.emf.common.util.URI;
64 import org.eclipse.emf.common.util.UniqueEList;
65 import org.eclipse.emf.ecore.EAnnotation;
66 import org.eclipse.emf.ecore.EClass;
67 import org.eclipse.emf.ecore.EClassifier;
68 import org.eclipse.emf.ecore.EDataType;
69 import org.eclipse.emf.ecore.EEnum;
70 import org.eclipse.emf.ecore.EEnumLiteral;
71 import org.eclipse.emf.ecore.EModelElement;
72 import org.eclipse.emf.ecore.EObject;
73 import org.eclipse.emf.ecore.EOperation;
74 import org.eclipse.emf.ecore.EPackage;
75 import org.eclipse.emf.ecore.EParameter;
76 import org.eclipse.emf.ecore.EReference;
77 import org.eclipse.emf.ecore.EStructuralFeature;
78 import org.eclipse.emf.ecore.EcorePackage;
79 import org.eclipse.emf.ecore.InternalEObject;
80 import org.eclipse.emf.ecore.impl.ENotificationImpl;
81 import org.eclipse.emf.ecore.plugin.EcorePlugin;
82 import org.eclipse.emf.ecore.resource.Resource;
83 import org.eclipse.emf.ecore.resource.ResourceSet;
84 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
85 import org.eclipse.emf.ecore.util.EObjectContainmentEList;
86 import org.eclipse.emf.ecore.util.EcoreSwitch;
87 import org.eclipse.emf.ecore.util.EcoreUtil;
88 import org.eclipse.emf.ecore.util.ExtendedMetaData;
89 import org.eclipse.emf.ecore.util.InternalEList;
90
91
92 /**
93  * <!-- begin-user-doc -->
94  * An implementation of the model object '<em><b>Gen Package</b></em>'.
95  * <!-- end-user-doc -->
96  * <p>
97  * The following features are implemented:
98  * <ul>
99  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getPrefix <em>Prefix</em>}</li>
100  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getBasePackage <em>Base Package</em>}</li>
101  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getResource <em>Resource</em>}</li>
102  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#isDisposableProviderFactory <em>Disposable Provider Factory</em>}</li>
103  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#isAdapterFactory <em>Adapter Factory</em>}</li>
104  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#isLoadInitialization <em>Load Initialization</em>}</li>
105  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getInterfacePackageSuffix <em>Interface Package Suffix</em>}</li>
106  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getClassPackageSuffix <em>Class Package Suffix</em>}</li>
107  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getUtilityPackageSuffix <em>Utility Package Suffix</em>}</li>
108  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getProviderPackageSuffix <em>Provider Package Suffix</em>}</li>
109  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getPresentationPackageSuffix <em>Presentation Package Suffix</em>}</li>
110  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getTestsPackageSuffix <em>Tests Package Suffix</em>}</li>
111  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#isGenerateExampleClass <em>Generate Example Class</em>}</li>
112  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getEcorePackage <em>Ecore Package</em>}</li>
113  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getGenModel <em>Gen Model</em>}</li>
114  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getGenEnums <em>Gen Enums</em>}</li>
115  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getGenDataTypes <em>Gen Data Types</em>}</li>
116  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getGenClasses <em>Gen Classes</em>}</li>
117  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getNestedGenPackages <em>Nested Gen Packages</em>}</li>
118  * <li>{@link org.eclipse.emf.codegen.ecore.genmodel.impl.GenPackageImpl#getGenClassifiers <em>Gen Classifiers</em>}</li>
119  * </ul>
120  * </p>
121  *
122  * @generated
123  */

124 public class GenPackageImpl extends GenBaseImpl implements GenPackage
125 {
126   protected static final String JavaDoc XSD2ECORE_URI = "http:///org/eclipse/emf/mapping/xsd2ecore/XSD2Ecore";
127
128   /**
129    * The default value of the '{@link #getPrefix() <em>Prefix</em>}' attribute.
130    * <!-- begin-user-doc -->
131    * <!-- end-user-doc -->
132    * @see #getPrefix()
133    * @generated
134    * @ordered
135    */

136   protected static final String JavaDoc PREFIX_EDEFAULT = null;
137
138   /**
139    * The cached value of the '{@link #getPrefix() <em>Prefix</em>}' attribute.
140    * <!-- begin-user-doc -->
141    * <!-- end-user-doc -->
142    * @see #getPrefix()
143    * @generated
144    * @ordered
145    */

146   protected String JavaDoc prefix = PREFIX_EDEFAULT;
147
148   /**
149    * The default value of the '{@link #getBasePackage() <em>Base Package</em>}' attribute.
150    * <!-- begin-user-doc -->
151    * <!-- end-user-doc -->
152    * @see #getBasePackage()
153    * @generated
154    * @ordered
155    */

156   protected static final String JavaDoc BASE_PACKAGE_EDEFAULT = null;
157
158   /**
159    * The cached value of the '{@link #getBasePackage() <em>Base Package</em>}' attribute.
160    * <!-- begin-user-doc -->
161    * <!-- end-user-doc -->
162    * @see #getBasePackage()
163    * @generated
164    * @ordered
165    */

166   protected String JavaDoc basePackage = BASE_PACKAGE_EDEFAULT;
167
168   /**
169    * The default value of the '{@link #getResource() <em>Resource</em>}' attribute.
170    * <!-- begin-user-doc -->
171    * <!-- end-user-doc -->
172    * @see #getResource()
173    * @generated
174    * @ordered
175    */

176   protected static final GenResourceKind RESOURCE_EDEFAULT = GenResourceKind.NONE_LITERAL;
177
178   /**
179    * The cached value of the '{@link #getResource() <em>Resource</em>}' attribute.
180    * <!-- begin-user-doc -->
181    * <!-- end-user-doc -->
182    * @see #getResource()
183    * @generated
184    * @ordered
185    */

186   protected GenResourceKind resource = RESOURCE_EDEFAULT;
187
188   /**
189    * The default value of the '{@link #isDisposableProviderFactory() <em>Disposable Provider Factory</em>}' attribute.
190    * <!-- begin-user-doc -->
191    * <!-- end-user-doc -->
192    * @see #isDisposableProviderFactory()
193    * @generated
194    * @ordered
195    */

196   protected static final boolean DISPOSABLE_PROVIDER_FACTORY_EDEFAULT = false;
197
198   /**
199    * The cached value of the '{@link #isDisposableProviderFactory() <em>Disposable Provider Factory</em>}' attribute.
200    * <!-- begin-user-doc -->
201    * <!-- end-user-doc -->
202    * @see #isDisposableProviderFactory()
203    * @generated
204    * @ordered
205    */

206   protected boolean disposableProviderFactory = DISPOSABLE_PROVIDER_FACTORY_EDEFAULT;
207
208   /**
209    * The default value of the '{@link #isAdapterFactory() <em>Adapter Factory</em>}' attribute.
210    * <!-- begin-user-doc -->
211    * <!-- end-user-doc -->
212    * @see #isAdapterFactory()
213    * @generated
214    * @ordered
215    */

216   protected static final boolean ADAPTER_FACTORY_EDEFAULT = true;
217
218   /**
219    * The cached value of the '{@link #isAdapterFactory() <em>Adapter Factory</em>}' attribute.
220    * <!-- begin-user-doc -->
221    * <!-- end-user-doc -->
222    * @see #isAdapterFactory()
223    * @generated
224    * @ordered
225    */

226   protected boolean adapterFactory = ADAPTER_FACTORY_EDEFAULT;
227
228   /**
229    * The default value of the '{@link #isLoadInitialization() <em>Load Initialization</em>}' attribute.
230    * <!-- begin-user-doc -->
231    * <!-- end-user-doc -->
232    * @see #isLoadInitialization()
233    * @generated
234    * @ordered
235    */

236   protected static final boolean LOAD_INITIALIZATION_EDEFAULT = false;
237
238   /**
239    * The cached value of the '{@link #isLoadInitialization() <em>Load Initialization</em>}' attribute.
240    * <!-- begin-user-doc -->
241    * <!-- end-user-doc -->
242    * @see #isLoadInitialization()
243    * @generated
244    * @ordered
245    */

246   protected boolean loadInitialization = LOAD_INITIALIZATION_EDEFAULT;
247
248   /**
249    * The default value of the '{@link #getInterfacePackageSuffix() <em>Interface Package Suffix</em>}' attribute.
250    * <!-- begin-user-doc -->
251    * <!-- end-user-doc -->
252    * @see #getInterfacePackageSuffix()
253    * @generated
254    * @ordered
255    */

256   protected static final String JavaDoc INTERFACE_PACKAGE_SUFFIX_EDEFAULT = "";
257
258   /**
259    * The cached value of the '{@link #getInterfacePackageSuffix() <em>Interface Package Suffix</em>}' attribute.
260    * <!-- begin-user-doc -->
261    * <!-- end-user-doc -->
262    * @see #getInterfacePackageSuffix()
263    * @generated
264    * @ordered
265    */

266   protected String JavaDoc interfacePackageSuffix = INTERFACE_PACKAGE_SUFFIX_EDEFAULT;
267
268   /**
269    * The default value of the '{@link #getClassPackageSuffix() <em>Class Package Suffix</em>}' attribute.
270    * <!-- begin-user-doc -->
271    * <!-- end-user-doc -->
272    * @see #getClassPackageSuffix()
273    * @generated
274    * @ordered
275    */

276   protected static final String JavaDoc CLASS_PACKAGE_SUFFIX_EDEFAULT = "impl";
277
278   /**
279    * The cached value of the '{@link #getClassPackageSuffix() <em>Class Package Suffix</em>}' attribute.
280    * <!-- begin-user-doc -->
281    * <!-- end-user-doc -->
282    * @see #getClassPackageSuffix()
283    * @generated
284    * @ordered
285    */

286   protected String JavaDoc classPackageSuffix = CLASS_PACKAGE_SUFFIX_EDEFAULT;
287
288   /**
289    * The default value of the '{@link #getUtilityPackageSuffix() <em>Utility Package Suffix</em>}' attribute.
290    * <!-- begin-user-doc -->
291    * <!-- end-user-doc -->
292    * @see #getUtilityPackageSuffix()
293    * @generated
294    * @ordered
295    */

296   protected static final String JavaDoc UTILITY_PACKAGE_SUFFIX_EDEFAULT = "util";
297
298   /**
299    * The cached value of the '{@link #getUtilityPackageSuffix() <em>Utility Package Suffix</em>}' attribute.
300    * <!-- begin-user-doc -->
301    * <!-- end-user-doc -->
302    * @see #getUtilityPackageSuffix()
303    * @generated
304    * @ordered
305    */

306   protected String JavaDoc utilityPackageSuffix = UTILITY_PACKAGE_SUFFIX_EDEFAULT;
307
308   /**
309    * The default value of the '{@link #getProviderPackageSuffix() <em>Provider Package Suffix</em>}' attribute.
310    * <!-- begin-user-doc -->
311    * <!-- end-user-doc -->
312    * @see #getProviderPackageSuffix()
313    * @generated
314    * @ordered
315    */

316   protected static final String JavaDoc PROVIDER_PACKAGE_SUFFIX_EDEFAULT = "provider";
317
318   /**
319    * The cached value of the '{@link #getProviderPackageSuffix() <em>Provider Package Suffix</em>}' attribute.
320    * <!-- begin-user-doc -->
321    * <!-- end-user-doc -->
322    * @see #getProviderPackageSuffix()
323    * @generated
324    * @ordered
325    */

326   protected String JavaDoc providerPackageSuffix = PROVIDER_PACKAGE_SUFFIX_EDEFAULT;
327
328   /**
329    * The default value of the '{@link #getPresentationPackageSuffix() <em>Presentation Package Suffix</em>}' attribute.
330    * <!-- begin-user-doc -->
331    * <!-- end-user-doc -->
332    * @see #getPresentationPackageSuffix()
333    * @generated
334    * @ordered
335    */

336   protected static final String JavaDoc PRESENTATION_PACKAGE_SUFFIX_EDEFAULT = "presentation";
337
338   /**
339    * The cached value of the '{@link #getPresentationPackageSuffix() <em>Presentation Package Suffix</em>}' attribute.
340    * <!-- begin-user-doc -->
341    * <!-- end-user-doc -->
342    * @see #getPresentationPackageSuffix()
343    * @generated
344    * @ordered
345    */

346   protected String JavaDoc presentationPackageSuffix = PRESENTATION_PACKAGE_SUFFIX_EDEFAULT;
347
348   /**
349    * The default value of the '{@link #getTestsPackageSuffix() <em>Tests Package Suffix</em>}' attribute.
350    * <!-- begin-user-doc -->
351    * <!-- end-user-doc -->
352    * @see #getTestsPackageSuffix()
353    * @generated
354    * @ordered
355    */

356   protected static final String JavaDoc TESTS_PACKAGE_SUFFIX_EDEFAULT = "tests";
357
358   /**
359    * The cached value of the '{@link #getTestsPackageSuffix() <em>Tests Package Suffix</em>}' attribute.
360    * <!-- begin-user-doc -->
361    * <!-- end-user-doc -->
362    * @see #getTestsPackageSuffix()
363    * @generated
364    * @ordered
365    */

366   protected String JavaDoc testsPackageSuffix = TESTS_PACKAGE_SUFFIX_EDEFAULT;
367
368   /**
369    * The default value of the '{@link #isGenerateExampleClass() <em>Generate Example Class</em>}' attribute.
370    * <!-- begin-user-doc -->
371    * <!-- end-user-doc -->
372    * @see #isGenerateExampleClass()
373    * @generated
374    * @ordered
375    */

376   protected static final boolean GENERATE_EXAMPLE_CLASS_EDEFAULT = true;
377
378   /**
379    * The cached value of the '{@link #isGenerateExampleClass() <em>Generate Example Class</em>}' attribute.
380    * <!-- begin-user-doc -->
381    * <!-- end-user-doc -->
382    * @see #isGenerateExampleClass()
383    * @generated
384    * @ordered
385    */

386   protected boolean generateExampleClass = GENERATE_EXAMPLE_CLASS_EDEFAULT;
387
388   /**
389    * The cached value of the '{@link #getEcorePackage() <em>Ecore Package</em>}' reference.
390    * <!-- begin-user-doc -->
391    * <!-- end-user-doc -->
392    * @see #getEcorePackage()
393    * @generated
394    * @ordered
395    */

396   protected EPackage ecorePackage = null;
397
398   /**
399    * The cached value of the '{@link #getGenEnums() <em>Gen Enums</em>}' containment reference list.
400    * <!-- begin-user-doc -->
401    * <!-- end-user-doc -->
402    * @see #getGenEnums()
403    * @generated
404    * @ordered
405    */

406   protected EList genEnums = null;
407
408   /**
409    * The cached value of the '{@link #getGenDataTypes() <em>Gen Data Types</em>}' containment reference list.
410    * <!-- begin-user-doc -->
411    * <!-- end-user-doc -->
412    * @see #getGenDataTypes()
413    * @generated
414    * @ordered
415    */

416   protected EList genDataTypes = null;
417
418   /**
419    * The cached value of the '{@link #getGenClasses() <em>Gen Classes</em>}' containment reference list.
420    * <!-- begin-user-doc -->
421    * <!-- end-user-doc -->
422    * @see #getGenClasses()
423    * @generated
424    * @ordered
425    */

426   protected EList genClasses = null;
427
428   /**
429    * The cached value of the '{@link #getNestedGenPackages() <em>Nested Gen Packages</em>}' containment reference list.
430    * <!-- begin-user-doc -->
431    * <!-- end-user-doc -->
432    * @see #getNestedGenPackages()
433    * @generated
434    * @ordered
435    */

436   protected EList nestedGenPackages = null;
437
438   /**
439    * <!-- begin-user-doc -->
440    * <!-- end-user-doc -->
441    * @generated modifiable
442    */

443   protected GenPackageImpl()
444   {
445     super();
446   }
447
448   /**
449    * <!-- begin-user-doc -->
450    * <!-- end-user-doc -->
451    * @generated
452    */

453   protected EClass eStaticClass()
454   {
455     return GenModelPackage.eINSTANCE.getGenPackage();
456   }
457
458   /**
459    * <!-- begin-user-doc -->
460    * <!-- end-user-doc -->
461    * @generated
462    */

463   public String JavaDoc getPrefixGen()
464   {
465     return prefix;
466   }
467
468   public String JavaDoc getPrefix()
469   {
470     if (getPrefixGen() != null)
471     {
472       return getPrefixGen();
473     }
474     return "";
475   }
476
477   /**
478    * <!-- begin-user-doc -->
479    * <!-- end-user-doc -->
480    * @generated
481    */

482   public void setPrefix(String JavaDoc newPrefix)
483   {
484     String JavaDoc oldPrefix = prefix;
485     prefix = newPrefix;
486     if (eNotificationRequired())
487       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PREFIX, oldPrefix, prefix));
488   }
489
490   /**
491    * <!-- begin-user-doc -->
492    * <!-- end-user-doc -->
493    * @generated
494    */

495   public String JavaDoc getBasePackageGen()
496   {
497     return basePackage;
498   }
499
500   public String JavaDoc getBasePackage()
501   {
502     // If the base package isn't set but there is a parent package, us it's information instead.
503
//
504
String JavaDoc result = getBasePackageGen();
505     if (isBlank(result))
506     {
507       EObject container = eContainer();
508       result = container instanceof GenPackage ? ((GenPackage)container).getQualifiedPackageName() : null;
509     }
510     return result;
511   }
512
513   /**
514    * <!-- begin-user-doc -->
515    * <!-- end-user-doc -->
516    * @generated
517    */

518   public void setBasePackage(String JavaDoc newBasePackage)
519   {
520     String JavaDoc oldBasePackage = basePackage;
521     basePackage = newBasePackage;
522     if (eNotificationRequired())
523       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__BASE_PACKAGE, oldBasePackage, basePackage));
524   }
525
526   /**
527    * <!-- begin-user-doc -->
528    * <!-- end-user-doc -->
529    * @generated
530    */

531   public GenResourceKind getResource()
532   {
533     return resource;
534   }
535
536   /**
537    * <!-- begin-user-doc -->
538    * <!-- end-user-doc -->
539    * @generated
540    */

541   public void setResource(GenResourceKind newResource)
542   {
543     GenResourceKind oldResource = resource;
544     resource = newResource == null ? RESOURCE_EDEFAULT : newResource;
545     if (eNotificationRequired())
546       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__RESOURCE, oldResource, resource));
547   }
548
549   /**
550    * <!-- begin-user-doc -->
551    * <!-- end-user-doc -->
552    * @generated
553    */

554   public boolean isDisposableProviderFactory()
555   {
556     return disposableProviderFactory;
557   }
558
559   /**
560    * <!-- begin-user-doc -->
561    * <!-- end-user-doc -->
562    * @generated
563    */

564   public void setDisposableProviderFactory(boolean newDisposableProviderFactory)
565   {
566     boolean oldDisposableProviderFactory = disposableProviderFactory;
567     disposableProviderFactory = newDisposableProviderFactory;
568     if (eNotificationRequired())
569       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY, oldDisposableProviderFactory, disposableProviderFactory));
570   }
571
572   /**
573    * <!-- begin-user-doc -->
574    * <!-- end-user-doc -->
575    * @generated
576    */

577   public boolean isAdapterFactory()
578   {
579     return adapterFactory;
580   }
581
582   /**
583    * <!-- begin-user-doc -->
584    * <!-- end-user-doc -->
585    * @generated
586    */

587   public void setAdapterFactory(boolean newAdapterFactory)
588   {
589     boolean oldAdapterFactory = adapterFactory;
590     adapterFactory = newAdapterFactory;
591     if (eNotificationRequired())
592       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY, oldAdapterFactory, adapterFactory));
593   }
594
595   /**
596    * <!-- begin-user-doc -->
597    * <!-- end-user-doc -->
598    * @generated
599    */

600   public boolean isLoadInitialization()
601   {
602     return loadInitialization;
603   }
604
605   /**
606    * <!-- begin-user-doc -->
607    * <!-- end-user-doc -->
608    * @generated
609    */

610   public void setLoadInitialization(boolean newLoadInitialization)
611   {
612     boolean oldLoadInitialization = loadInitialization;
613     loadInitialization = newLoadInitialization;
614     if (eNotificationRequired())
615       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION, oldLoadInitialization, loadInitialization));
616   }
617
618   /**
619    * <!-- begin-user-doc -->
620    * <!-- end-user-doc -->
621    * @generated
622    */

623   public String JavaDoc getInterfacePackageSuffix()
624   {
625     return interfacePackageSuffix;
626   }
627
628   /**
629    * <!-- begin-user-doc -->
630    * <!-- end-user-doc -->
631    * @generated
632    */

633   public void setInterfacePackageSuffix(String JavaDoc newInterfacePackageSuffix)
634   {
635     String JavaDoc oldInterfacePackageSuffix = interfacePackageSuffix;
636     interfacePackageSuffix = newInterfacePackageSuffix;
637     if (eNotificationRequired())
638       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX, oldInterfacePackageSuffix, interfacePackageSuffix));
639   }
640
641   /**
642    * <!-- begin-user-doc -->
643    * <!-- end-user-doc -->
644    * @generated
645    */

646   public String JavaDoc getClassPackageSuffix()
647   {
648     return classPackageSuffix;
649   }
650
651   /**
652    * <!-- begin-user-doc -->
653    * <!-- end-user-doc -->
654    * @generated
655    */

656   public void setClassPackageSuffix(String JavaDoc newClassPackageSuffix)
657   {
658     String JavaDoc oldClassPackageSuffix = classPackageSuffix;
659     classPackageSuffix = newClassPackageSuffix;
660     if (eNotificationRequired())
661       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX, oldClassPackageSuffix, classPackageSuffix));
662   }
663
664   /**
665    * <!-- begin-user-doc -->
666    * <!-- end-user-doc -->
667    * @generated
668    */

669   public String JavaDoc getUtilityPackageSuffix()
670   {
671     return utilityPackageSuffix;
672   }
673
674   /**
675    * <!-- begin-user-doc -->
676    * <!-- end-user-doc -->
677    * @generated
678    */

679   public void setUtilityPackageSuffix(String JavaDoc newUtilityPackageSuffix)
680   {
681     String JavaDoc oldUtilityPackageSuffix = utilityPackageSuffix;
682     utilityPackageSuffix = newUtilityPackageSuffix;
683     if (eNotificationRequired())
684       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX, oldUtilityPackageSuffix, utilityPackageSuffix));
685   }
686
687   /**
688    * <!-- begin-user-doc -->
689    * <!-- end-user-doc -->
690    * @generated
691    */

692   public String JavaDoc getProviderPackageSuffix()
693   {
694     return providerPackageSuffix;
695   }
696
697   /**
698    * <!-- begin-user-doc -->
699    * <!-- end-user-doc -->
700    * @generated
701    */

702   public void setProviderPackageSuffix(String JavaDoc newProviderPackageSuffix)
703   {
704     String JavaDoc oldProviderPackageSuffix = providerPackageSuffix;
705     providerPackageSuffix = newProviderPackageSuffix;
706     if (eNotificationRequired())
707       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX, oldProviderPackageSuffix, providerPackageSuffix));
708   }
709
710   /**
711    * <!-- begin-user-doc -->
712    * <!-- end-user-doc -->
713    * @generated
714    */

715   public String JavaDoc getPresentationPackageSuffix()
716   {
717     return presentationPackageSuffix;
718   }
719
720   /**
721    * <!-- begin-user-doc -->
722    * <!-- end-user-doc -->
723    * @generated
724    */

725   public void setPresentationPackageSuffix(String JavaDoc newPresentationPackageSuffix)
726   {
727     String JavaDoc oldPresentationPackageSuffix = presentationPackageSuffix;
728     presentationPackageSuffix = newPresentationPackageSuffix;
729     if (eNotificationRequired())
730       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX, oldPresentationPackageSuffix, presentationPackageSuffix));
731   }
732
733   /**
734    * <!-- begin-user-doc -->
735    * <!-- end-user-doc -->
736    * @generated
737    */

738   public String JavaDoc getTestsPackageSuffix()
739   {
740     return testsPackageSuffix;
741   }
742
743   /**
744    * <!-- begin-user-doc -->
745    * <!-- end-user-doc -->
746    * @generated
747    */

748   public void setTestsPackageSuffix(String JavaDoc newTestsPackageSuffix)
749   {
750     String JavaDoc oldTestsPackageSuffix = testsPackageSuffix;
751     testsPackageSuffix = newTestsPackageSuffix;
752     if (eNotificationRequired())
753       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX, oldTestsPackageSuffix, testsPackageSuffix));
754   }
755
756   /**
757    * <!-- begin-user-doc -->
758    * <!-- end-user-doc -->
759    * @generated
760    */

761   public boolean isGenerateExampleClass()
762   {
763     return generateExampleClass;
764   }
765
766   /**
767    * <!-- begin-user-doc -->
768    * <!-- end-user-doc -->
769    * @generated
770    */

771   public void setGenerateExampleClass(boolean newGenerateExampleClass)
772   {
773     boolean oldGenerateExampleClass = generateExampleClass;
774     generateExampleClass = newGenerateExampleClass;
775     if (eNotificationRequired())
776       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS, oldGenerateExampleClass, generateExampleClass));
777   }
778
779   public EModelElement getEcoreModelElement()
780   {
781     return getEcorePackage();
782   }
783
784   /**
785    * <!-- begin-user-doc -->
786    * <!-- end-user-doc -->
787    * @generated
788    */

789   public EPackage getEcorePackage()
790   {
791     if (ecorePackage != null && ecorePackage.eIsProxy())
792     {
793       EPackage oldEcorePackage = ecorePackage;
794       ecorePackage = (EPackage)eResolveProxy((InternalEObject)ecorePackage);
795       if (ecorePackage != oldEcorePackage)
796       {
797         if (eNotificationRequired())
798           eNotify(new ENotificationImpl(this, Notification.RESOLVE, GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE, oldEcorePackage, ecorePackage));
799       }
800     }
801     return ecorePackage;
802   }
803
804   /**
805    * <!-- begin-user-doc -->
806    * <!-- end-user-doc -->
807    * @generated
808    */

809   public EPackage basicGetEcorePackage()
810   {
811     return ecorePackage;
812   }
813
814   /**
815    * <!-- begin-user-doc -->
816    * <!-- end-user-doc -->
817    * @generated
818    */

819   public void setEcorePackage(EPackage newEcorePackage)
820   {
821     EPackage oldEcorePackage = ecorePackage;
822     ecorePackage = newEcorePackage;
823     if (eNotificationRequired())
824       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE, oldEcorePackage, ecorePackage));
825   }
826
827   public GenModel getGenModel()
828   {
829     GenModel result = getGenModelGen();
830     if (result == null && eContainer() != null)
831     {
832       result = ((GenBase)eContainer()).getGenModel();
833     }
834
835     return result;
836   }
837
838   /**
839    * <!-- begin-user-doc -->
840    * <!-- end-user-doc -->
841    * @generated
842    */

843   public GenModel getGenModelGen()
844   {
845     if (eContainerFeatureID != GenModelPackage.GEN_PACKAGE__GEN_MODEL) return null;
846     return (GenModel)eContainer;
847   }
848
849   /**
850    * <!-- begin-user-doc -->
851    * <!-- end-user-doc -->
852    * @generated
853    */

854   public void setGenModel(GenModel newGenModel)
855   {
856     if (newGenModel != eContainer || (eContainerFeatureID != GenModelPackage.GEN_PACKAGE__GEN_MODEL && newGenModel != null))
857     {
858       if (EcoreUtil.isAncestor(this, newGenModel))
859         throw new IllegalArgumentException JavaDoc("Recursive containment not allowed for " + toString());
860       NotificationChain msgs = null;
861       if (eContainer != null)
862         msgs = eBasicRemoveFromContainer(msgs);
863       if (newGenModel != null)
864         msgs = ((InternalEObject)newGenModel).eInverseAdd(this, GenModelPackage.GEN_MODEL__GEN_PACKAGES, GenModel.class, msgs);
865       msgs = eBasicSetContainer((InternalEObject)newGenModel, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs);
866       if (msgs != null) msgs.dispatch();
867     }
868     else if (eNotificationRequired())
869       eNotify(new ENotificationImpl(this, Notification.SET, GenModelPackage.GEN_PACKAGE__GEN_MODEL, newGenModel, newGenModel));
870   }
871
872   /**
873    * <!-- begin-user-doc -->
874    * <!-- end-user-doc -->
875    * @generated
876    */

877   public EList getGenEnums()
878   {
879     if (genEnums == null)
880     {
881       genEnums = new EObjectContainmentEList(GenEnum.class, this, GenModelPackage.GEN_PACKAGE__GEN_ENUMS);
882     }
883     return genEnums;
884   }
885
886   /**
887    * <!-- begin-user-doc -->
888    * <!-- end-user-doc -->
889    * @generated
890    */

891   public EList getGenDataTypes()
892   {
893     if (genDataTypes == null)
894     {
895       genDataTypes = new EObjectContainmentEList(GenDataType.class, this, GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES);
896     }
897     return genDataTypes;
898   }
899
900   /**
901    * <!-- begin-user-doc -->
902    * <!-- end-user-doc -->
903    * @generated
904    */

905   public EList getGenClasses()
906   {
907     if (genClasses == null)
908     {
909       genClasses = new EObjectContainmentEList(GenClass.class, this, GenModelPackage.GEN_PACKAGE__GEN_CLASSES);
910     }
911     return genClasses;
912   }
913
914   /**
915    * <!-- begin-user-doc -->
916    * <!-- end-user-doc -->
917    * @generated
918    */

919   public EList getNestedGenPackages()
920   {
921     if (nestedGenPackages == null)
922     {
923       nestedGenPackages = new EObjectContainmentEList(GenPackage.class, this, GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES);
924     }
925     return nestedGenPackages;
926   }
927
928   /**
929    * <!-- begin-user-doc -->
930    * <!-- end-user-doc -->
931    * @generated modifiable
932    */

933   public EList getGenClassifiers()
934   {
935     EList result = new BasicEList();
936     result.addAll(getGenClasses());
937     result.addAll(getGenEnums());
938     result.addAll(getGenDataTypes());
939     return result;
940   }
941
942   /**
943    * <!-- begin-user-doc -->
944    * <!-- end-user-doc -->
945    * @generated
946    */

947   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
948   {
949     if (featureID >= 0)
950     {
951       switch (eDerivedStructuralFeatureID(featureID, baseClass))
952       {
953         case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
954           if (eContainer != null)
955             msgs = eBasicRemoveFromContainer(msgs);
956           return eBasicSetContainer(otherEnd, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs);
957         default:
958           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
959       }
960     }
961     if (eContainer != null)
962       msgs = eBasicRemoveFromContainer(msgs);
963     return eBasicSetContainer(otherEnd, featureID, msgs);
964   }
965
966   /**
967    * <!-- begin-user-doc -->
968    * <!-- end-user-doc -->
969    * @generated
970    */

971   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
972   {
973     if (featureID >= 0)
974     {
975       switch (eDerivedStructuralFeatureID(featureID, baseClass))
976       {
977         case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
978           return eBasicSetContainer(null, GenModelPackage.GEN_PACKAGE__GEN_MODEL, msgs);
979         case GenModelPackage.GEN_PACKAGE__GEN_ENUMS:
980           return ((InternalEList)getGenEnums()).basicRemove(otherEnd, msgs);
981         case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES:
982           return ((InternalEList)getGenDataTypes()).basicRemove(otherEnd, msgs);
983         case GenModelPackage.GEN_PACKAGE__GEN_CLASSES:
984           return ((InternalEList)getGenClasses()).basicRemove(otherEnd, msgs);
985         case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES:
986           return ((InternalEList)getNestedGenPackages()).basicRemove(otherEnd, msgs);
987         default:
988           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
989       }
990     }
991     return eBasicSetContainer(null, featureID, msgs);
992   }
993
994   /**
995    * <!-- begin-user-doc -->
996    * <!-- end-user-doc -->
997    * @generated
998    */

999   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
1000  {
1001    if (eContainerFeatureID >= 0)
1002    {
1003      switch (eContainerFeatureID)
1004      {
1005        case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
1006          return eContainer.eInverseRemove(this, GenModelPackage.GEN_MODEL__GEN_PACKAGES, GenModel.class, msgs);
1007        default:
1008          return eDynamicBasicRemoveFromContainer(msgs);
1009      }
1010    }
1011    return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
1012  }
1013
1014  /**
1015   * <!-- begin-user-doc -->
1016   * <!-- end-user-doc -->
1017   * @generated
1018   */

1019  public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
1020  {
1021    switch (eDerivedStructuralFeatureID(eFeature))
1022    {
1023      case GenModelPackage.GEN_PACKAGE__PREFIX:
1024        return getPrefix();
1025      case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE:
1026        return getBasePackage();
1027      case GenModelPackage.GEN_PACKAGE__RESOURCE:
1028        return getResource();
1029      case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY:
1030        return isDisposableProviderFactory() ? Boolean.TRUE : Boolean.FALSE;
1031      case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY:
1032        return isAdapterFactory() ? Boolean.TRUE : Boolean.FALSE;
1033      case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION:
1034        return isLoadInitialization() ? Boolean.TRUE : Boolean.FALSE;
1035      case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX:
1036        return getInterfacePackageSuffix();
1037      case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX:
1038        return getClassPackageSuffix();
1039      case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX:
1040        return getUtilityPackageSuffix();
1041      case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX:
1042        return getProviderPackageSuffix();
1043      case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX:
1044        return getPresentationPackageSuffix();
1045      case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX:
1046        return getTestsPackageSuffix();
1047      case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS:
1048        return isGenerateExampleClass() ? Boolean.TRUE : Boolean.FALSE;
1049      case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE:
1050        if (resolve) return getEcorePackage();
1051        return basicGetEcorePackage();
1052      case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
1053        return getGenModel();
1054      case GenModelPackage.GEN_PACKAGE__GEN_ENUMS:
1055        return getGenEnums();
1056      case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES:
1057        return getGenDataTypes();
1058      case GenModelPackage.GEN_PACKAGE__GEN_CLASSES:
1059        return getGenClasses();
1060      case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES:
1061        return getNestedGenPackages();
1062      case GenModelPackage.GEN_PACKAGE__GEN_CLASSIFIERS:
1063        return getGenClassifiers();
1064    }
1065    return eDynamicGet(eFeature, resolve);
1066  }
1067
1068  /**
1069   * <!-- begin-user-doc -->
1070   * <!-- end-user-doc -->
1071   * @generated
1072   */

1073  public boolean eIsSet(EStructuralFeature eFeature)
1074  {
1075    switch (eDerivedStructuralFeatureID(eFeature))
1076    {
1077      case GenModelPackage.GEN_PACKAGE__PREFIX:
1078        return PREFIX_EDEFAULT == null ? prefix != null : !PREFIX_EDEFAULT.equals(prefix);
1079      case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE:
1080        return BASE_PACKAGE_EDEFAULT == null ? basePackage != null : !BASE_PACKAGE_EDEFAULT.equals(basePackage);
1081      case GenModelPackage.GEN_PACKAGE__RESOURCE:
1082        return resource != RESOURCE_EDEFAULT;
1083      case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY:
1084        return disposableProviderFactory != DISPOSABLE_PROVIDER_FACTORY_EDEFAULT;
1085      case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY:
1086        return adapterFactory != ADAPTER_FACTORY_EDEFAULT;
1087      case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION:
1088        return loadInitialization != LOAD_INITIALIZATION_EDEFAULT;
1089      case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX:
1090        return INTERFACE_PACKAGE_SUFFIX_EDEFAULT == null ? interfacePackageSuffix != null : !INTERFACE_PACKAGE_SUFFIX_EDEFAULT.equals(interfacePackageSuffix);
1091      case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX:
1092        return CLASS_PACKAGE_SUFFIX_EDEFAULT == null ? classPackageSuffix != null : !CLASS_PACKAGE_SUFFIX_EDEFAULT.equals(classPackageSuffix);
1093      case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX:
1094        return UTILITY_PACKAGE_SUFFIX_EDEFAULT == null ? utilityPackageSuffix != null : !UTILITY_PACKAGE_SUFFIX_EDEFAULT.equals(utilityPackageSuffix);
1095      case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX:
1096        return PROVIDER_PACKAGE_SUFFIX_EDEFAULT == null ? providerPackageSuffix != null : !PROVIDER_PACKAGE_SUFFIX_EDEFAULT.equals(providerPackageSuffix);
1097      case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX:
1098        return PRESENTATION_PACKAGE_SUFFIX_EDEFAULT == null ? presentationPackageSuffix != null : !PRESENTATION_PACKAGE_SUFFIX_EDEFAULT.equals(presentationPackageSuffix);
1099      case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX:
1100        return TESTS_PACKAGE_SUFFIX_EDEFAULT == null ? testsPackageSuffix != null : !TESTS_PACKAGE_SUFFIX_EDEFAULT.equals(testsPackageSuffix);
1101      case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS:
1102        return generateExampleClass != GENERATE_EXAMPLE_CLASS_EDEFAULT;
1103      case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE:
1104        return ecorePackage != null;
1105      case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
1106        return getGenModel() != null;
1107      case GenModelPackage.GEN_PACKAGE__GEN_ENUMS:
1108        return genEnums != null && !genEnums.isEmpty();
1109      case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES:
1110        return genDataTypes != null && !genDataTypes.isEmpty();
1111      case GenModelPackage.GEN_PACKAGE__GEN_CLASSES:
1112        return genClasses != null && !genClasses.isEmpty();
1113      case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES:
1114        return nestedGenPackages != null && !nestedGenPackages.isEmpty();
1115      case GenModelPackage.GEN_PACKAGE__GEN_CLASSIFIERS:
1116        return !getGenClassifiers().isEmpty();
1117    }
1118    return eDynamicIsSet(eFeature);
1119  }
1120
1121  /**
1122   * <!-- begin-user-doc -->
1123   * <!-- end-user-doc -->
1124   * @generated
1125   */

1126  public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
1127  {
1128    switch (eDerivedStructuralFeatureID(eFeature))
1129    {
1130      case GenModelPackage.GEN_PACKAGE__PREFIX:
1131        setPrefix((String JavaDoc)newValue);
1132        return;
1133      case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE:
1134        setBasePackage((String JavaDoc)newValue);
1135        return;
1136      case GenModelPackage.GEN_PACKAGE__RESOURCE:
1137        setResource((GenResourceKind)newValue);
1138        return;
1139      case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY:
1140        setDisposableProviderFactory(((Boolean JavaDoc)newValue).booleanValue());
1141        return;
1142      case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY:
1143        setAdapterFactory(((Boolean JavaDoc)newValue).booleanValue());
1144        return;
1145      case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION:
1146        setLoadInitialization(((Boolean JavaDoc)newValue).booleanValue());
1147        return;
1148      case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX:
1149        setInterfacePackageSuffix((String JavaDoc)newValue);
1150        return;
1151      case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX:
1152        setClassPackageSuffix((String JavaDoc)newValue);
1153        return;
1154      case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX:
1155        setUtilityPackageSuffix((String JavaDoc)newValue);
1156        return;
1157      case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX:
1158        setProviderPackageSuffix((String JavaDoc)newValue);
1159        return;
1160      case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX:
1161        setPresentationPackageSuffix((String JavaDoc)newValue);
1162        return;
1163      case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX:
1164        setTestsPackageSuffix((String JavaDoc)newValue);
1165        return;
1166      case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS:
1167        setGenerateExampleClass(((Boolean JavaDoc)newValue).booleanValue());
1168        return;
1169      case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE:
1170        setEcorePackage((EPackage)newValue);
1171        return;
1172      case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
1173        setGenModel((GenModel)newValue);
1174        return;
1175      case GenModelPackage.GEN_PACKAGE__GEN_ENUMS:
1176        getGenEnums().clear();
1177        getGenEnums().addAll((Collection JavaDoc)newValue);
1178        return;
1179      case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES:
1180        getGenDataTypes().clear();
1181        getGenDataTypes().addAll((Collection JavaDoc)newValue);
1182        return;
1183      case GenModelPackage.GEN_PACKAGE__GEN_CLASSES:
1184        getGenClasses().clear();
1185        getGenClasses().addAll((Collection JavaDoc)newValue);
1186        return;
1187      case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES:
1188        getNestedGenPackages().clear();
1189        getNestedGenPackages().addAll((Collection JavaDoc)newValue);
1190        return;
1191    }
1192    eDynamicSet(eFeature, newValue);
1193  }
1194
1195  /**
1196   * <!-- begin-user-doc -->
1197   * <!-- end-user-doc -->
1198   * @generated
1199   */

1200  public void eUnset(EStructuralFeature eFeature)
1201  {
1202    switch (eDerivedStructuralFeatureID(eFeature))
1203    {
1204      case GenModelPackage.GEN_PACKAGE__PREFIX:
1205        setPrefix(PREFIX_EDEFAULT);
1206        return;
1207      case GenModelPackage.GEN_PACKAGE__BASE_PACKAGE:
1208        setBasePackage(BASE_PACKAGE_EDEFAULT);
1209        return;
1210      case GenModelPackage.GEN_PACKAGE__RESOURCE:
1211        setResource(RESOURCE_EDEFAULT);
1212        return;
1213      case GenModelPackage.GEN_PACKAGE__DISPOSABLE_PROVIDER_FACTORY:
1214        setDisposableProviderFactory(DISPOSABLE_PROVIDER_FACTORY_EDEFAULT);
1215        return;
1216      case GenModelPackage.GEN_PACKAGE__ADAPTER_FACTORY:
1217        setAdapterFactory(ADAPTER_FACTORY_EDEFAULT);
1218        return;
1219      case GenModelPackage.GEN_PACKAGE__LOAD_INITIALIZATION:
1220        setLoadInitialization(LOAD_INITIALIZATION_EDEFAULT);
1221        return;
1222      case GenModelPackage.GEN_PACKAGE__INTERFACE_PACKAGE_SUFFIX:
1223        setInterfacePackageSuffix(INTERFACE_PACKAGE_SUFFIX_EDEFAULT);
1224        return;
1225      case GenModelPackage.GEN_PACKAGE__CLASS_PACKAGE_SUFFIX:
1226        setClassPackageSuffix(CLASS_PACKAGE_SUFFIX_EDEFAULT);
1227        return;
1228      case GenModelPackage.GEN_PACKAGE__UTILITY_PACKAGE_SUFFIX:
1229        setUtilityPackageSuffix(UTILITY_PACKAGE_SUFFIX_EDEFAULT);
1230        return;
1231      case GenModelPackage.GEN_PACKAGE__PROVIDER_PACKAGE_SUFFIX:
1232        setProviderPackageSuffix(PROVIDER_PACKAGE_SUFFIX_EDEFAULT);
1233        return;
1234      case GenModelPackage.GEN_PACKAGE__PRESENTATION_PACKAGE_SUFFIX:
1235        setPresentationPackageSuffix(PRESENTATION_PACKAGE_SUFFIX_EDEFAULT);
1236        return;
1237      case GenModelPackage.GEN_PACKAGE__TESTS_PACKAGE_SUFFIX:
1238        setTestsPackageSuffix(TESTS_PACKAGE_SUFFIX_EDEFAULT);
1239        return;
1240      case GenModelPackage.GEN_PACKAGE__GENERATE_EXAMPLE_CLASS:
1241        setGenerateExampleClass(GENERATE_EXAMPLE_CLASS_EDEFAULT);
1242        return;
1243      case GenModelPackage.GEN_PACKAGE__ECORE_PACKAGE:
1244        setEcorePackage((EPackage)null);
1245        return;
1246      case GenModelPackage.GEN_PACKAGE__GEN_MODEL:
1247        setGenModel((GenModel)null);
1248        return;
1249      case GenModelPackage.GEN_PACKAGE__GEN_ENUMS:
1250        getGenEnums().clear();
1251        return;
1252      case GenModelPackage.GEN_PACKAGE__GEN_DATA_TYPES:
1253        getGenDataTypes().clear();
1254        return;
1255      case GenModelPackage.GEN_PACKAGE__GEN_CLASSES:
1256        getGenClasses().clear();
1257        return;
1258      case GenModelPackage.GEN_PACKAGE__NESTED_GEN_PACKAGES:
1259        getNestedGenPackages().clear();
1260        return;
1261    }
1262    eDynamicUnset(eFeature);
1263  }
1264
1265  /**
1266   * <!-- begin-user-doc -->
1267   * <!-- end-user-doc -->
1268   * @generated
1269   */

1270  public String JavaDoc toString()
1271  {
1272    if (eIsProxy()) return super.toString();
1273
1274    StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
1275    result.append(" (prefix: ");
1276    result.append(prefix);
1277    result.append(", basePackage: ");
1278    result.append(basePackage);
1279    result.append(", resource: ");
1280    result.append(resource);
1281    result.append(", disposableProviderFactory: ");
1282    result.append(disposableProviderFactory);
1283    result.append(", adapterFactory: ");
1284    result.append(adapterFactory);
1285    result.append(", loadInitialization: ");
1286    result.append(loadInitialization);
1287    result.append(", interfacePackageSuffix: ");
1288    result.append(interfacePackageSuffix);
1289    result.append(", classPackageSuffix: ");
1290    result.append(classPackageSuffix);
1291    result.append(", utilityPackageSuffix: ");
1292    result.append(utilityPackageSuffix);
1293    result.append(", providerPackageSuffix: ");
1294    result.append(providerPackageSuffix);
1295    result.append(", presentationPackageSuffix: ");
1296    result.append(presentationPackageSuffix);
1297    result.append(", testsPackageSuffix: ");
1298    result.append(testsPackageSuffix);
1299    result.append(", generateExampleClass: ");
1300    result.append(generateExampleClass);
1301    result.append(')');
1302    return result.toString();
1303  }
1304
1305  public String JavaDoc getName()
1306  {
1307    return getPackageName();
1308  }
1309
1310  public String JavaDoc getPackageName()
1311  {
1312    return getEcorePackage().getName();
1313  }
1314
1315  public String JavaDoc getInterfacePackageName()
1316  {
1317    return getQualifiedPackageName(getInterfacePackageSuffix());
1318  }
1319
1320  public String JavaDoc getClassPackageName()
1321  {
1322    return getQualifiedPackageName(getClassPackageSuffix());
1323  }
1324
1325  public String JavaDoc getUtilitiesPackageName()
1326  {
1327    return getQualifiedPackageName(getUtilityPackageSuffix());
1328  }
1329
1330  public String JavaDoc getTestsPackageName()
1331  {
1332    return getQualifiedPackageName(getTestsPackageSuffix());
1333  }
1334
1335  public String JavaDoc getPackageID()
1336  {
1337    return getEcorePackage().getNsPrefix();
1338  }
1339
1340  public String JavaDoc getNSName()
1341  {
1342    return getEcorePackage().getNsPrefix();
1343  }
1344
1345  public String JavaDoc getNSURI()
1346  {
1347    return getEcorePackage().getNsURI();
1348  }
1349
1350  public String JavaDoc getPackageInterfaceName()
1351  {
1352    return getPrefixedName("Package");
1353  }
1354
1355  public String JavaDoc getQualifiedPackageInterfaceName()
1356  {
1357    return getInterfacePackageName() + "." + getPackageInterfaceName();
1358  }
1359
1360  public String JavaDoc getImportedPackageInterfaceName()
1361  {
1362    return getGenModel().getImportedName(getQualifiedPackageInterfaceName());
1363  }
1364
1365  public String JavaDoc getUncapPackageInterfaceName()
1366  {
1367    return uncapPrefixedName(getPackageInterfaceName(), true);
1368  }
1369
1370  public String JavaDoc getPackageClassName()
1371  {
1372    return getImplClassName(getPackageInterfaceName());
1373  }
1374  
1375  public String JavaDoc getQualifiedPackageClassName()
1376  {
1377    return getClassPackageName() + "." + getPackageClassName();
1378  }
1379
1380  public String JavaDoc getImportedPackageClassName()
1381  {
1382    return getGenModel().getImportedName(getQualifiedPackageClassName());
1383  }
1384
1385  public String JavaDoc getFactoryInterfaceName()
1386  {
1387    return getPrefixedName("Factory");
1388  }
1389
1390  public String JavaDoc getQualifiedFactoryInterfaceName()
1391  {
1392    return getInterfacePackageName() + "." + getFactoryInterfaceName();
1393  }
1394
1395  public String JavaDoc getImportedFactoryInterfaceName()
1396  {
1397    return getGenModel().getImportedName(getQualifiedFactoryInterfaceName());
1398  }
1399
1400  public String JavaDoc getUncapFactoryInterfaceName()
1401  {
1402    return uncapPrefixedName(getFactoryInterfaceName(), true);
1403  }
1404
1405  public String JavaDoc getFactoryClassName()
1406  {
1407    return getImplClassName(getFactoryInterfaceName());
1408  }
1409
1410  public String JavaDoc getQualifiedFactoryClassName()
1411  {
1412    return getClassPackageName() + "." + getFactoryClassName();
1413  }
1414
1415  public String JavaDoc getImportedFactoryClassName()
1416  {
1417    return getGenModel().getImportedName(getQualifiedFactoryClassName());
1418  }
1419
1420  public String JavaDoc getAdapterFactoryClassName()
1421  {
1422    return getPrefixedName("AdapterFactory");
1423  }
1424
1425  public String JavaDoc getQualifiedAdapterFactoryClassName()
1426  {
1427    return getUtilitiesPackageName() + "." + getAdapterFactoryClassName();
1428  }
1429
1430  public String JavaDoc getImportedAdapterFactoryClassName()
1431  {
1432    return getGenModel().getImportedName(getQualifiedAdapterFactoryClassName());
1433  }
1434
1435  public String JavaDoc getUncapAdapterFactoryClassName()
1436  {
1437    return uncapPrefixedName(getAdapterFactoryClassName(), true);
1438  }
1439
1440  public String JavaDoc getSwitchClassName()
1441  {
1442    return getPrefixedName("Switch");
1443  }
1444
1445  public String JavaDoc getTestSuiteClassName()
1446  {
1447    return getPrefixedName("Tests");
1448  }
1449  
1450  public String JavaDoc getExampleClassName()
1451  {
1452    return getPrefixedName("Example");
1453  }
1454
1455  public String JavaDoc getQualifiedTestSuiteClassName()
1456  {
1457    return getTestsPackageName() + "." + getPrefixedName("Tests");
1458  }
1459
1460  public String JavaDoc getImportedTestSuiteClassName()
1461  {
1462    return getGenModel().getImportedName(getQualifiedTestSuiteClassName());
1463  }
1464
1465  protected static final boolean NO_CONSTRAINTS = "true".equals(System.getProperty("EMF_NO_CONSTRAINTS"));
1466
1467  public boolean hasConstraints()
1468  {
1469    if (NO_CONSTRAINTS) return false;
1470    for (Iterator JavaDoc i = getGenClassifiers().iterator(); i.hasNext(); )
1471    {
1472      GenClassifier genClassifier = (GenClassifier)i.next();
1473      if (!genClassifier.getGenConstraints().isEmpty())
1474      {
1475        return true;
1476      }
1477    }
1478    return false;
1479  }
1480
1481  public String JavaDoc getValidatorClassName()
1482  {
1483    return getPrefixedName("Validator");
1484  }
1485
1486  public String JavaDoc getImportedValidatorClassName()
1487  {
1488    return getGenModel().getImportedName(getUtilitiesPackageName() + "." + getPrefixedName("Validator"));
1489  }
1490
1491  protected String JavaDoc getPrefixedName(String JavaDoc name)
1492  {
1493    if (getPrefix() != null)
1494    {
1495      return getPrefix() + name;
1496    }
1497    return name;
1498  }
1499
1500  public List JavaDoc getAllGenDataTypes()
1501  {
1502    List JavaDoc result = new ArrayList JavaDoc();
1503    result.addAll(getGenEnums());
1504    result.addAll(getGenDataTypes());
1505    return result;
1506  }
1507
1508  public List JavaDoc getOrderedGenClasses()
1509  {
1510    List JavaDoc result = new ArrayList JavaDoc();
1511    Set JavaDoc resultSet = new HashSet JavaDoc();
1512
1513    for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
1514    {
1515      List JavaDoc extendChain = new LinkedList JavaDoc();
1516      for (GenClass genClass = (GenClass)iter.next(); genClass != null; genClass = genClass.getBaseGenClass())
1517      {
1518        if (this == genClass.getGenPackage() && resultSet.add(genClass))
1519        {
1520          extendChain.add(0, genClass);
1521        }
1522      }
1523      result.addAll(extendChain);
1524    }
1525    return result;
1526  }
1527
1528  public List JavaDoc getOrderedGenClassifiers()
1529  {
1530    List JavaDoc result = new ArrayList JavaDoc(getOrderedGenClasses());
1531    result.addAll(getGenEnums());
1532    result.addAll(getGenDataTypes());
1533    return result;
1534  }
1535
1536  public String JavaDoc getClassifierID(GenClassifier genClassifier)
1537  {
1538    return genClassifier.getClassifierID();
1539  }
1540
1541  public int getClassifierValue(GenClassifier genClassifier)
1542  {
1543    return getGenClassifiers().indexOf(genClassifier);
1544  }
1545
1546  public int getLocalClassifierIndex(GenClassifier genClassifier)
1547  {
1548    return getEcorePackage().getEClassifiers().indexOf(genClassifier.getEcoreClassifier());
1549  }
1550
1551  public List JavaDoc getPackageSimpleDependencies()
1552  {
1553    return dependencyHelper.getSimpleDependencies();
1554  }
1555
1556  public List JavaDoc getPackageInterDependencies()
1557  {
1558    return dependencyHelper.getInterDependencies();
1559  }
1560
1561  public List JavaDoc getPackageLoadInterDependencies()
1562  {
1563    return dependencyHelper.getLoadInterDependencies();
1564  }
1565
1566  public List JavaDoc getPackageBuildInterDependencies()
1567  {
1568    return dependencyHelper.getBuildInterDependencies();
1569  }
1570
1571  public List JavaDoc getPackageInitializationDependencies()
1572  {
1573    return dependencyHelper.getInitializationDependencies();
1574  }
1575
1576  public String JavaDoc getPackageInstanceVariable(GenPackage genPackage)
1577  {
1578    if (genPackage == this) return "this";
1579    if (genPackage == ecoreGenPackage) return "ecorePackage";
1580
1581    return "the" + dependencyHelper.getUniqueName(genPackage);
1582  }
1583
1584  private DependencyHelper dependencyHelper = null;
1585
1586  private class DependencyHelper extends GenBaseImpl.UniqueNameHelper
1587  {
1588    private List JavaDoc simpleDependencies;
1589    private List JavaDoc interDependencies;
1590    private List JavaDoc loadInterDependencies;
1591    private List JavaDoc buildInterDependencies;
1592    private List JavaDoc initializationDependencies;
1593
1594    public DependencyHelper()
1595    {
1596      super(2 * (getGenModel().getGenPackages().size() + getGenModel().getUsedGenPackages().size()));
1597
1598      add(GenPackageImpl.this);
1599
1600      simpleDependencies = new ArrayList JavaDoc();
1601      collectPackages(simpleDependencies, getGenModel().getUsedGenPackages(), 1);
1602      addAll(simpleDependencies);
1603      
1604      interDependencies = new ArrayList JavaDoc();
1605      collectPackages(interDependencies, getGenModel().getGenPackages(), -1);
1606      interDependencies.remove(GenPackageImpl.this);
1607      addAll(interDependencies);
1608
1609      loadInterDependencies = new ArrayList JavaDoc();
1610      buildInterDependencies = new ArrayList JavaDoc();
1611      for (Iterator JavaDoc i = interDependencies.iterator(); i.hasNext(); )
1612      {
1613        GenPackage genPackage = (GenPackage)i.next();
1614        if (genPackage.isLoadedInitialization())
1615        {
1616          loadInterDependencies.add(genPackage);
1617        }
1618        else
1619        {
1620          buildInterDependencies.add(genPackage);
1621        }
1622      }
1623
1624      initializationDependencies = new UniqueEList();
1625      for (Iterator JavaDoc i = getSubGenPackages().iterator(); i.hasNext(); )
1626      {
1627        initializationDependencies.add(i.next());
1628      }
1629      for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
1630      {
1631        GenClass genClass = (GenClass)i.next();
1632        for (Iterator JavaDoc j = genClass.getBaseGenClasses().iterator(); j.hasNext(); )
1633        {
1634          GenClass baseGenClass = (GenClass)j.next();
1635          initializationDependencies.add(baseGenClass.getGenPackage());
1636        }
1637        for (Iterator JavaDoc j = genClass.getGenFeatures().iterator(); j.hasNext(); )
1638        {
1639          GenFeature genFeature = (GenFeature)j.next();
1640          initializationDependencies.add(genFeature.getTypeGenPackage());
1641
1642          if (genFeature.isReferenceType())
1643          {
1644            GenFeature reverseGenFeature = genFeature.getReverse();
1645            if (reverseGenFeature != null)
1646            {
1647              initializationDependencies.add(reverseGenFeature.getGenPackage());
1648            }
1649          }
1650
1651          GenFeature delegateFeature = genFeature.getDelegateFeature();
1652          if (delegateFeature != null)
1653          {
1654            initializationDependencies.add(delegateFeature.getGenPackage());
1655          }
1656        }
1657        for (Iterator JavaDoc j = genClass.getGenOperations().iterator(); j.hasNext(); )
1658        {
1659          GenOperation genOperation = (GenOperation)j.next();
1660          if (!genOperation.isVoid())
1661          {
1662            initializationDependencies.add(genOperation.getTypeGenPackage());
1663          }
1664          for (Iterator JavaDoc k = genOperation.getGenParameters().iterator(); k.hasNext(); )
1665          {
1666            GenParameter genParameter = (GenParameter)k.next();
1667            initializationDependencies.add(genParameter.getTypeGenPackage());
1668          }
1669          for (Iterator JavaDoc k = genOperation.getGenExceptions().iterator(); k.hasNext(); )
1670          {
1671            GenClassifier genClassifier = (GenClassifier)k.next();
1672            initializationDependencies.add(genClassifier.getGenPackage());
1673          }
1674        }
1675      }
1676      for (Iterator JavaDoc i = getGenDataTypes().iterator(); i.hasNext(); )
1677      {
1678        GenDataType genDataType = (GenDataType)i.next();
1679        GenDataType baseType = genDataType.getBaseType();
1680        if (baseType != null)
1681        {
1682          initializationDependencies.add(baseType.getGenPackage());
1683        }
1684        GenDataType itemType = genDataType.getItemType();
1685        if (itemType != null)
1686        {
1687          initializationDependencies.add(itemType.getGenPackage());
1688        }
1689        for (Iterator JavaDoc j = genDataType.getMemberTypes().iterator(); j.hasNext(); )
1690        {
1691          GenDataType memberType = (GenDataType)j.next();
1692          initializationDependencies.add(memberType.getGenPackage());
1693        }
1694      }
1695
1696      if (initializationDependencies.contains(xmlTypeGenPackage) && !xmlTypeGenPackage.getNSURI().equals(getNSURI()))
1697      {
1698        simpleDependencies.add(xmlTypeGenPackage);
1699      }
1700      if (initializationDependencies.contains(xmlNamespaceGenPackage))
1701      {
1702        simpleDependencies.add(xmlNamespaceGenPackage);
1703      }
1704
1705      initializationDependencies.remove(GenPackageImpl.this);
1706      initializationDependencies.remove(findGenPackage(EcorePackage.eINSTANCE));
1707    }
1708
1709    protected String JavaDoc getName(Object JavaDoc o)
1710    {
1711      return ((GenPackage)o).getPackageInterfaceName();
1712    }
1713
1714    public List JavaDoc getSimpleDependencies()
1715    {
1716      return simpleDependencies;
1717    }
1718
1719    public List JavaDoc getInterDependencies()
1720    {
1721      return interDependencies;
1722    }
1723
1724    public List JavaDoc getLoadInterDependencies()
1725    {
1726      return loadInterDependencies;
1727    }
1728
1729    public List JavaDoc getBuildInterDependencies()
1730    {
1731      return buildInterDependencies;
1732    }
1733
1734    public List JavaDoc getInitializationDependencies()
1735    {
1736      return initializationDependencies;
1737    }
1738  }
1739  
1740  /**
1741   * Collects into result nested GenPackages to the specified depth,
1742   * not counting those without classifiers (for which nothing is ever
1743   * generated); -1 for no limit.
1744   */

1745  protected void collectPackages(List JavaDoc result, List JavaDoc genPackages, int depth)
1746  {
1747    if (depth == 0) return;
1748
1749    for (Iterator JavaDoc i = genPackages.iterator(); i.hasNext(); )
1750    {
1751      GenPackage genPackage = (GenPackage)i.next();
1752      if (genPackage.hasClassifiers())
1753      {
1754        result.add(genPackage);
1755        collectPackages(result, genPackage.getNestedGenPackages(), depth - 1);
1756      }
1757      else
1758      {
1759        collectPackages(result, genPackage.getNestedGenPackages(), depth);
1760      }
1761    }
1762  }
1763
1764  public List JavaDoc getSubGenPackages()
1765  {
1766    List JavaDoc result = new ArrayList JavaDoc();
1767    collectPackages(result, getNestedGenPackages(), 1);
1768    return result;
1769  }
1770
1771  public GenPackage getSuperGenPackage()
1772  {
1773    EObject container = eContainer();
1774    while (container instanceof GenPackage)
1775    {
1776      GenPackage outer = (GenPackage)container;
1777      if (this == outer)
1778      {
1779       throw new RuntimeException JavaDoc("inheritance loop at " + getPackageName());
1780      }
1781
1782      if (outer.hasClassifiers()) return outer;
1783      container = outer.eContainer();
1784    }
1785    return null;
1786  }
1787
1788  public GenPackage getRootGenPackage()
1789  {
1790    GenPackage root = this;
1791    while (true)
1792    {
1793      GenPackage container = root.getSuperGenPackage();
1794      if (container == null)
1795      {
1796        return root;
1797      }
1798      else if (this == container)
1799      {
1800        throw new RuntimeException JavaDoc("inheritance loop at " + getPackageName());
1801      }
1802      root = container;
1803    }
1804  }
1805
1806  public boolean isLoadingInitialization()
1807  {
1808    return getRootGenPackage() == this && needsLoadInitialization(this);
1809  }
1810
1811  public boolean isLoadedInitialization()
1812  {
1813    return needsLoadInitialization(getRootGenPackage());
1814  }
1815
1816  private boolean needsLoadInitialization(GenPackage genPackage)
1817  {
1818    if (genPackage.isLoadInitialization()) return true;
1819    
1820    for (Iterator JavaDoc i = genPackage.getSubGenPackages().iterator(); i.hasNext(); )
1821    {
1822      if (needsLoadInitialization((GenPackage)i.next())) return true;
1823    }
1824    return false;
1825  }
1826  
1827  public boolean isEcorePackage()
1828  {
1829    return (EcorePackage.eNS_URI.equals(getNSURI()));
1830  }
1831
1832  public boolean hasJavaLangConflict()
1833  {
1834    return !getJavaLangConflicts().isEmpty();
1835  }
1836
1837  public List JavaDoc getJavaLangConflicts()
1838  {
1839    List JavaDoc result = new ArrayList JavaDoc();
1840    for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
1841    {
1842      GenClass genClass = (GenClass)i.next();
1843      String JavaDoc name = genClass.getName();
1844      if (CodeGenUtil.isJavaDefaultType(name))
1845      {
1846        result.add(name);
1847      }
1848    }
1849    return result;
1850  }
1851
1852  public boolean hasInterfaceImplConflict()
1853  {
1854    Set JavaDoc names = new HashSet JavaDoc();
1855    for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
1856    {
1857      GenClass genClass = (GenClass)i.next();
1858      names.add(genClass.getName());
1859    }
1860
1861    for (Iterator JavaDoc i = names.iterator(); i.hasNext(); )
1862    {
1863      String JavaDoc name = (String JavaDoc)i.next();
1864      if (names.contains(name + "Impl"))
1865      {
1866        return true;
1867      }
1868    }
1869
1870    return false;
1871  }
1872
1873  public List JavaDoc getAllSwitchGenClasses()
1874  {
1875    if (switchHelper == null)
1876    {
1877      switchHelper = new SwitchHelper();
1878    }
1879    return switchHelper.getAllGenClasses();
1880  }
1881
1882  public String JavaDoc getClassUniqueName(GenClass genClass)
1883  {
1884    if (switchHelper == null)
1885    {
1886      switchHelper = new SwitchHelper();
1887    }
1888    return switchHelper.getUniqueName(genClass);
1889  }
1890
1891  private SwitchHelper switchHelper = null;
1892
1893  private class SwitchHelper extends GenBaseImpl.UniqueNameHelper
1894  {
1895    protected List JavaDoc allGenClasses = new LinkedList JavaDoc();
1896    protected List JavaDoc allBaseGenPackages = new UniqueEList();
1897
1898    public SwitchHelper()
1899    {
1900      super(3 * getGenClasses().size());
1901      initLocal();
1902      initBases();
1903    }
1904
1905    protected SwitchHelper(int size)
1906    {
1907      super(size);
1908    }
1909
1910    protected void initLocal()
1911    {
1912      // Add all classes from this package first, to guarantee they get the
1913
// simple names
1914
for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
1915      {
1916        GenClass genClass = (GenClass)i.next();
1917        
1918        // EObject is handled by default case
1919
if (!genClass.isEObject() && add(genClass))
1920        {
1921          allGenClasses.add(genClass);
1922        }
1923      }
1924    }
1925
1926    protected void initBases()
1927    {
1928      // Go through class supertypes to catch any from other packages
1929
for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
1930      {
1931        GenClass genClass = (GenClass)i.next();
1932        if (genClass.isEObject()) continue;
1933
1934        for (Iterator JavaDoc j = genClass.getEcoreClass().getEAllSuperTypes().iterator(); j.hasNext(); )
1935        {
1936          EClass base = (EClass)j.next();
1937          GenClass baseGenClass = findGenClass(base);
1938          if (baseGenClass != null && !baseGenClass.isEObject() && add(baseGenClass))
1939          {
1940            allGenClasses.add(baseGenClass);
1941            if (baseGenClass.getGenPackage() != GenPackageImpl.this)
1942            {
1943              allBaseGenPackages.add(baseGenClass.getGenPackage());
1944            }
1945          }
1946        }
1947      }
1948    }
1949
1950    protected String JavaDoc getName(Object JavaDoc o)
1951    {
1952      return ((GenClassifier)o).getName();
1953    }
1954
1955    protected List JavaDoc getAlternateNames(Object JavaDoc o)
1956    {
1957      GenClassifier genClassifier = (GenClassifier)o;
1958      return Collections.singletonList(genClassifier.getGenPackage().getPrefix() + "_" + genClassifier.getName());
1959    }
1960
1961    public List JavaDoc getAllGenClasses()
1962    {
1963      return allGenClasses;
1964    }
1965  }
1966
1967  public List JavaDoc getAllValidatorBaseGenPackages()
1968  {
1969    if (validatorHelper == null)
1970    {
1971      validatorHelper = new ValidatorHelper();
1972    }
1973    return validatorHelper.getAllBaseGenPackages();
1974  }
1975
1976  public String JavaDoc getValidatorPackageUniqueSafeName(GenPackage genPackage)
1977  {
1978    if (validatorHelper == null)
1979    {
1980      validatorHelper = new ValidatorHelper();
1981    }
1982    return validatorHelper.getPackageUniqueSafeName(genPackage);
1983  }
1984
1985  private ValidatorHelper validatorHelper = null;
1986
1987  private class ValidatorHelper
1988  {
1989    protected List JavaDoc allBaseGenPackages = new UniqueEList();
1990
1991    public ValidatorHelper()
1992    {
1993      init();
1994    }
1995
1996    protected void init()
1997    {
1998      // Go through class supertypes to catch constraints from other packages
1999
for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
2000      {
2001        GenClass genClass = (GenClass)i.next();
2002        if (!genClass.isEObject())
2003        {
2004          for (Iterator JavaDoc j = genClass.getEcoreClass().getEAllSuperTypes().iterator(); j.hasNext(); )
2005          {
2006            EClass base = (EClass)j.next();
2007            GenClass baseGenClass = findGenClass(base);
2008            if (baseGenClass != null &&
2009                  !baseGenClass.isEObject() &&
2010                  baseGenClass.getGenPackage() != GenPackageImpl.this &&
2011                  !baseGenClass.getGenConstraints().isEmpty())
2012            {
2013              allBaseGenPackages.add(baseGenClass.getGenPackage());
2014            }
2015          }
2016        }
2017      }
2018
2019      for (Iterator JavaDoc i = getGenDataTypes().iterator(); i.hasNext(); )
2020      {
2021        GenDataType genDataType = (GenDataType)i.next();
2022        for (GenDataType baseType = genDataType.getBaseType(); baseType != null; baseType = baseType.getBaseType())
2023        {
2024          allBaseGenPackages.add(baseType.getGenPackage());
2025        }
2026        GenDataType itemType = genDataType.getItemType();
2027        if (itemType != null)
2028        {
2029          allBaseGenPackages.add(itemType.getGenPackage());
2030        }
2031        for (Iterator JavaDoc j = genDataType.getMemberTypes().iterator(); j.hasNext(); )
2032        {
2033          GenDataType memberType = (GenDataType)j.next();
2034          allBaseGenPackages.add(memberType.getGenPackage());
2035        }
2036      }
2037
2038      allBaseGenPackages.remove(GenPackageImpl.this);
2039    }
2040
2041    public List JavaDoc getAllBaseGenPackages()
2042    {
2043      return allBaseGenPackages;
2044    }
2045
2046    public String JavaDoc getPackageUniqueSafeName(GenPackage genPackage)
2047    {
2048      return safeName(uncapPrefixedName(genPackage.getPrefix()));
2049    }
2050  }
2051
2052  public void initialize(EPackage ePackage)
2053  {
2054    boolean isDifferentPackage = ePackage != getEcorePackage();
2055    if (isDifferentPackage)
2056    {
2057      setEcorePackage(ePackage);
2058  
2059      if (hasExtendedMetaData(ePackage))
2060      {
2061        setResource(GenResourceKind.XML_LITERAL);
2062      }
2063      setDisposableProviderFactory(true);
2064    }
2065
2066    CLASSIFIER_LOOP:
2067    for (Iterator JavaDoc iter = ePackage.getEClassifiers().iterator(); iter.hasNext(); )
2068    {
2069      EClassifier eClassifier = (EClassifier)iter.next();
2070
2071      for (Iterator JavaDoc j = getGenClassifiers().iterator(); j.hasNext(); )
2072      {
2073        GenClassifier genClassifier = (GenClassifier)j.next();
2074        if (genClassifier.getEcoreClassifier() == eClassifier)
2075        {
2076          if (eClassifier instanceof EClass)
2077          {
2078            ((GenClass)genClassifier).initialize((EClass)eClassifier);
2079          }
2080          else if (eClassifier instanceof EEnum)
2081          {
2082            ((GenEnum)genClassifier).initialize((EEnum)eClassifier);
2083          }
2084          else if (eClassifier instanceof EDataType)
2085          {
2086            ((GenDataType)genClassifier).initialize((EDataType)eClassifier);
2087          }
2088
2089          continue CLASSIFIER_LOOP;
2090        }
2091      }
2092
2093      if (eClassifier instanceof EClass)
2094      {
2095        EClass eClass = (EClass)eClassifier;
2096        GenClass genClass = getGenModel().createGenClass();
2097        getGenClasses().add(genClass);
2098        genClass.initialize(eClass);
2099
2100      }
2101      else if (eClassifier instanceof EEnum)
2102      {
2103        EEnum eEnum = (EEnum)eClassifier;
2104        GenEnum genEnum = getGenModel().createGenEnum();
2105        getGenEnums().add(genEnum);
2106        genEnum.initialize(eEnum);
2107      }
2108      else if (eClassifier instanceof EDataType)
2109      {
2110        EDataType eDataType = (EDataType)eClassifier;
2111        GenDataType genDataType = getGenModel().createGenDataType();
2112        getGenDataTypes().add(genDataType);
2113        genDataType.initialize(eDataType);
2114      }
2115    }
2116
2117    PACKAGE_LOOP:
2118    for (Iterator JavaDoc iter = ePackage.getESubpackages().iterator(); iter.hasNext(); )
2119    {
2120      EPackage nestedEPackage = (EPackage)iter.next();
2121
2122      for (Iterator JavaDoc j = getNestedGenPackages().iterator(); j.hasNext(); )
2123      {
2124        GenPackage nestedGenPackage = (GenPackage)j.next();
2125        if (nestedGenPackage.getEcorePackage() == nestedEPackage)
2126        {
2127          nestedGenPackage.initialize(nestedEPackage);
2128          continue PACKAGE_LOOP;
2129        }
2130      }
2131
2132      GenPackage genPackage = getGenModel().createGenPackage();
2133      getNestedGenPackages().add(genPackage);
2134      genPackage.initialize(nestedEPackage);
2135    }
2136
2137    if (isDifferentPackage)
2138    {
2139      setLoadInitialization(isBigModel());
2140    }
2141  }
2142
2143  protected boolean hasModelContribution()
2144  {
2145    return hasClassifiers() || !getNestedGenPackages().isEmpty();
2146  }
2147
2148  public void generate(IProgressMonitor progressMonitor)
2149  {
2150    try
2151    {
2152      if (!canGenerate()) return;
2153
2154      progressMonitor.beginTask("", 2 * getGenClasses().size() + 2 * getGenEnums().size() + 8 + getNestedGenPackages().size());
2155      progressMonitor.subTask
2156        (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingPackage_message", new Object JavaDoc [] { getPackageInterfaceName() }));
2157
2158      // Create helpers to cache and supply information for unique naming
2159
switchHelper = new SwitchHelper();
2160      validatorHelper = new ValidatorHelper();
2161      dependencyHelper = new DependencyHelper();
2162
2163      for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
2164      {
2165        GenClass genClass = (GenClass)iter.next();
2166        progressMonitor.subTask
2167          (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingModelClass_message", new Object JavaDoc [] { genClass.getFormattedName() }));
2168        genClass.generate(new SubProgressMonitor(progressMonitor, 2));
2169      }
2170
2171      for (Iterator JavaDoc iter = getGenEnums().iterator(); iter.hasNext(); )
2172      {
2173        GenEnum genEnum = (GenEnum)iter.next();
2174        progressMonitor.subTask
2175          (CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingModelEnum_message", new Object JavaDoc [] { genEnum.getFormattedName() }));
2176        genEnum.generate(new SubProgressMonitor(progressMonitor, 2));
2177      }
2178
2179      if (hasClassifiers())
2180      {
2181        if (getGenModel().isGenerateSchema())
2182        {
2183          generateSchema(new SubProgressMonitor(progressMonitor, 1));
2184        }
2185
2186        if (isLoadingInitialization())
2187        {
2188          generatePackageSerialization(new SubProgressMonitor(progressMonitor, 1));
2189        }
2190
2191        progressMonitor.subTask
2192          (CodeGenEcorePlugin.INSTANCE.getString
2193             ("_UI_GeneratingJavaInterface_message", new Object JavaDoc [] { getInterfacePackageName() + "." + getPackageInterfaceName() }));
2194        generate
2195          (new SubProgressMonitor(progressMonitor, 1),
2196           Generator.EMF_MODEL_PROJECT_STYLE,
2197           getGenModel().getEffectiveModelPluginVariables(),
2198           getGenModel().getModelDirectory(),
2199           getInterfacePackageName(),
2200           getPackageInterfaceName(),
2201           getGenModel().getPackageInterfaceEmitter());
2202  
2203        progressMonitor.subTask
2204          (CodeGenEcorePlugin.INSTANCE.getString
2205             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getClassPackageName() + "." + getPackageClassName() }));
2206        generate
2207          (new SubProgressMonitor(progressMonitor, 1),
2208           Generator.EMF_MODEL_PROJECT_STYLE,
2209           getGenModel().getEffectiveModelPluginVariables(),
2210           getGenModel().getModelDirectory(),
2211           getClassPackageName(),
2212           getPackageClassName(),
2213           getGenModel().getPackageClassEmitter());
2214  
2215        progressMonitor.subTask
2216          (CodeGenEcorePlugin.INSTANCE.getString
2217            ("_UI_GeneratingJavaInterface_message", new Object JavaDoc [] { getInterfacePackageName() + "." + getFactoryInterfaceName() }));
2218        generate
2219          (new SubProgressMonitor(progressMonitor, 1),
2220           Generator.EMF_MODEL_PROJECT_STYLE,
2221           getGenModel().getEffectiveModelPluginVariables(),
2222           getGenModel().getModelDirectory(),
2223           getInterfacePackageName(),
2224           getFactoryInterfaceName(),
2225           getGenModel().getFactoryInterfaceEmitter());
2226  
2227        progressMonitor.subTask
2228          (CodeGenEcorePlugin.INSTANCE.getString
2229             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getClassPackageName() + "." + getFactoryClassName() }));
2230        generate
2231          (new SubProgressMonitor(progressMonitor, 1),
2232           Generator.EMF_MODEL_PROJECT_STYLE,
2233           getGenModel().getEffectiveModelPluginVariables(),
2234           getGenModel().getModelDirectory(),
2235           getClassPackageName(),
2236           getFactoryClassName(),
2237           getGenModel().getFactoryClassEmitter());
2238
2239        if (hasConstraints())
2240        {
2241          progressMonitor.subTask
2242            (CodeGenEcorePlugin.INSTANCE.getString
2243               ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getUtilitiesPackageName() + "." + getValidatorClassName() }));
2244          generate
2245            (new SubProgressMonitor(progressMonitor, 1),
2246             Generator.EMF_MODEL_PROJECT_STYLE,
2247             getGenModel().getEffectiveModelPluginVariables(),
2248             getGenModel().getModelDirectory(),
2249             getUtilitiesPackageName(),
2250             getValidatorClassName(),
2251             getGenModel().getValidatorClassEmitter());
2252        }
2253
2254        if (isAdapterFactory())
2255        {
2256          progressMonitor.subTask
2257            (CodeGenEcorePlugin.INSTANCE.getString
2258               ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getUtilitiesPackageName() + "." + getSwitchClassName() }));
2259          generate
2260            (new SubProgressMonitor(progressMonitor, 1),
2261             Generator.EMF_MODEL_PROJECT_STYLE,
2262             getGenModel().getEffectiveModelPluginVariables(),
2263             getGenModel().getModelDirectory(),
2264             getUtilitiesPackageName(),
2265             getSwitchClassName(),
2266             getGenModel().getSwitchClassEmitter());
2267  
2268          progressMonitor.subTask
2269            (CodeGenEcorePlugin.INSTANCE.getString
2270               ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getUtilitiesPackageName() + "." + getAdapterFactoryClassName() }));
2271          generate
2272            (new SubProgressMonitor(progressMonitor, 1),
2273             Generator.EMF_MODEL_PROJECT_STYLE,
2274             getGenModel().getEffectiveModelPluginVariables(),
2275             getGenModel().getModelDirectory(),
2276             getUtilitiesPackageName(),
2277             getAdapterFactoryClassName(),
2278             getGenModel().getAdapterFactoryClassEmitter());
2279        }
2280      }
2281
2282      if (getResource() != GenResourceKind.NONE_LITERAL)
2283      {
2284        progressMonitor.subTask
2285          (CodeGenEcorePlugin.INSTANCE.getString
2286             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getQualifiedResourceFactoryClassName() }));
2287        generate
2288          (new SubProgressMonitor(progressMonitor, 1),
2289           Generator.EMF_MODEL_PROJECT_STYLE,
2290           getGenModel().getEffectiveModelPluginVariables(),
2291           getGenModel().getModelDirectory(),
2292           getUtilitiesPackageName(),
2293           getResourceFactoryClassName(),
2294           getGenModel().getResourceFactoryClassEmitter());
2295  
2296        progressMonitor.subTask
2297          (CodeGenEcorePlugin.INSTANCE.getString
2298             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getQualifiedResourceFactoryClassName() }));
2299        generate
2300          (new SubProgressMonitor(progressMonitor, 1),
2301           Generator.EMF_MODEL_PROJECT_STYLE,
2302           getGenModel().getEffectiveModelPluginVariables(),
2303           getGenModel().getModelDirectory(),
2304           getUtilitiesPackageName(),
2305           getResourceClassName(),
2306           getGenModel().getResourceClassEmitter());
2307      }
2308
2309      for (Iterator JavaDoc nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); )
2310      {
2311        GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next();
2312        nestedGenPackage.generate(new SubProgressMonitor(progressMonitor, 1));
2313      }
2314    }
2315    finally
2316    {
2317      // Clear the transient helpers
2318
switchHelper = null;
2319      validatorHelper = null;
2320      dependencyHelper = null;
2321
2322      progressMonitor.done();
2323    }
2324  }
2325  
2326  /**
2327   * @deprecated Use {@link GenBase#generateSchema(IProgressMonitor)} instead. This
2328   * method will be removed soon.
2329   */

2330  public void generateSchema()
2331  {
2332    generateSchema(new NullProgressMonitor());
2333  }
2334  
2335  public boolean canGenerateSchema()
2336  {
2337    return canGenerate();
2338  }
2339  
2340  public void generateSchema(IProgressMonitor progressMonitor)
2341  {
2342    if (!canGenerateSchema()) return;
2343      
2344    if (hasClassifiers())
2345    {
2346      switch (getResource().getValue())
2347      {
2348        case GenResourceKind.XML:
2349        {
2350          generateXSD("XML");
2351          break;
2352        }
2353        case GenResourceKind.NONE:
2354        case GenResourceKind.XMI:
2355        {
2356          generateXSD("XMI");
2357          break;
2358        }
2359      }
2360    }
2361    
2362    for (Iterator JavaDoc i = getNestedGenPackages().iterator(); i.hasNext();)
2363    {
2364      ((GenPackage)i.next()).generateSchema(progressMonitor);
2365    }
2366  }
2367
2368  protected void generateXSD(String JavaDoc type)
2369  {
2370    Bundle xsdPlugin = Platform.getBundle("org.eclipse.xsd");
2371    if (xsdPlugin != null)
2372    {
2373      try
2374      {
2375        Class JavaDoc theGeneratorClass =
2376          xsdPlugin.loadClass
2377            ("org.eclipse.xsd.ecore.Ecore" + type + "SchemaBuilder");
2378
2379        try
2380        {
2381          Object JavaDoc generator = theGeneratorClass.newInstance();
2382
2383          // Set the mapper to build an XSD2EcoreMappingRoot, if available.
2384
//
2385
Bundle xsd2ecorePlugin = Platform.getBundle("org.eclipse.emf.mapping.xsd2ecore");
2386          if (xsd2ecorePlugin != null)
2387          {
2388            try
2389            {
2390              Class JavaDoc theMapperInterface =
2391                xsdPlugin.loadClass
2392                  ("org.eclipse.xsd.ecore.MapBuilder$Mapper");
2393
2394              Class JavaDoc theMapperClass =
2395                xsd2ecorePlugin.loadClass
2396                  ("org.eclipse.emf.mapping.xsd2ecore.XSD2EcoreMapper");
2397  
2398              Object JavaDoc mapper = theMapperClass.newInstance();
2399  
2400              theGeneratorClass.getMethod
2401                ("setMapper",
2402                 new Class JavaDoc [] { theMapperInterface }).invoke(generator, new Object JavaDoc [] { mapper });
2403            }
2404            catch (InstantiationException JavaDoc exception)
2405            {
2406              CodeGenEcorePlugin.INSTANCE.log(exception);
2407            }
2408            catch (NoSuchMethodException JavaDoc exception)
2409            {
2410              CodeGenEcorePlugin.INSTANCE.log(exception);
2411            }
2412            catch (IllegalAccessException JavaDoc exception)
2413            {
2414              CodeGenEcorePlugin.INSTANCE.log(exception);
2415            }
2416            catch (InvocationTargetException JavaDoc exception)
2417            {
2418              CodeGenEcorePlugin.INSTANCE.log(exception);
2419            }
2420            catch (ClassNotFoundException JavaDoc exception)
2421            {
2422              // Ignore this soft dependency when it's not satisfied.
2423
}
2424          }
2425
2426          Collection JavaDoc result =
2427            (Collection JavaDoc)theGeneratorClass.getMethod
2428              ("generate",
2429               new Class JavaDoc [] { EPackage.class }).invoke(generator, new Object JavaDoc [] { getEcorePackage() });
2430
2431          Iterator JavaDoc i = result.iterator();
2432          Object JavaDoc xsdSchema = i.next();
2433
2434          ResourceSet resourceSet = new ResourceSetImpl();
2435          resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
2436          URI uri = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment(getPrefix() + type + ".xsd");
2437          Resource xsdSchemaResource = resourceSet.createResource(uri);
2438          xsdSchemaResource.getContents().add(xsdSchema);
2439          try
2440          {
2441            xsdSchemaResource.save(Collections.EMPTY_MAP);
2442          }
2443          catch (IOException JavaDoc exception)
2444          {
2445            CodeGenEcorePlugin.INSTANCE.log(exception);
2446          }
2447
2448          if (i.hasNext())
2449          {
2450            if (!"XML".equals(type))
2451            {
2452              Object JavaDoc otherXSDSchema = i.next();
2453              URI otherURI = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment("XMI.xsd");
2454              Resource otherXSDSchemaResource = resourceSet.createResource(otherURI);
2455              otherXSDSchemaResource.getContents().add(otherXSDSchema);
2456              try
2457              {
2458                otherXSDSchemaResource.save(Collections.EMPTY_MAP);
2459              }
2460              catch (IOException JavaDoc exception)
2461              {
2462                CodeGenEcorePlugin.INSTANCE.log(exception);
2463              }
2464            }
2465            if (i.hasNext())
2466            {
2467              Object JavaDoc mappingRoot = i.next();
2468              URI mappingURI = getEcorePackage().eResource().getURI().trimSegments(1).appendSegment(getPrefix() + type + ".xsd2ecore");
2469              Resource mappingResource = resourceSet.createResource(mappingURI);
2470              mappingResource.getContents().add(mappingRoot);
2471              try
2472              {
2473                mappingResource.save(Collections.EMPTY_MAP);
2474              }
2475              catch (IOException JavaDoc exception)
2476              {
2477                CodeGenEcorePlugin.INSTANCE.log(exception);
2478              }
2479            }
2480          }
2481        }
2482        catch (InstantiationException JavaDoc exception)
2483        {
2484          CodeGenEcorePlugin.INSTANCE.log(exception);
2485        }
2486        catch (NoSuchMethodException JavaDoc exception)
2487        {
2488          CodeGenEcorePlugin.INSTANCE.log(exception);
2489        }
2490        catch (IllegalAccessException JavaDoc exception)
2491        {
2492          CodeGenEcorePlugin.INSTANCE.log(exception);
2493        }
2494        catch (InvocationTargetException JavaDoc exception)
2495        {
2496          CodeGenEcorePlugin.INSTANCE.log(exception);
2497        }
2498      }
2499      catch (ClassNotFoundException JavaDoc exception)
2500      {
2501        // Ignore this soft dependency when it's not satisfied.
2502
}
2503    }
2504  }
2505
2506  public void generatePackageSerialization(IProgressMonitor progressMonitor)
2507  {
2508    try
2509    {
2510      if (!canGenerate() || !isLoadingInitialization()) return;
2511
2512      String JavaDoc outputFile = getGenModel().getModelDirectory() + "/" + getClassPackageName().replace('.', '/') + "/" + getSerializedPackageFilename();
2513
2514      progressMonitor.beginTask("", 2);
2515      progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("_UI_GeneratingPackageSerialization_message", new Object JavaDoc [] { outputFile }));
2516
2517      IPath outputFilePath = new Path(outputFile);
2518      findOrCreateContainer
2519        (new SubProgressMonitor(progressMonitor, 1),
2520         Generator.EMF_MODEL_PROJECT_STYLE,
2521         getGenModel().getEffectiveModelPluginVariables(),
2522         outputFilePath.removeLastSegments(1),
2523         false);
2524
2525      URI outputURI = URI.createPlatformResourceURI(outputFilePath.toString());
2526      Resource outputResource = getEcorePackage().eResource();
2527      ResourceSet set = outputResource.getResourceSet();
2528
2529      Map JavaDoc oldURIs = new HashMap JavaDoc();
2530
2531      // Set URIs of EPackage-containing resources: output resource to desired target URI, and others to package
2532
// namespace URIs (so cross-references will be resolved via package registry when deserialized).
2533
//
2534
for (Iterator JavaDoc i = set.getResources().iterator(); i.hasNext(); )
2535      {
2536        Resource resource = (Resource)i.next();
2537        List JavaDoc contents = resource.getContents();
2538        
2539        if (!contents.isEmpty() && contents.get(0) instanceof EPackage)
2540        {
2541          EPackage ePackage = (EPackage)contents.get(0);
2542          oldURIs.put(resource, resource.getURI());
2543          resource.setURI(resource == outputResource ? outputURI : URI.createURI(ePackage.getNsURI()));
2544        }
2545      }
2546
2547      try
2548      {
2549        outputResource.save(null);
2550      }
2551      catch (IOException JavaDoc exception)
2552      {
2553        CodeGenEcorePlugin.INSTANCE.log(exception);
2554      }
2555
2556      // Restore original resource URI values.
2557
//
2558
for (Iterator JavaDoc i = set.getResources().iterator(); i.hasNext(); )
2559      {
2560        Resource resource = (Resource)i.next();
2561        List JavaDoc contents = resource.getContents();
2562        
2563        if (!contents.isEmpty() && contents.get(0) instanceof EPackage)
2564        {
2565          resource.setURI((URI)oldURIs.get(resource));
2566        }
2567      }
2568
2569      progressMonitor.worked(1);
2570    }
2571    finally
2572    {
2573      progressMonitor.done();
2574    }
2575  }
2576
2577  //
2578
// EMFEdit generation
2579
//
2580

2581  public String JavaDoc getProviderPackageName()
2582  {
2583    return getQualifiedPackageName(getProviderPackageSuffix());
2584  }
2585
2586  public String JavaDoc getPresentationPackageName()
2587  {
2588    return getQualifiedPackageName(getPresentationPackageSuffix());
2589  }
2590  
2591  protected String JavaDoc getQualifiedPackageName(String JavaDoc suffix)
2592  {
2593    String JavaDoc name = getQualifiedPackageName();
2594    return isBlank(suffix) ? name : name + "." + suffix;
2595  }
2596  
2597  public String JavaDoc getQualifiedPackageName()
2598  {
2599    String JavaDoc name = safeName(getPackageName());
2600    if (!isBlank(getBasePackage()))
2601    {
2602      name = getBasePackage() + "." + name;
2603    }
2604    return name;
2605  }
2606
2607// public String getExtendedItemProviderClassName()
2608
// {
2609
// return getPrefixedName("ItemProviderAdapter");
2610
// }
2611

2612  public String JavaDoc getItemProviderAdapterFactoryClassName()
2613  {
2614    return getPrefixedName("ItemProviderAdapterFactory");
2615  }
2616
2617  public String JavaDoc getQualifiedItemProviderAdapterFactoryClassName()
2618  {
2619    return getProviderPackageName() + "." + getItemProviderAdapterFactoryClassName();
2620  }
2621
2622  public String JavaDoc getImportedItemProviderAdapterFactoryClassName()
2623  {
2624    return getGenModel().getImportedName(getQualifiedItemProviderAdapterFactoryClassName());
2625  }
2626
2627  public String JavaDoc getEditorClassName()
2628  {
2629    return getPrefixedName("Editor");
2630  }
2631
2632  public String JavaDoc getQualifiedEditorClassName()
2633  {
2634    return getPresentationPackageName() + "." + getEditorClassName();
2635  }
2636
2637  public String JavaDoc getImportedEditorClassName()
2638  {
2639    return getGenModel().getImportedName(getQualifiedEditorClassName());
2640  }
2641
2642  public String JavaDoc getModelWizardClassName()
2643  {
2644    return getPrefixedName("ModelWizard");
2645  }
2646
2647  public String JavaDoc getQualifiedModelWizardClassName()
2648  {
2649    return getPresentationPackageName() + "." + getModelWizardClassName();
2650  }
2651
2652  public String JavaDoc getImportedModelWizardClassName()
2653  {
2654    return getGenModel().getImportedName(getQualifiedModelWizardClassName());
2655  }
2656
2657  public String JavaDoc getActionBarContributorClassName()
2658  {
2659    return getPrefixedName("ActionBarContributor");
2660  }
2661
2662  public String JavaDoc getQualifiedActionBarContributorClassName()
2663  {
2664    return getPresentationPackageName() + "." + getActionBarContributorClassName();
2665  }
2666
2667  public String JavaDoc getImportedActionBarContributorClassName()
2668  {
2669    return getGenModel().getImportedName(getQualifiedActionBarContributorClassName());
2670  }
2671
2672  public String JavaDoc getAdapterFactoryDelegateName(GenPackage genDelegate)
2673  {
2674    String JavaDoc result = genDelegate.getAdapterFactoryClassName();
2675    if (!result.equals(genDelegate.getImportedAdapterFactoryClassName()))
2676    {
2677      int count = getAdapterDelegatePackages().indexOf(genDelegate);
2678      result += "_" + count;
2679    }
2680    return result;
2681  }
2682
2683  public String JavaDoc getUncapAdapterFactoryDelegateName(GenPackage genDelegate)
2684  {
2685    return uncapPrefixedName(getAdapterFactoryDelegateName(genDelegate), true);
2686  }
2687
2688  //
2689
//TBD rethink where exactly some of the following methods belong (GenModel or GenPackage)
2690
//
2691

2692  public String JavaDoc getEditPluginClassName()
2693  {
2694    // return getPrefixedName("EditPlugin");
2695
return getGenModel().getEditPluginClassName();
2696  }
2697
2698  public String JavaDoc getQualifiedEditPluginClassName()
2699  {
2700    // return getProviderPackageName() + "." + getEditPluginClassName();
2701
return getGenModel().getQualifiedEditPluginClassName();
2702  }
2703
2704  public String JavaDoc getImportedEditPluginClassName()
2705  {
2706    return getGenModel().getImportedName(getQualifiedEditPluginClassName());
2707  }
2708
2709  public String JavaDoc getEditorPluginClassName()
2710  {
2711    // return getPrefixedName("EditorPlugin");
2712
return getGenModel().getEditorPluginClassName();
2713  }
2714
2715  public String JavaDoc getQualifiedEditorPluginClassName()
2716  {
2717    return getGenModel().getQualifiedEditorPluginClassName();
2718    // return getPresentationPackageName() + "." + getEditorPluginClassName();
2719
}
2720
2721  public String JavaDoc getImportedEditorPluginClassName()
2722  {
2723    return getGenModel().getImportedName(getQualifiedEditorPluginClassName());
2724  }
2725
2726  public String JavaDoc getCapPackageID()
2727  {
2728    return capName(getPackageID());
2729  }
2730
2731  public List JavaDoc/*GenFeature*/ getAllGenFeatures()
2732  {
2733    List JavaDoc result = new ArrayList JavaDoc();
2734
2735    // Any features that delegate to features in this package.
2736
//
2737
List JavaDoc delegated = new ArrayList JavaDoc();
2738
2739    for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
2740    {
2741      GenClass genClass = (GenClass)iter.next();
2742      for (Iterator JavaDoc fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); )
2743      {
2744        GenFeature genFeature = (GenFeature)fIter.next();
2745        result.add(genFeature);
2746        delegated.addAll(genFeature.getDelegatedFeatures());
2747      }
2748    }
2749
2750    // If there are delegated features, add only those that aren't already in this package to the end of the list.
2751
//
2752
if (!delegated.isEmpty())
2753    {
2754      addNonDuplicates(result, delegated, null);
2755    }
2756    return result;
2757  }
2758
2759  public List JavaDoc/*GenFeature*/ getFilteredAllGenFeatures()
2760  {
2761    ArrayList JavaDoc result = new ArrayList JavaDoc();
2762
2763    // We need to screen out duplicates in the unlikely event that we have two
2764
// features with the same class-qualifed name. We'll only generate one property
2765
// string in that case and let the user add the second one mannually, if necessary.
2766
//
2767
HashSet JavaDoc noDupHash = new HashSet JavaDoc();
2768    for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
2769    {
2770      GenClass genClass = (GenClass)iter.next();
2771      for (Iterator JavaDoc fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); )
2772      {
2773        GenFeature genFeature = (GenFeature)fIter.next();
2774        if (noDupHash.add(genFeature.getGenClass().getName() + genFeature.getName()))
2775        {
2776          result.add(genFeature);
2777        }
2778      }
2779    }
2780
2781    return result;
2782  }
2783
2784  public List JavaDoc/*GenPackage*/ getAdapterDelegatePackages()
2785  {
2786    List JavaDoc result = new ArrayList JavaDoc();
2787
2788    //TBD return (user selected subset?) of referenced packages that contain super classes of classes in this package.
2789

2790    return result;
2791  }
2792
2793  public List JavaDoc/*GenClass*/ getAdapterDelegateSuperClasses()
2794  {
2795    List JavaDoc result = new ArrayList JavaDoc();
2796
2797    //TBD return superclasses of classes in this package that come from a delegate package.
2798

2799    return result;
2800  }
2801
2802  public boolean hasStatefulProvider()
2803  {
2804    for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
2805    {
2806      GenClass genClass = (GenClass)iter.next();
2807      if (!genClass.isAbstract() && genClass.getProvider() == GenProviderKind.STATEFUL_LITERAL)
2808      {
2809        return true;
2810      }
2811    }
2812    return false;
2813  }
2814
2815  public void generateEdit(IProgressMonitor progressMonitor)
2816  {
2817    try
2818    {
2819      if (!canGenerateEdit()) return;
2820
2821      progressMonitor.beginTask("", getGenClasses().size() + getNestedGenPackages().size() + 2); //TBD
2822
progressMonitor.subTask
2823        (CodeGenEcorePlugin.INSTANCE.getString
2824           ("_UI_GeneratingItemProvidersForPackage_message", new Object JavaDoc [] { getPackageInterfaceName() }));
2825
2826      if (hasClassifiers())
2827      {
2828        for (Iterator JavaDoc iter = getGenClasses().iterator(); iter.hasNext(); )
2829        {
2830          GenClass genClass = (GenClass)iter.next();
2831          if (genClass.getProvider() == GenProviderKind.NONE_LITERAL) continue;
2832          progressMonitor.subTask
2833            (CodeGenEcorePlugin.INSTANCE.getString
2834               ("_UI_GeneratingItemProviderFor_message", new Object JavaDoc [] { genClass.getFormattedName() }));
2835          genClass.generateEdit(new SubProgressMonitor(progressMonitor, 1));
2836        }
2837  
2838        progressMonitor.subTask
2839          (CodeGenEcorePlugin.INSTANCE.getString
2840             ("_UI_GeneratingJavaClass_message",
2841              new Object JavaDoc [] { getProviderPackageName() + "." + getItemProviderAdapterFactoryClassName() }));
2842        generate
2843          (new SubProgressMonitor(progressMonitor, 1),
2844           Generator.EMF_EDIT_PROJECT_STYLE,
2845           getGenModel().getEffectiveModelPluginVariables(),
2846           getGenModel().getEditDirectory(),
2847           getProviderPackageName(),
2848           getItemProviderAdapterFactoryClassName(),
2849           getGenModel().getItemProviderAdapterFactoryEmitter());
2850      }
2851
2852      for (Iterator JavaDoc nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); )
2853      {
2854        GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next();
2855        nestedGenPackage.generateEdit(new SubProgressMonitor(progressMonitor, 1));
2856      }
2857    }
2858    finally
2859    {
2860      progressMonitor.done();
2861    }
2862  }
2863
2864  public void generateEditor(IProgressMonitor progressMonitor)
2865  {
2866    try
2867    {
2868      if (!canGenerateEditor()) return;
2869
2870      progressMonitor.beginTask("", 7); //TBD
2871
progressMonitor.subTask
2872        (CodeGenEcorePlugin.INSTANCE.getString
2873           ("_UI_GeneratingEditorForPackage_message", new Object JavaDoc [] { getPackageInterfaceName() }));
2874
2875      if (hasClassifiers() && hasConcreteClasses())
2876      {
2877        progressMonitor.subTask
2878          (CodeGenEcorePlugin.INSTANCE.getString
2879             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getQualifiedEditorClassName() }));
2880        generate
2881          (new SubProgressMonitor(progressMonitor, 1),
2882           Generator.EMF_EDITOR_PROJECT_STYLE,
2883           getGenModel().getEffectiveModelPluginVariables(),
2884           getGenModel().getEditorDirectory(),
2885           getPresentationPackageName(),
2886           getEditorClassName(),
2887           getGenModel().getEditorEmitter());
2888  
2889        progressMonitor.subTask
2890        (CodeGenEcorePlugin.INSTANCE.getString
2891           ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getQualifiedModelWizardClassName() }));
2892      generate
2893        (new SubProgressMonitor(progressMonitor, 1),
2894         Generator.EMF_EDITOR_PROJECT_STYLE,
2895         getGenModel().getEffectiveModelPluginVariables(),
2896         getGenModel().getEditorDirectory(),
2897         getPresentationPackageName(),
2898         getModelWizardClassName(),
2899         getGenModel().getModelWizardEmitter());
2900
2901        progressMonitor.subTask
2902          (CodeGenEcorePlugin.INSTANCE.getString
2903             ("_UI_GeneratingJavaClass_message", new Object JavaDoc [] { getQualifiedActionBarContributorClassName() }));
2904        generate
2905          (new SubProgressMonitor(progressMonitor, 1),
2906           Generator.EMF_EDITOR_PROJECT_STYLE,
2907           getGenModel().getEffectiveModelPluginVariables(),
2908           getGenModel().getEditorDirectory(),
2909           getPresentationPackageName(),
2910           getActionBarContributorClassName(),
2911           getGenModel().getActionBarContributorEmitter());
2912  
2913        progressMonitor.subTask
2914          (CodeGenEcorePlugin.INSTANCE.getString
2915             ("_UI_GeneratingModelIcon_message", new Object JavaDoc [] { getModelIconFileName() }));
2916        generate
2917          (new SubProgressMonitor(progressMonitor, 1),
2918           Generator.EMF_EDIT_PROJECT_STYLE,
2919           getGenModel().getEffectiveModelPluginVariables(),
2920           getModelIconFileName(),
2921           ((GenModelImpl)getGenModel()).getModelGIFEmitter(),
2922           getPrefix());
2923
2924        progressMonitor.subTask
2925          (CodeGenEcorePlugin.INSTANCE.getString
2926             ("_UI_GeneratingModelWizardIcon_message", new Object JavaDoc [] { getModelWizardIconFileName() }));
2927        generate
2928          (new SubProgressMonitor(progressMonitor, 1),
2929           Generator.EMF_EDIT_PROJECT_STYLE,
2930           getGenModel().getEffectiveModelPluginVariables(),
2931           getModelWizardIconFileName(),
2932           ((GenModelImpl)getGenModel()).getModelWizardGIFEmitter(),
2933           getPrefix());
2934      }
2935
2936      for (Iterator JavaDoc nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext(); )
2937      {
2938        GenPackage nestedGenPackage = (GenPackage)nestedGenPackages.next();
2939        nestedGenPackage.generateEditor(new SubProgressMonitor(progressMonitor, 1));
2940      }
2941    }
2942    finally
2943    {
2944      progressMonitor.done();
2945    }
2946  }
2947
2948  public boolean hasTests()
2949  {
2950    for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext();)
2951    {
2952      if (((GenClass)i.next()).hasTests())
2953      {
2954        return true;
2955      }
2956    }
2957
2958    return false;
2959  }
2960
2961  public boolean canGenerateTests()
2962  {
2963    return getGenModel().canGenerateTests() && hasClassifiers(true);
2964  }
2965
2966  public void generateTests(IProgressMonitor progressMonitor)
2967  {
2968    try
2969    {
2970      if (!canGenerateTests())
2971        return;
2972
2973      progressMonitor.beginTask("", getGenClasses().size() + getNestedGenPackages().size());
2974
2975      if (hasClassifiers())
2976      {
2977        progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString(
2978          "_UI_GeneratingJavaClass_message",
2979          new Object JavaDoc []{ getQualifiedTestSuiteClassName() }));
2980          
2981        generate(
2982          new SubProgressMonitor(progressMonitor, 1),
2983          Generator.EMF_TESTS_PROJECT_STYLE,
2984          getGenModel().getEffectiveModelPluginVariables(),
2985          getGenModel().getTestsDirectory(),
2986          getTestsPackageName(),
2987          getTestSuiteClassName(),
2988          getGenModel().getPackageTestSuiteEmitter());
2989  
2990        if (isGenerateExampleClass())
2991        {
2992          generate(
2993            new SubProgressMonitor(progressMonitor, 1),
2994            Generator.EMF_TESTS_PROJECT_STYLE,
2995            getGenModel().getEffectiveModelPluginVariables(),
2996            getGenModel().getTestsDirectory(),
2997            getTestsPackageName(),
2998            getExampleClassName(),
2999            getGenModel().getPackageExampleEmitter());
3000        }
3001          
3002        for (Iterator JavaDoc genClasses = getGenClasses().iterator(); genClasses.hasNext();)
3003        {
3004          GenClass genClass = (GenClass)genClasses.next();
3005          progressMonitor.subTask(CodeGenEcorePlugin.INSTANCE.getString(
3006            "_UI_Generating_message",
3007            new Object JavaDoc []{ genClass.getFormattedName() }));
3008          genClass.generateTests(new SubProgressMonitor(progressMonitor, 1));
3009        }
3010      }
3011
3012      for (Iterator JavaDoc nestedGenPackages = getNestedGenPackages().iterator(); nestedGenPackages.hasNext();)
3013      {
3014        ((GenPackage)nestedGenPackages.next()).generateTests(new SubProgressMonitor(progressMonitor, 1));
3015      }
3016    }
3017    finally
3018    {
3019      progressMonitor.done();
3020    }
3021  }
3022
3023  public String JavaDoc getModelIconFileName()
3024  {
3025    return getGenModel().getEditorIconsDirectory() + "/full/obj16/" + getPrefix() + "ModelFile.gif";
3026  }
3027
3028  public String JavaDoc getModelWizardIconFileName()
3029  {
3030    return getGenModel().getEditorIconsDirectory() + "/full/wizban/New" + getPrefix() + ".gif";
3031  }
3032
3033  public boolean hasClassifiers()
3034  {
3035    return getGenClasses().size() + getGenEnums().size() + getGenDataTypes().size() != 0;
3036  }
3037  
3038  public boolean hasClassifiers(boolean traverseNestedPackages)
3039  {
3040    if (hasClassifiers())
3041    {
3042      return true;
3043    }
3044    else if (traverseNestedPackages)
3045    {
3046      for (Iterator JavaDoc i = getNestedGenPackages().iterator(); i.hasNext();)
3047      {
3048        GenPackage genPackage = (GenPackage)i.next();
3049        if(genPackage.hasClassifiers(true))
3050        {
3051          return true;
3052        }
3053      }
3054    }
3055    return false;
3056  }
3057
3058  public String JavaDoc getModelInfo()
3059  {
3060    StringBuffer JavaDoc result = new StringBuffer JavaDoc();
3061    appendModelSetting(result, "kind", "package");
3062    return result.toString().trim();
3063  }
3064
3065  public boolean reconcile(GenPackage oldGenPackageVersion)
3066  {
3067    if (getEcorePackage().getNsURI() == null ?
3068          getEcorePackage().getName().equals(oldGenPackageVersion.getEcorePackage().getName()) :
3069          getEcorePackage().getNsURI().equals(oldGenPackageVersion.getEcorePackage().getNsURI()))
3070    {
3071      for (Iterator JavaDoc i = getGenClassifiers().iterator(); i.hasNext(); )
3072      {
3073        GenClassifier genClassifier = (GenClassifier)i.next();
3074        for (Iterator JavaDoc j = oldGenPackageVersion.getGenClassifiers().iterator(); j.hasNext(); )
3075        {
3076          GenClassifier oldGenClassifierVersion = (GenClassifier)j.next();
3077          if (genClassifier instanceof GenEnum)
3078          {
3079            if (oldGenClassifierVersion instanceof GenEnum &&
3080                  ((GenEnum)genClassifier).reconcile((GenEnum)oldGenClassifierVersion))
3081            {
3082              break;
3083            }
3084          }
3085          else if (genClassifier instanceof GenDataType)
3086          {
3087            if (oldGenClassifierVersion instanceof GenDataType &&
3088                  !(oldGenClassifierVersion instanceof GenEnum) &&
3089                  ((GenDataType)genClassifier).reconcile((GenDataType)oldGenClassifierVersion))
3090            {
3091              break;
3092            }
3093          }
3094          else if (genClassifier instanceof GenClass)
3095          {
3096            if (oldGenClassifierVersion instanceof GenClass &&
3097                  ((GenClass)genClassifier).reconcile((GenClass)oldGenClassifierVersion))
3098            {
3099              break;
3100            }
3101          }
3102        }
3103      }
3104
3105      for (Iterator JavaDoc i = getNestedGenPackages().iterator(); i.hasNext(); )
3106      {
3107        GenPackage nestedGenPackage = (GenPackage)i.next();
3108        for (Iterator JavaDoc j = oldGenPackageVersion.getNestedGenPackages().iterator(); j.hasNext(); )
3109        {
3110          GenPackage oldNestedGenPackageVersion = (GenPackage)j.next();
3111          if (nestedGenPackage.reconcile(oldNestedGenPackageVersion))
3112          {
3113            break;
3114          }
3115        }
3116      }
3117
3118      reconcileSettings(oldGenPackageVersion);
3119      return true;
3120    }
3121    else
3122    {
3123      return false;
3124    }
3125  }
3126
3127  protected void reconcileSettings(GenPackage oldGenPackageVersion)
3128  {
3129    setPrefix(oldGenPackageVersion.getPrefix());
3130    setBasePackage(oldGenPackageVersion.getBasePackage());
3131    setResource(oldGenPackageVersion.getResource());
3132    setAdapterFactory(oldGenPackageVersion.isAdapterFactory());
3133    setLoadInitialization(oldGenPackageVersion.isLoadInitialization());
3134    setDisposableProviderFactory(oldGenPackageVersion.isDisposableProviderFactory());
3135    
3136    setInterfacePackageSuffix(oldGenPackageVersion.getInterfacePackageSuffix());
3137    setClassPackageSuffix(oldGenPackageVersion.getClassPackageSuffix());
3138    setUtilityPackageSuffix(oldGenPackageVersion.getUtilityPackageSuffix());
3139    setProviderPackageSuffix(oldGenPackageVersion.getProviderPackageSuffix());
3140    setPresentationPackageSuffix(oldGenPackageVersion.getPresentationPackageSuffix());
3141    setTestsPackageSuffix(oldGenPackageVersion.getTestsPackageSuffix());
3142    setGenerateExampleClass(oldGenPackageVersion.isGenerateExampleClass());
3143  }
3144
3145  public boolean reconcile()
3146  {
3147    EPackage ePackage = getEcorePackage();
3148    if (ePackage == null || ePackage.eIsProxy() || ePackage.eResource() == null)
3149    {
3150      return false;
3151    }
3152    else
3153    {
3154      for (Iterator JavaDoc i = getGenClassifiers().iterator(); i.hasNext(); )
3155      {
3156        GenClassifier genClassifier = (GenClassifier)i.next();
3157        if (!genClassifier.reconcile())
3158        {
3159          i.remove();
3160        }
3161      }
3162
3163      for (Iterator JavaDoc i = getNestedGenPackages().iterator(); i.hasNext(); )
3164      {
3165        GenPackage nestedGenPackage = (GenPackage)i.next();
3166        if (!nestedGenPackage.reconcile())
3167        {
3168          i.remove();
3169        }
3170      }
3171
3172      initialize(ePackage);
3173      return true;
3174    }
3175  }
3176
3177  public List JavaDoc getAnnotationSources()
3178  {
3179    List JavaDoc result = new UniqueEList();
3180    EPackage ePackage = getEcorePackage();
3181    for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); )
3182    {
3183      Object JavaDoc object = i.next();
3184      if (object instanceof EPackage)
3185      {
3186        i.prune();
3187      }
3188      else if (object instanceof EAnnotation)
3189      {
3190        EAnnotation eAnnotation = (EAnnotation)object;
3191        String JavaDoc source = eAnnotation.getSource();
3192
3193        // Ignore GenModel exceptions ones with a body for now.
3194
//
3195
if (source == null || !source.equals(GenModelPackage.eNS_URI) || eAnnotation.getDetails().containsKey("body"))
3196        {
3197          result.add(source);
3198        }
3199      }
3200    }
3201    return result;
3202  }
3203
3204  public String JavaDoc getAnnotationSourceIdentifier(String JavaDoc annotationSource)
3205  {
3206    String JavaDoc result = annotationSource;
3207    if (annotationSource == null)
3208    {
3209      return "Null";
3210    }
3211    else
3212    {
3213      int index = result.lastIndexOf("/");
3214      if (index == result.length() - 1)
3215      {
3216        result = result.substring(0, index);
3217        index = result.lastIndexOf("/");
3218      }
3219      if (index != -1)
3220      {
3221        result = result.substring(index + 1);
3222      }
3223      index = result.indexOf(".");
3224      if (index != -1)
3225      {
3226        result = result.substring(0, index);
3227      }
3228      return capName(result);
3229    }
3230  }
3231
3232  public List JavaDoc getAllAnnotations()
3233  {
3234    List JavaDoc result = new UniqueEList();
3235    EPackage ePackage = getEcorePackage();
3236    for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); )
3237    {
3238      Object JavaDoc object = i.next();
3239      if (object instanceof EPackage)
3240      {
3241        i.prune();
3242      }
3243      else if (object instanceof EAnnotation)
3244      {
3245        result.add(object);
3246        i.prune();
3247      }
3248    }
3249    return result;
3250  }
3251
3252  public String JavaDoc getAnnotatedModelElementAccessor(EAnnotation eAnnotation)
3253  {
3254    EModelElement eModelElement = eAnnotation.getEModelElement();
3255    String JavaDoc result =
3256      (String JavaDoc)
3257        new EcoreSwitch()
3258        {
3259          public Object JavaDoc caseEPackage(EPackage ePackage)
3260          {
3261            return "this";
3262          }
3263
3264          public Object JavaDoc caseEClassifier(EClassifier eClassifier)
3265          {
3266            return findGenClassifier(eClassifier).getClassifierInstanceName();
3267          }
3268
3269          public Object JavaDoc caseEStructuralFeature(EStructuralFeature eStructuralFeature)
3270          {
3271            return "get" + findGenFeature(eStructuralFeature).getFeatureAccessorName() + "()";
3272          }
3273
3274          public Object JavaDoc caseEOperation(EOperation eOperation)
3275          {
3276            EClass eClass = eOperation.getEContainingClass();
3277            return
3278              "(" +
3279                getGenModel().getImportedName("org.eclipse.emf.ecore.EOperation") +
3280                ")" +
3281                caseEClassifier(eClass) +
3282                ".getEOperations().get(" +
3283                eClass.getEOperations().indexOf(eOperation) +
3284                ")";
3285          }
3286          public Object JavaDoc caseEEnumLiteral(EEnumLiteral eEnumLiteral)
3287          {
3288            EEnum eEnum = eEnumLiteral.getEEnum();
3289            return
3290              "(" +
3291                getGenModel().getImportedName("org.eclipse.emf.ecore.EEnumLiteral") +
3292                ")" +
3293                caseEClassifier(eEnum) +
3294                ".getELiterals().get(" +
3295                eEnum.getELiterals().indexOf(eEnumLiteral) +
3296                ")";
3297          }
3298
3299          public Object JavaDoc caseEParameter(EParameter eParameter)
3300          {
3301            EOperation eOperation = eParameter.getEOperation();
3302            return
3303              "(" +
3304                getGenModel().getImportedName("org.eclipse.emf.ecore.EParameter") +
3305                ")(" +
3306                caseEOperation(eOperation) +
3307                ").getEParameters().get(" +
3308                eOperation.getEParameters().indexOf(eParameter) +
3309                ")";
3310          }
3311        }.doSwitch(eModelElement);
3312
3313    return result;
3314  }
3315
3316  public String JavaDoc getResourceClassName()
3317  {
3318    return getPrefix() + "ResourceImpl";
3319  }
3320
3321  public String JavaDoc getQualifiedResourceClassName()
3322  {
3323    return getUtilitiesPackageName() + "." + getResourceClassName();
3324  }
3325
3326  public String JavaDoc getImportedResourceClassName()
3327  {
3328    return getGenModel().getImportedName(getQualifiedResourceClassName());
3329  }
3330
3331  public String JavaDoc getImportedResourceBaseClassName()
3332  {
3333    switch (getResource().getValue())
3334    {
3335      case GenResourceKind.XML:
3336        return getGenModel().getImportedName("org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl");
3337      case GenResourceKind.XMI:
3338        return getGenModel().getImportedName("org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl");
3339      default:
3340        return getGenModel().getImportedName("org.eclipse.emf.ecore.resource.impl.ResourceImpl");
3341    }
3342  }
3343
3344  public String JavaDoc getResourceFactoryClassName()
3345  {
3346    return getPrefix() + "ResourceFactoryImpl";
3347  }
3348
3349  public String JavaDoc getQualifiedResourceFactoryClassName()
3350  {
3351    return getUtilitiesPackageName() + "." + getResourceFactoryClassName();
3352  }
3353
3354  public String JavaDoc getImportedResourceFactoryClassName()
3355  {
3356    return getGenModel().getImportedName(getQualifiedResourceFactoryClassName());
3357  }
3358
3359  public String JavaDoc getImportedResourceFactoryBaseClassName()
3360  {
3361    return getGenModel().getImportedName("org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl");
3362  }
3363
3364  public boolean hasDocumentRoot()
3365  {
3366    if (getResource() != GenResourceKind.XML_LITERAL)
3367    {
3368      return false;
3369    }
3370
3371    return getExtendedMetaData().getDocumentRoot(getEcorePackage()) != null;
3372  }
3373
3374  public boolean hasExtendedMetaData()
3375  {
3376    if (getResource() != GenResourceKind.XML_LITERAL)
3377    {
3378      return false;
3379    }
3380    return hasExtendedMetaData(getEcorePackage());
3381  }
3382
3383  protected static boolean hasExtendedMetaData(EPackage ePackage)
3384  {
3385    for (TreeIterator i = ePackage.eAllContents(); i.hasNext(); )
3386    {
3387      Object JavaDoc object = i.next();
3388      if (object instanceof EPackage)
3389      {
3390        i.prune();
3391      }
3392      else if (object instanceof EAnnotation)
3393      {
3394        EAnnotation eAnnotation = (EAnnotation)object;
3395        String JavaDoc source = eAnnotation.getSource();
3396        if (ExtendedMetaData.ANNOTATION_URI.equals(source))
3397        {
3398          return true;
3399        }
3400      }
3401    }
3402
3403    return false;
3404  }
3405
3406  public boolean hasXMLMap()
3407  {
3408    if (getResource() != GenResourceKind.XML_LITERAL)
3409    {
3410      return false;
3411    }
3412
3413    EAnnotation eAnnotation = getEcorePackage().getEAnnotation(XSD2ECORE_URI);
3414    return eAnnotation != null;
3415  }
3416
3417  public boolean hasTargetNamespace()
3418  {
3419    if (hasExtendedMetaData())
3420    {
3421      return getExtendedMetaData().getNamespace(getEcorePackage()) != null;
3422    }
3423
3424    EAnnotation eAnnotation = getEcorePackage().getEAnnotation(XSD2ECORE_URI);
3425    return eAnnotation == null || eAnnotation.getDetails().get("targetNamespace") != null;
3426  }
3427
3428  public String JavaDoc getSerializedPackageFilename()
3429  {
3430    return getName() + ".ecore";
3431  }
3432  
3433  protected boolean isBigModel()
3434  {
3435    int classes = getGenClasses().size();
3436    int supers = 0;
3437    int features = 0;
3438    int operations = 0;
3439    int parameters = 0;
3440    int exceptions = 0;
3441    
3442    for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
3443    {
3444      GenClass genClass = (GenClass)i.next();
3445      supers += genClass.getEcoreClass().getESuperTypes().size();
3446      features += genClass.getGenFeatures().size();
3447      operations += genClass.getGenOperations().size();
3448      
3449      for (Iterator JavaDoc j = genClass.getGenOperations().iterator(); j.hasNext(); )
3450      {
3451        GenOperation genOperation = (GenOperation)j.next();
3452        parameters += genOperation.getGenParameters().size();
3453        exceptions += genOperation.getEcoreOperation().getEExceptions().size();
3454      }
3455    }
3456
3457    int enums = getGenEnums().size();
3458    int literals = 0;
3459
3460    for (Iterator JavaDoc i = getGenEnums().iterator(); i.hasNext(); )
3461    {
3462      GenEnum genEnum = (GenEnum)i.next();
3463      literals += genEnum.getGenEnumLiterals().size();
3464    }
3465
3466    int datatypes = getGenDataTypes().size();
3467
3468    return (classes + supers + features + operations + parameters + exceptions + enums + literals + datatypes) > 500;
3469  }
3470  
3471  public List JavaDoc /*String*/ getProviderSupportedTypes()
3472  {
3473    List JavaDoc result = new ArrayList JavaDoc();
3474    result.add("org.eclipse.emf.edit.provider.IEditingDomainItemProvider");
3475    result.add("org.eclipse.emf.edit.provider.IStructuredItemContentProvider");
3476    result.add("org.eclipse.emf.edit.provider.ITreeItemContentProvider");
3477    result.add("org.eclipse.emf.edit.provider.IItemLabelProvider");
3478    result.add("org.eclipse.emf.edit.provider.IItemPropertySource");
3479    return result;
3480  }
3481  
3482  public GenClass getRootClass()
3483  {
3484    GenFeature rootFeature = getRootFeature();
3485    if (rootFeature == null)
3486    {
3487      for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext();)
3488      {
3489        GenClass genClass = (GenClass)i.next();
3490        if (!genClass.isAbstract())
3491        {
3492          return genClass;
3493        }
3494      }
3495      return null;
3496    }
3497    else
3498    {
3499      return rootFeature.getTypeGenClass();
3500    }
3501  }
3502
3503  public GenFeature getRootFeature()
3504  {
3505    EClass documentRoot = getExtendedMetaData().getDocumentRoot(getEcorePackage());
3506    if (documentRoot != null)
3507    {
3508      for (Iterator JavaDoc i = getExtendedMetaData().getAllElements(documentRoot).iterator(); i.hasNext();)
3509      {
3510        EStructuralFeature eStructuralFeature = (EStructuralFeature)i.next();
3511        if (eStructuralFeature instanceof EReference && !((EClass)eStructuralFeature.getEType()).isAbstract())
3512        {
3513          return findGenFeature(eStructuralFeature);
3514        }
3515      }
3516    }
3517    return null;
3518  }
3519    
3520  public boolean hasConcreteClasses()
3521  {
3522    for (Iterator JavaDoc i = getGenClasses().iterator(); i.hasNext(); )
3523    {
3524      GenClass genClass = (GenClass)i.next();
3525      if (!genClass.isAbstract())
3526      {
3527        return true;
3528      }
3529    }
3530    return false;
3531  }
3532} //GenPackageImpl
3533
Popular Tags