KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > EPackageImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: EPackageImpl.java,v 1.16 2005/06/12 13:29:22 emerks Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.eclipse.emf.common.notify.Notification;
28 import org.eclipse.emf.common.notify.NotificationChain;
29 import org.eclipse.emf.common.util.EList;
30 import org.eclipse.emf.common.util.EMap;
31 import org.eclipse.emf.common.util.Enumerator;
32 import org.eclipse.emf.common.util.URI;
33 import org.eclipse.emf.ecore.EAnnotation;
34 import org.eclipse.emf.ecore.EAttribute;
35 import org.eclipse.emf.ecore.EClass;
36 import org.eclipse.emf.ecore.EClassifier;
37 import org.eclipse.emf.ecore.EDataType;
38 import org.eclipse.emf.ecore.EEnum;
39 import org.eclipse.emf.ecore.EEnumLiteral;
40 import org.eclipse.emf.ecore.EFactory;
41 import org.eclipse.emf.ecore.ENamedElement;
42 import org.eclipse.emf.ecore.EOperation;
43 import org.eclipse.emf.ecore.EPackage;
44 import org.eclipse.emf.ecore.EParameter;
45 import org.eclipse.emf.ecore.EReference;
46 import org.eclipse.emf.ecore.EStructuralFeature;
47 import org.eclipse.emf.ecore.EcoreFactory;
48 import org.eclipse.emf.ecore.EcorePackage;
49 import org.eclipse.emf.ecore.InternalEObject;
50 import org.eclipse.emf.ecore.resource.Resource;
51 import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
52 import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
53 import org.eclipse.emf.ecore.util.ExtendedMetaData;
54 import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
55 import org.eclipse.emf.ecore.util.InternalEList;
56
57
58 /**
59  * <!-- begin-user-doc -->
60  * An implementation of the model object '<em><b>EPackage</b></em>'.
61  * @extends BasicExtendedMetaData.EPackageExtendedMetaData.Holder
62  * <!-- end-user-doc -->
63  * <p>
64  * The following features are implemented:
65  * <ul>
66  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getNsURI <em>Ns URI</em>}</li>
67  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getNsPrefix <em>Ns Prefix</em>}</li>
68  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getEFactoryInstance <em>EFactory Instance</em>}</li>
69  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getEClassifiers <em>EClassifiers</em>}</li>
70  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getESubpackages <em>ESubpackages</em>}</li>
71  * <li>{@link org.eclipse.emf.ecore.impl.EPackageImpl#getESuperPackage <em>ESuper Package</em>}</li>
72  * </ul>
73  * </p>
74  *
75  * @generated
76  */

77 public class EPackageImpl extends ENamedElementImpl implements EPackage, BasicExtendedMetaData.EPackageExtendedMetaData.Holder
78 {
79   /**
80    * The default value of the '{@link #getNsURI() <em>Ns URI</em>}' attribute.
81    * <!-- begin-user-doc -->
82    * <!-- end-user-doc -->
83    * @see #getNsURI()
84    * @generated
85    * @ordered
86    */

87   protected static final String JavaDoc NS_URI_EDEFAULT = null;
88
89   /**
90    * The Ecore factory.
91    */

92   protected EcoreFactory ecoreFactory = null;
93
94   /**
95    * The Ecore factory.
96    */

97   protected EcorePackage ecorePackage = null;
98
99   /**
100    * The map from name to
101    */

102   protected Map JavaDoc eNameToEClassifierMap;
103
104   /**
105    * <!-- begin-user-doc -->
106    * Creates an instance.
107    * <!-- end-user-doc -->
108    * @generated NOT
109    */

110   protected EPackageImpl()
111   {
112     super();
113
114     setEFactoryInstance(new EFactoryImpl());
115
116     ecorePackage = EcorePackage.eINSTANCE;
117     ecoreFactory = EcoreFactory.eINSTANCE;
118   }
119
120   /**
121    * Creates an instance with a factory.
122    * @param eFactory the factory of the new package.
123    */

124   protected EPackageImpl(EFactory eFactory)
125   {
126     super();
127
128     setEFactoryInstance(eFactory);
129
130     ecorePackage = EcorePackage.eINSTANCE;
131     ecoreFactory = EcoreFactory.eINSTANCE;
132   }
133
134   /**
135    * Creates a {@link org.eclipse.emf.ecore.EPackage.Registry#INSTANCE registered} instance that has a default factory.
136    * @param packageURI the registered {@link #getNsURI namespace URI} of the new package.
137    */

138   protected EPackageImpl(String JavaDoc packageURI)
139   {
140     this(packageURI, new EFactoryImpl());
141   }
142
143   /**
144    * Creates a {@link org.eclipse.emf.ecore.EPackage.Registry#INSTANCE registered} instance with a factory.
145    * @param packageURI the registered {@link #getNsURI namespace URI} of the new package.
146    * @param factory the factory of the new package.
147    */

148   protected EPackageImpl(String JavaDoc packageURI, EFactory factory)
149   {
150     super();
151
152     Registry.INSTANCE.put(packageURI, this);
153
154     setEFactoryInstance(factory);
155
156     if (factory == EcoreFactory.eINSTANCE)
157     {
158       ecorePackage = (EcorePackage)this;
159       ecoreFactory = (EcoreFactory)factory;
160     }
161     else
162     {
163       ecorePackage = EcorePackage.eINSTANCE;
164       ecoreFactory = EcoreFactory.eINSTANCE;
165     }
166   }
167
168   public void freeze()
169   {
170     super.freeze();
171   }
172
173   /**
174    * <!-- begin-user-doc -->
175    * <!-- end-user-doc -->
176    * @generated
177    */

178   protected EClass eStaticClass()
179   {
180     return EcorePackage.eINSTANCE.getEPackage();
181   }
182
183   /**
184    * @generated modifiable
185    */

186   public void setNamespaceURI(String JavaDoc nsURI)
187   {
188   }
189
190   /**
191    * <!-- begin-user-doc -->
192    * <!-- end-user-doc -->
193    * @generated
194    */

195   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
196   {
197     switch (eDerivedStructuralFeatureID(eFeature))
198     {
199       case EcorePackage.EPACKAGE__EANNOTATIONS:
200         return getEAnnotations();
201       case EcorePackage.EPACKAGE__NAME:
202         return getName();
203       case EcorePackage.EPACKAGE__NS_URI:
204         return getNsURI();
205       case EcorePackage.EPACKAGE__NS_PREFIX:
206         return getNsPrefix();
207       case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
208         return getEFactoryInstance();
209       case EcorePackage.EPACKAGE__ECLASSIFIERS:
210         return getEClassifiers();
211       case EcorePackage.EPACKAGE__ESUBPACKAGES:
212         return getESubpackages();
213       case EcorePackage.EPACKAGE__ESUPER_PACKAGE:
214         return getESuperPackage();
215     }
216     return eDynamicGet(eFeature, resolve);
217   }
218
219   /**
220    * <!-- begin-user-doc -->
221    * <!-- end-user-doc -->
222    * @generated
223    */

224   public boolean eIsSet(EStructuralFeature eFeature)
225   {
226     switch (eDerivedStructuralFeatureID(eFeature))
227     {
228       case EcorePackage.EPACKAGE__EANNOTATIONS:
229         return eAnnotations != null && !eAnnotations.isEmpty();
230       case EcorePackage.EPACKAGE__NAME:
231         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
232       case EcorePackage.EPACKAGE__NS_URI:
233         return NS_URI_EDEFAULT == null ? nsURI != null : !NS_URI_EDEFAULT.equals(nsURI);
234       case EcorePackage.EPACKAGE__NS_PREFIX:
235         return NS_PREFIX_EDEFAULT == null ? nsPrefix != null : !NS_PREFIX_EDEFAULT.equals(nsPrefix);
236       case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
237         return eFactoryInstance != null;
238       case EcorePackage.EPACKAGE__ECLASSIFIERS:
239         return eClassifiers != null && !eClassifiers.isEmpty();
240       case EcorePackage.EPACKAGE__ESUBPACKAGES:
241         return eSubpackages != null && !eSubpackages.isEmpty();
242       case EcorePackage.EPACKAGE__ESUPER_PACKAGE:
243         return getESuperPackage() != null;
244     }
245     return eDynamicIsSet(eFeature);
246   }
247
248   /**
249    * <!-- begin-user-doc -->
250    * <!-- end-user-doc -->
251    * @generated
252    */

253   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
254   {
255     switch (eDerivedStructuralFeatureID(eFeature))
256     {
257       case EcorePackage.EPACKAGE__EANNOTATIONS:
258         getEAnnotations().clear();
259         getEAnnotations().addAll((Collection JavaDoc)newValue);
260         return;
261       case EcorePackage.EPACKAGE__NAME:
262         setName((String JavaDoc)newValue);
263         return;
264       case EcorePackage.EPACKAGE__NS_URI:
265         setNsURI((String JavaDoc)newValue);
266         return;
267       case EcorePackage.EPACKAGE__NS_PREFIX:
268         setNsPrefix((String JavaDoc)newValue);
269         return;
270       case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
271         setEFactoryInstance((EFactory)newValue);
272         return;
273       case EcorePackage.EPACKAGE__ECLASSIFIERS:
274         getEClassifiers().clear();
275         getEClassifiers().addAll((Collection JavaDoc)newValue);
276         return;
277       case EcorePackage.EPACKAGE__ESUBPACKAGES:
278         getESubpackages().clear();
279         getESubpackages().addAll((Collection JavaDoc)newValue);
280         return;
281     }
282     eDynamicSet(eFeature, newValue);
283   }
284
285   /**
286    * <!-- begin-user-doc -->
287    * <!-- end-user-doc -->
288    * @generated
289    */

290   public void eUnset(EStructuralFeature eFeature)
291   {
292     switch (eDerivedStructuralFeatureID(eFeature))
293     {
294       case EcorePackage.EPACKAGE__EANNOTATIONS:
295         getEAnnotations().clear();
296         return;
297       case EcorePackage.EPACKAGE__NAME:
298         setName(NAME_EDEFAULT);
299         return;
300       case EcorePackage.EPACKAGE__NS_URI:
301         setNsURI(NS_URI_EDEFAULT);
302         return;
303       case EcorePackage.EPACKAGE__NS_PREFIX:
304         setNsPrefix(NS_PREFIX_EDEFAULT);
305         return;
306       case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
307         setEFactoryInstance((EFactory)null);
308         return;
309       case EcorePackage.EPACKAGE__ECLASSIFIERS:
310         getEClassifiers().clear();
311         return;
312       case EcorePackage.EPACKAGE__ESUBPACKAGES:
313         getESubpackages().clear();
314         return;
315     }
316     eDynamicUnset(eFeature);
317   }
318
319   /**
320    * The cached value of the '{@link #getNsURI() <em>Ns URI</em>}' attribute.
321    * <!-- begin-user-doc -->
322    * <!-- end-user-doc -->
323    * @see #getNsURI()
324    * @generated
325    * @ordered
326    */

327   protected String JavaDoc nsURI = NS_URI_EDEFAULT;
328
329   /**
330    * The default value of the '{@link #getNsPrefix() <em>Ns Prefix</em>}' attribute.
331    * <!-- begin-user-doc -->
332    * <!-- end-user-doc -->
333    * @see #getNsPrefix()
334    * @generated
335    * @ordered
336    */

337   protected static final String JavaDoc NS_PREFIX_EDEFAULT = null;
338
339   /**
340    * The cached value of the '{@link #getNsPrefix() <em>Ns Prefix</em>}' attribute.
341    * <!-- begin-user-doc -->
342    * <!-- end-user-doc -->
343    * @see #getNsPrefix()
344    * @generated
345    * @ordered
346    */

347   protected String JavaDoc nsPrefix = NS_PREFIX_EDEFAULT;
348
349   /**
350    * The cached value of the '{@link #getEFactoryInstance() <em>EFactory Instance</em>}' reference.
351    * <!-- begin-user-doc -->
352    * <!-- end-user-doc -->
353    * @see #getEFactoryInstance()
354    * @generated
355    * @ordered
356    */

357   protected EFactory eFactoryInstance = null;
358
359   /**
360    * The cached value of the '{@link #getEClassifiers() <em>EClassifiers</em>}' containment reference list.
361    * <!-- begin-user-doc -->
362    * <!-- end-user-doc -->
363    * @see #getEClassifiers()
364    * @generated
365    * @ordered
366    */

367   protected EList eClassifiers = null;
368
369   /**
370    * The cached value of the '{@link #getESubpackages() <em>ESubpackages</em>}' containment reference list.
371    * <!-- begin-user-doc -->
372    * <!-- end-user-doc -->
373    * @see #getESubpackages()
374    * @generated
375    * @ordered
376    */

377   protected EList eSubpackages = null;
378
379   /**
380    * <!-- begin-user-doc -->
381    * <!-- end-user-doc -->
382    * @generated
383    */

384   public String JavaDoc getNsURI()
385   {
386     return nsURI;
387   }
388
389   /**
390    * <!-- begin-user-doc -->
391    * <!-- end-user-doc -->
392    * @generated
393    */

394   public void setNsURI(String JavaDoc newNsURI)
395   {
396     String JavaDoc oldNsURI = nsURI;
397     nsURI = newNsURI;
398     if (eNotificationRequired())
399       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__NS_URI, oldNsURI, nsURI));
400   }
401
402   /**
403    * <!-- begin-user-doc -->
404    * <!-- end-user-doc -->
405    * @generated
406    */

407   public String JavaDoc getNsPrefix()
408   {
409     return nsPrefix;
410   }
411
412   /**
413    * <!-- begin-user-doc -->
414    * <!-- end-user-doc -->
415    * @generated
416    */

417   public void setNsPrefix(String JavaDoc newNsPrefix)
418   {
419     String JavaDoc oldNsPrefix = nsPrefix;
420     nsPrefix = newNsPrefix;
421     if (eNotificationRequired())
422       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__NS_PREFIX, oldNsPrefix, nsPrefix));
423   }
424
425   /**
426    * <!-- begin-user-doc -->
427    * <!-- end-user-doc -->
428    * @generated
429    */

430   public EFactory getEFactoryInstance()
431   {
432     return eFactoryInstance;
433   }
434
435   /**
436    * <!-- begin-user-doc -->
437    * <!-- end-user-doc -->
438    * @generated
439    */

440   public void setEFactoryInstance(EFactory newEFactoryInstance)
441   {
442     if (newEFactoryInstance != eFactoryInstance)
443     {
444       NotificationChain msgs = null;
445       if (eFactoryInstance != null)
446         msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs);
447       if (newEFactoryInstance != null)
448         msgs = ((InternalEObject)newEFactoryInstance).eInverseAdd(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs);
449       msgs = basicSetEFactoryInstance(newEFactoryInstance, msgs);
450       if (msgs != null) msgs.dispatch();
451     }
452     else if (eNotificationRequired())
453       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__EFACTORY_INSTANCE, newEFactoryInstance, newEFactoryInstance));
454   }
455
456   /**
457    * <!-- begin-user-doc -->
458    * <!-- end-user-doc -->
459    * @generated
460    */

461   public NotificationChain basicSetEFactoryInstance(EFactory newEFactoryInstance, NotificationChain msgs)
462   {
463     EFactory oldEFactoryInstance = eFactoryInstance;
464     eFactoryInstance = newEFactoryInstance;
465     if (eNotificationRequired())
466     {
467       ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EcorePackage.EPACKAGE__EFACTORY_INSTANCE, oldEFactoryInstance, newEFactoryInstance);
468       if (msgs == null) msgs = notification; else msgs.add(notification);
469     }
470     return msgs;
471   }
472
473   /**
474    * <!-- begin-user-doc -->
475    * <!-- end-user-doc -->
476    * @generated NOT
477    */

478   public EList getEClassifiers()
479   {
480     if (eClassifiers == null)
481     {
482       eClassifiers =
483         new EObjectContainmentWithInverseEList(EClassifier.class, this, EcorePackage.EPACKAGE__ECLASSIFIERS, EcorePackage.ECLASSIFIER__EPACKAGE)
484         {
485           protected void didChange()
486           {
487             eNameToEClassifierMap = null;
488           }
489         };
490     }
491     return eClassifiers;
492   }
493
494   /**
495    * @generated modifiable
496    */

497   public EClassifier getEClassifier(String JavaDoc name)
498   {
499     if (eNameToEClassifierMap == null)
500     {
501       List JavaDoc eClassifiers = getEClassifiers();
502       Map JavaDoc result = new HashMap JavaDoc(eClassifiers.size());
503       for (Iterator JavaDoc i = eClassifiers.iterator(); i.hasNext(); )
504       {
505         EClassifier eClassifier = (EClassifier)i.next();
506         result.put(eClassifier.getName(), eClassifier);
507       }
508       eNameToEClassifierMap = result;
509     }
510
511     return (EClassifier)eNameToEClassifierMap.get(name);
512   }
513
514   /**
515    * <!-- begin-user-doc -->
516    * <!-- end-user-doc -->
517    * @generated
518    */

519   public EList getESubpackages()
520   {
521     if (eSubpackages == null)
522     {
523       eSubpackages = new EObjectContainmentWithInverseEList(EPackage.class, this, EcorePackage.EPACKAGE__ESUBPACKAGES, EcorePackage.EPACKAGE__ESUPER_PACKAGE);
524     }
525     return eSubpackages;
526   }
527
528   /**
529    * <!-- begin-user-doc -->
530    * <!-- end-user-doc -->
531    * @generated modifiable
532    */

533   public EPackage getESuperPackage()
534   {
535     return (eContainerFeatureID == EcorePackage.EPACKAGE__ESUPER_PACKAGE) ? (EPackage)eContainer : null;
536   }
537
538
539   /**
540    * <!-- begin-user-doc -->
541    * <!-- end-user-doc -->
542    * @generated
543    */

544   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
545   {
546     if (featureID >= 0)
547     {
548       switch (eDerivedStructuralFeatureID(featureID, baseClass))
549       {
550         case EcorePackage.EPACKAGE__EANNOTATIONS:
551           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
552         case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
553           if (eFactoryInstance != null)
554             msgs = ((InternalEObject)eFactoryInstance).eInverseRemove(this, EcorePackage.EFACTORY__EPACKAGE, EFactory.class, msgs);
555           return basicSetEFactoryInstance((EFactory)otherEnd, msgs);
556         case EcorePackage.EPACKAGE__ECLASSIFIERS:
557           return ((InternalEList)getEClassifiers()).basicAdd(otherEnd, msgs);
558         case EcorePackage.EPACKAGE__ESUBPACKAGES:
559           return ((InternalEList)getESubpackages()).basicAdd(otherEnd, msgs);
560         case EcorePackage.EPACKAGE__ESUPER_PACKAGE:
561           if (eContainer != null)
562             msgs = eBasicRemoveFromContainer(msgs);
563           return eBasicSetContainer(otherEnd, EcorePackage.EPACKAGE__ESUPER_PACKAGE, msgs);
564         default:
565           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
566       }
567     }
568     if (eContainer != null)
569       msgs = eBasicRemoveFromContainer(msgs);
570     return eBasicSetContainer(otherEnd, featureID, msgs);
571   }
572
573   /**
574    * <!-- begin-user-doc -->
575    * <!-- end-user-doc -->
576    * @generated
577    */

578   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
579   {
580     if (featureID >= 0)
581     {
582       switch (eDerivedStructuralFeatureID(featureID, baseClass))
583       {
584         case EcorePackage.EPACKAGE__EANNOTATIONS:
585           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
586         case EcorePackage.EPACKAGE__EFACTORY_INSTANCE:
587           return basicSetEFactoryInstance(null, msgs);
588         case EcorePackage.EPACKAGE__ECLASSIFIERS:
589           return ((InternalEList)getEClassifiers()).basicRemove(otherEnd, msgs);
590         case EcorePackage.EPACKAGE__ESUBPACKAGES:
591           return ((InternalEList)getESubpackages()).basicRemove(otherEnd, msgs);
592         case EcorePackage.EPACKAGE__ESUPER_PACKAGE:
593           return eBasicSetContainer(null, EcorePackage.EPACKAGE__ESUPER_PACKAGE, msgs);
594         default:
595           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
596       }
597     }
598     return eBasicSetContainer(null, featureID, msgs);
599   }
600
601   /**
602    * <!-- begin-user-doc -->
603    * <!-- end-user-doc -->
604    * @generated
605    */

606   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
607   {
608     if (eContainerFeatureID >= 0)
609     {
610       switch (eContainerFeatureID)
611       {
612         case EcorePackage.EPACKAGE__ESUPER_PACKAGE:
613           return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ESUBPACKAGES, EPackage.class, msgs);
614         default:
615           return eDynamicBasicRemoveFromContainer(msgs);
616       }
617     }
618     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
619   }
620
621   /**
622    * <!-- begin-user-doc -->
623    * <!-- end-user-doc -->
624    * @generated
625    */

626   public String JavaDoc toString()
627   {
628     if (eIsProxy()) return super.toString();
629
630     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
631     result.append(" (nsURI: ");
632     result.append(nsURI);
633     result.append(", nsPrefix: ");
634     result.append(nsPrefix);
635     result.append(')');
636     return result.toString();
637   }
638
639   protected Resource createResource(String JavaDoc uri)
640   {
641     Resource resource = eResource();
642     if (resource == null)
643     {
644       URI actualURI = URI.createURI(uri);
645       resource = new ResourceImpl(actualURI);
646       resource.getContents().add(this);
647     }
648     return resource;
649   }
650
651   protected EClass createEClass(int id)
652   {
653     EClassImpl c = (EClassImpl)ecoreFactory.createEClass();
654     c.setClassifierID(id);
655     getEClassifiers().add(c);
656     return c;
657   }
658
659   protected EEnum createEEnum(int id)
660   {
661     EEnumImpl e = (EEnumImpl)ecoreFactory.createEEnum();
662     e.setClassifierID(id);
663     getEClassifiers().add(e);
664     return e;
665   }
666
667   protected EDataType createEDataType(int id)
668   {
669     EDataTypeImpl d = (EDataTypeImpl)ecoreFactory.createEDataType();
670     d.setClassifierID(id);
671     getEClassifiers().add(d);
672     return d;
673   }
674
675   protected void createEAttribute(EClass owner, int id)
676   {
677     EAttributeImpl a = (EAttributeImpl)ecoreFactory.createEAttribute();
678     a.setFeatureID(id);
679     owner.getEStructuralFeatures().add(a);
680   }
681
682   protected void createEReference(EClass owner, int id)
683   {
684     EReferenceImpl r = (EReferenceImpl)ecoreFactory.createEReference();
685     r.setFeatureID(id);
686     owner.getEStructuralFeatures().add(r);
687   }
688
689   final static protected boolean IS_ABSTRACT = true;
690   final static protected boolean IS_INTERFACE = true;
691   final static protected boolean IS_GENERATED_INSTANCE_CLASS = true;
692
693   protected EClass initEClass(EClass c, Class JavaDoc instanceClass, String JavaDoc name, boolean isAbstract, boolean isInterface)
694   {
695     initEClassifier(c, ecorePackage.getEClass(), instanceClass, name);
696     c.setAbstract(isAbstract);
697     c.setInterface(isInterface);
698     return c;
699   }
700
701   protected EClass initEClass(EClass c, Class JavaDoc instanceClass, String JavaDoc name, boolean isAbstract, boolean isInterface, boolean isGenerated)
702   {
703     initEClassifier(c, ecorePackage.getEClass(), instanceClass, name, isGenerated);
704     c.setAbstract(isAbstract);
705     c.setInterface(isInterface);
706     return c;
707   }
708
709   protected EEnum initEEnum(EEnum e, Class JavaDoc instanceClass, String JavaDoc name)
710   {
711     initEClassifier(e, ecorePackage.getEEnum(), instanceClass, name, true);
712     return e;
713   }
714
715   final static protected boolean IS_SERIALIZABLE = true;
716
717   protected EDataType initEDataType(EDataType d, Class JavaDoc instanceClass, String JavaDoc name, boolean isSerializable)
718   {
719     initEClassifier(d, ecorePackage.getEDataType(), instanceClass, name, false);
720     d.setSerializable(isSerializable);
721     return d;
722   }
723
724   protected EDataType initEDataType(EDataType d, Class JavaDoc instanceClass, String JavaDoc name, boolean isSerializable, boolean isGenerated)
725   {
726     initEClassifier(d, ecorePackage.getEDataType(), instanceClass, name, isGenerated);
727     d.setSerializable(isSerializable);
728     return d;
729   }
730
731   private void initEClassifier(EClassifier o, EClass metaObject, Class JavaDoc instanceClass, String JavaDoc name)
732   {
733     o.setName(name);
734     if (instanceClass != null)
735     {
736       o.setInstanceClass(instanceClass);
737     }
738   }
739
740   private void initEClassifier(EClassifier o, EClass metaObject, Class JavaDoc instanceClass, String JavaDoc name, boolean isGenerated)
741   {
742     o.setName(name);
743     if (instanceClass != null)
744     {
745       o.setInstanceClass(instanceClass);
746     }
747     if (isGenerated)
748     {
749       setGeneratedClassName(o);
750     }
751   }
752
753   protected void setGeneratedClassName(EClassifier eClassifier)
754   {
755     ((EClassifierImpl)eClassifier).setGeneratedInstanceClass(true);
756   }
757
758   protected static final boolean IS_DERIVED = true;
759   protected static final boolean IS_TRANSIENT = true;
760   protected static final boolean IS_VOLATILE = true;
761   protected static final boolean IS_CHANGEABLE = true;
762   protected static final boolean IS_UNSETTABLE = true;
763   protected static final boolean IS_UNIQUE = true;
764   protected static final boolean IS_ID = true;
765   protected static final boolean IS_ORDERED = true;
766
767   /**
768    * @deprecated
769    */

770   protected EAttribute initEAttribute
771     (EAttribute a,
772      EClassifier type,
773      String JavaDoc name,
774      String JavaDoc defaultValue,
775      int lowerBound,
776      int upperBound,
777      boolean isTransient,
778      boolean isVolatile,
779      boolean isChangeable,
780      boolean isUnsettable)
781   {
782     return
783       initEAttribute
784         (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, false, true);
785   }
786
787   /**
788    * @deprecated
789    */

790   protected EAttribute initEAttribute
791     (EAttribute a,
792      EClassifier type,
793      String JavaDoc name,
794      String JavaDoc defaultValue,
795      int lowerBound,
796      int upperBound,
797      boolean isTransient,
798      boolean isVolatile,
799      boolean isChangeable,
800      boolean isUnsettable,
801      boolean isID)
802   {
803     return
804       initEAttribute
805         (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, isID, true);
806   }
807
808   /**
809    * @deprecated
810    */

811   protected EAttribute initEAttribute
812     (EAttribute a,
813      EClassifier type,
814      String JavaDoc name,
815      String JavaDoc defaultValue,
816      int lowerBound,
817      int upperBound,
818      boolean isTransient,
819      boolean isVolatile,
820      boolean isChangeable,
821      boolean isUnsettable,
822      boolean isID,
823      boolean isUnique)
824   {
825     return
826       initEAttribute
827         (a, type, name, defaultValue, lowerBound, upperBound, isTransient, isVolatile, isChangeable, isUnsettable, isID, isUnique, false);
828   }
829
830   protected EAttribute initEAttribute
831     (EAttribute a,
832      EClassifier type,
833      String JavaDoc name,
834      String JavaDoc defaultValue,
835      int lowerBound,
836      int upperBound,
837      boolean isTransient,
838      boolean isVolatile,
839      boolean isChangeable,
840      boolean isUnsettable,
841      boolean isID,
842      boolean isUnique,
843      boolean isDerived)
844   {
845     return
846       initEAttribute
847         (a,
848          type,
849          name,
850          defaultValue,
851          lowerBound,
852          upperBound,
853          isTransient,
854          isVolatile,
855          isChangeable,
856          isUnsettable,
857          isID,
858          isUnique,
859          isDerived,
860          true);
861   }
862
863   protected EAttribute initEAttribute
864     (EAttribute a,
865      EClassifier type,
866      String JavaDoc name,
867      String JavaDoc defaultValue,
868      int lowerBound,
869      int upperBound,
870      boolean isTransient,
871      boolean isVolatile,
872      boolean isChangeable,
873      boolean isUnsettable,
874      boolean isID,
875      boolean isUnique,
876      boolean isDerived,
877      boolean isOrdered)
878   {
879     initEAttribute
880       (a,
881        type,
882        name,
883        defaultValue,
884        lowerBound,
885        upperBound,
886        ((EClassifier)a.eContainer()).getInstanceClass(),
887        isTransient,
888        isVolatile,
889        isChangeable,
890        isUnsettable,
891        isID,
892        isUnique,
893        isDerived,
894        isOrdered);
895     return a;
896   }
897
898   protected EAttribute initEAttribute
899     (EAttribute a,
900      EClassifier type,
901      String JavaDoc name,
902      String JavaDoc defaultValue,
903      int lowerBound,
904      int upperBound,
905      Class JavaDoc containerClass,
906      boolean isTransient,
907      boolean isVolatile,
908      boolean isChangeable,
909      boolean isUnsettable,
910      boolean isID,
911      boolean isUnique,
912      boolean isDerived,
913      boolean isOrdered)
914   {
915     initEStructuralFeature
916       (a,
917        type,
918        name,
919        defaultValue,
920        lowerBound,
921        upperBound,
922        containerClass,
923        isTransient,
924        isVolatile,
925        isChangeable,
926        isUnsettable,
927        isUnique,
928        isDerived,
929        isOrdered);
930     a.setID(isID);
931     return a;
932   }
933
934   final static protected boolean IS_COMPOSITE = true;
935   final static protected boolean IS_RESOLVE_PROXIES = true;
936   final static protected boolean IS_RESOLVABLE = true;
937
938   /**
939    * @deprecated
940    */

941   protected EReference initEReference
942     (EReference r,
943      EClassifier type,
944      EReference otherEnd,
945      String JavaDoc name,
946      String JavaDoc defaultValue,
947      int lowerBound,
948      int upperBound,
949      boolean isTransient,
950      boolean isVolatile,
951      boolean isChangeable,
952      boolean isContainment,
953      boolean isResolveProxies)
954   {
955     initEReference
956       (r,
957        type,
958        otherEnd,
959        name,
960        defaultValue,
961        lowerBound,
962        upperBound,
963        isTransient,
964        isVolatile,
965        isChangeable,
966        isContainment,
967        isResolveProxies,
968        false,
969        true);
970     return r;
971   }
972
973   /**
974    * @deprecated
975    */

976   protected EReference initEReference
977     (EReference r,
978      EClassifier type,
979      EReference otherEnd,
980      String JavaDoc name,
981      String JavaDoc defaultValue,
982      int lowerBound,
983      int upperBound,
984      boolean isTransient,
985      boolean isVolatile,
986      boolean isChangeable,
987      boolean isContainment,
988      boolean isResolveProxies,
989      boolean isUnsettable)
990   {
991     initEReference
992       (r,
993        type,
994        otherEnd,
995        name,
996        defaultValue,
997        lowerBound,
998        upperBound,
999        isTransient,
1000       isVolatile,
1001       isChangeable,
1002       isContainment,
1003       isResolveProxies,
1004       isUnsettable,
1005       true);
1006    return r;
1007  }
1008
1009  /**
1010   * @deprecated
1011   */

1012  protected EReference initEReference
1013    (EReference r,
1014     EClassifier type,
1015     EReference otherEnd,
1016     String JavaDoc name,
1017     String JavaDoc defaultValue,
1018     int lowerBound,
1019     int upperBound,
1020     boolean isTransient,
1021     boolean isVolatile,
1022     boolean isChangeable,
1023     boolean isContainment,
1024     boolean isResolveProxies,
1025     boolean isUnsettable,
1026     boolean isUnique)
1027  {
1028    initEReference
1029      (r,
1030       type,
1031       otherEnd,
1032       name,
1033       defaultValue,
1034       lowerBound,
1035       upperBound,
1036       isTransient,
1037       isVolatile,
1038       isChangeable,
1039       isContainment,
1040       isResolveProxies,
1041       isUnsettable,
1042       isUnique,
1043       false);
1044    return r;
1045  }
1046
1047  protected EReference initEReference
1048    (EReference r,
1049     EClassifier type,
1050     EReference otherEnd,
1051     String JavaDoc name,
1052     String JavaDoc defaultValue,
1053     int lowerBound,
1054     int upperBound,
1055     boolean isTransient,
1056     boolean isVolatile,
1057     boolean isChangeable,
1058     boolean isContainment,
1059     boolean isResolveProxies,
1060     boolean isUnsettable,
1061     boolean isUnique,
1062     boolean isDerived)
1063  {
1064    initEReference
1065      (r,
1066       type,
1067       otherEnd,
1068       name,
1069       defaultValue,
1070       lowerBound,
1071       upperBound,
1072       isTransient,
1073       isVolatile,
1074       isChangeable,
1075       isContainment,
1076       isResolveProxies,
1077       isUnsettable,
1078       isUnique,
1079       isDerived,
1080       true);
1081    return r;
1082  }
1083
1084  protected EReference initEReference
1085    (EReference r,
1086     EClassifier type,
1087     EReference otherEnd,
1088     String JavaDoc name,
1089     String JavaDoc defaultValue,
1090     int lowerBound,
1091     int upperBound,
1092     boolean isTransient,
1093     boolean isVolatile,
1094     boolean isChangeable,
1095     boolean isContainment,
1096     boolean isResolveProxies,
1097     boolean isUnsettable,
1098     boolean isUnique,
1099     boolean isDerived,
1100     boolean isOrdered)
1101  {
1102    initEReference
1103      (r,
1104       type,
1105       otherEnd,
1106       name,
1107       defaultValue,
1108       lowerBound,
1109       upperBound,
1110       ((EClassifier)r.eContainer()).getInstanceClass(),
1111       isTransient,
1112       isVolatile,
1113       isChangeable,
1114       isContainment,
1115       isResolveProxies,
1116       isUnsettable,
1117       isUnique,
1118       isDerived,
1119       isOrdered);
1120    return r;
1121  }
1122
1123  protected EReference initEReference
1124    (EReference r,
1125     EClassifier type,
1126     EReference otherEnd,
1127     String JavaDoc name,
1128     String JavaDoc defaultValue,
1129     int lowerBound,
1130     int upperBound,
1131     Class JavaDoc containerClass,
1132     boolean isTransient,
1133     boolean isVolatile,
1134     boolean isChangeable,
1135     boolean isContainment,
1136     boolean isResolveProxies,
1137     boolean isUnsettable,
1138     boolean isUnique,
1139     boolean isDerived,
1140     boolean isOrdered)
1141  {
1142    initEStructuralFeature
1143      (r,
1144       type,
1145       name,
1146       defaultValue,
1147       lowerBound,
1148       upperBound,
1149       containerClass,
1150       isTransient,
1151       isVolatile,
1152       isChangeable,
1153       isUnsettable,
1154       isUnique,
1155       isDerived,
1156       isOrdered);
1157    r.setContainment(isContainment);
1158    if (otherEnd != null)
1159    {
1160      r.setEOpposite(otherEnd);
1161    }
1162    r.setResolveProxies(isResolveProxies);
1163    return r;
1164  }
1165
1166  private void initEStructuralFeature
1167    (EStructuralFeature s,
1168     EClassifier type,
1169     String JavaDoc name,
1170     String JavaDoc defaultValue,
1171     int lowerBound,
1172     int upperBound,
1173     Class JavaDoc containerClass,
1174     boolean isTransient,
1175     boolean isVolatile,
1176     boolean isChangeable,
1177     boolean isUnsettable,
1178     boolean isUnique,
1179     boolean isDerived,
1180     boolean isOrdered)
1181  {
1182    s.setName(name);
1183    ((EStructuralFeatureImpl)s).setContainerClass(containerClass);
1184    s.setTransient(isTransient);
1185    s.setVolatile(isVolatile);
1186    s.setChangeable(isChangeable);
1187    s.setUnsettable(isUnsettable);
1188    s.setUnique(isUnique);
1189    s.setDerived(isDerived);
1190    s.setOrdered(isOrdered);
1191    s.setLowerBound(lowerBound);
1192    s.setUpperBound(upperBound);
1193    s.setEType(type);
1194    if (defaultValue != null)
1195    {
1196      s.setDefaultValueLiteral(defaultValue);
1197    }
1198  }
1199
1200  protected EOperation addEOperation(EClass owner, EClassifier type, String JavaDoc name)
1201  {
1202    EOperation o = ecoreFactory.createEOperation();
1203    o.setEType(type);
1204    o.setName(name);
1205    owner.getEOperations().add(o);
1206    return o;
1207  }
1208
1209  protected void addEParameter(EOperation owner, EClassifier type, String JavaDoc name)
1210  {
1211    EParameter p = ecoreFactory.createEParameter();
1212    p.setEType(type);
1213    p.setName(name);
1214    owner.getEParameters().add(p);
1215  }
1216
1217  protected void addEException(EOperation owner, EClassifier exception)
1218  {
1219    owner.getEExceptions().add(exception);
1220  }
1221
1222  protected void addEEnumLiteral(EEnum owner, Enumerator e)
1223  {
1224    EEnumLiteral l = ecoreFactory.createEEnumLiteral();
1225    l.setInstance(e);
1226    owner.getELiterals().add(l);
1227  }
1228
1229  protected void addAnnotation(ENamedElement eNamedElement, String JavaDoc source, String JavaDoc [] details)
1230  {
1231    EAnnotation eAnnotation = ecoreFactory.createEAnnotation();
1232    eAnnotation.setSource(source);
1233    EMap theDetails = eAnnotation.getDetails();
1234    for (int i = 1; i < details.length; i += 2)
1235    {
1236      theDetails.put(details[i - 1], details[i]);
1237    }
1238    eNamedElement.getEAnnotations().add(eAnnotation);
1239  }
1240
1241  protected void initializeFromLoadedEPackage(EPackage target, EPackage source)
1242  {
1243    target.setName(source.getName());
1244    target.setNsPrefix(source.getNsPrefix());
1245    target.setNsURI(source.getNsURI());
1246
1247    target.getEClassifiers().addAll(source.getEClassifiers());
1248    target.getEAnnotations().addAll(source.getEAnnotations());
1249
1250    for (Iterator JavaDoc i = source.getESubpackages().iterator(); i.hasNext(); )
1251    {
1252      EPackage sourceSubpackage = (EPackage)i.next();
1253      EPackage targetSubpackage = EPackage.Registry.INSTANCE.getEPackage(sourceSubpackage.getNsURI());
1254      initializeFromLoadedEPackage(targetSubpackage, sourceSubpackage);
1255      target.getESubpackages().add(targetSubpackage);
1256    }
1257  }
1258  
1259  protected void fixEClassifiers()
1260  {
1261    int id = 0;
1262    
1263    for (Iterator JavaDoc i = getEClassifiers().iterator(); i.hasNext(); )
1264    {
1265      EClassifierImpl eClassifier = (EClassifierImpl)i.next();
1266      if (eClassifier instanceof EClass)
1267      {
1268        eClassifier.setClassifierID(id++);
1269        fixInstanceClass(eClassifier);
1270        fixEStructuralFeatures((EClass)eClassifier);
1271      }
1272    }
1273    
1274    for (Iterator JavaDoc i = getEClassifiers().iterator(); i.hasNext(); )
1275    {
1276      EClassifierImpl eClassifier = (EClassifierImpl)i.next();
1277      if (eClassifier.getClassifierID() == -1 && eClassifier instanceof EEnum)
1278      {
1279        eClassifier.setClassifierID(id++);
1280        fixInstanceClass(eClassifier);
1281        fixEEnumLiterals((EEnum)eClassifier);
1282      }
1283    }
1284
1285    for (Iterator JavaDoc i = getEClassifiers().iterator(); i.hasNext(); )
1286    {
1287      EClassifierImpl eClassifier = (EClassifierImpl)i.next();
1288      if (eClassifier.getClassifierID() == -1 && eClassifier instanceof EDataType)
1289      {
1290        eClassifier.setClassifierID(id++);
1291        if (eClassifier.getInstanceClassName() == "org.eclipse.emf.common.util.AbstractEnumerator")
1292        {
1293          EDataType baseType = ExtendedMetaData.INSTANCE.getBaseType((EDataType)eClassifier);
1294          if (baseType instanceof EEnum)
1295          {
1296            eClassifier.setInstanceClass(baseType.getInstanceClass());
1297            setGeneratedClassName(eClassifier);
1298          }
1299        }
1300      }
1301    }
1302  }
1303
1304  protected void fixInstanceClass(EClassifier eClassifier)
1305  {
1306    if (eClassifier.getInstanceClassName() == null)
1307    {
1308      String JavaDoc className = getClass().getName();
1309      int i = className.lastIndexOf('.', className.lastIndexOf('.') - 1);
1310      className = i == -1 ? eClassifier.getName() : className.substring(0, i + 1) + eClassifier.getName();
1311      eClassifier.setInstanceClassName(className);
1312      setGeneratedClassName(eClassifier);
1313    }
1314  }
1315
1316  protected void fixEStructuralFeatures(EClass eClass)
1317  {
1318    List JavaDoc features = eClass.getEStructuralFeatures();
1319    if (!features.isEmpty())
1320    {
1321      // The container class must be null for the open content features of the document root
1322
// to ensure that they are looked up in the actual eClass()
1323
// rather than assumed to be a feature with a feature ID relative to the actual class.
1324
// Otherwise, it's good to have this optimization.
1325
//
1326
Class JavaDoc containerClass = ExtendedMetaData.INSTANCE.getDocumentRoot(this) == eClass ? null : eClass.getInstanceClass();
1327
1328      int id = eClass.getFeatureID((EStructuralFeature)features.get(0));
1329      
1330      for (Iterator JavaDoc i = features.iterator(); i.hasNext(); )
1331      {
1332        EStructuralFeatureImpl eStructuralFeature = (EStructuralFeatureImpl)i.next();
1333        eStructuralFeature.setFeatureID(id++);
1334        eStructuralFeature.setContainerClass(containerClass);
1335      }
1336    }
1337  }
1338
1339  protected void fixEEnumLiterals(EEnum eEnum)
1340  {
1341    Class JavaDoc enumClass = eEnum.getInstanceClass();
1342    
1343    try
1344    {
1345      Method JavaDoc getter = enumClass.getMethod("get", new Class JavaDoc[] { Integer.TYPE });
1346
1347      for (Iterator JavaDoc i = eEnum.getELiterals().iterator(); i.hasNext(); )
1348      {
1349        EEnumLiteral eEnumLiteral = (EEnumLiteral)i.next();
1350        Enumerator instance = (Enumerator)getter.invoke(null, new Object JavaDoc[] { new Integer JavaDoc(eEnumLiteral.getValue()) });
1351        eEnumLiteral.setInstance(instance);
1352      }
1353    }
1354    catch (Exception JavaDoc e)
1355    {
1356      // Do nothing
1357
}
1358  }
1359
1360  protected BasicExtendedMetaData.EPackageExtendedMetaData ePackageExtendedMetaData;
1361
1362  public BasicExtendedMetaData.EPackageExtendedMetaData getExtendedMetaData()
1363  {
1364    return ePackageExtendedMetaData;
1365  }
1366
1367  public void setExtendedMetaData(BasicExtendedMetaData.EPackageExtendedMetaData ePackageExtendedMetaData)
1368  {
1369    this.ePackageExtendedMetaData = ePackageExtendedMetaData;
1370  }
1371}
1372
Popular Tags