EEnum to Epackage relationship lost [message #73745] |
Tue, 06 March 2007 13:35 |
Eclipse User |
|
|
|
Originally posted by: prateek.babel.in.bosch.com
Hello,
I have a condition where I have an EPackage(OriginPackage) with some
EClassifiers in it.
Now using Dynamic EMF we are trying to create a new package with details
from OriginPackage like EClassifiers,name,uri,nsURI.
Code Snipplet:
for (Iterator iter = oldSubpackage.getEClassifiers().iterator();
iter.hasNext();) {
// Object container = element.getEClassifiers().get(i);
Object container = iter.next();
if (container instanceof EClass) {
EClass newClass = EcoreFactory.eINSTANCE.createEClass();
newClass.setName("_" + ((EClass) container).getName());
newClass.getESuperTypes().add(container);
newSubPackage.getEClassifiers().add(newClass);
} else {
EEnum tempEnum = EcoreFactory.eINSTANCE.createEEnum();
tempEnum.setName(((EEnum) container).getName());
tempEnum.getELiterals().addAll(((EEnum) container).getELiterals());
newSubPackage.getEClassifiers().add(tempEnum);
}
}
When this code is executed for the EEnum classifiers the EPackage is not
set. That is if i try to do eenum.getEPackage() it return null.
Any solutions?
|
|
|
Re: EEnum to Epackage relationship lost [message #73781 is a reply to message #73745] |
Tue, 06 March 2007 14:15 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Prateek,
It looks like this code wouldn't work if the EClassifier is an
EDataType. It also looks like you will move the EEnumLiterals from the
original to the copy; you should use EcoreUtil.copy to copy each
literal. It should not be possible for tempEnum to have no containing
EPackage after you add it to the classifiers of a package. What's the
value of EObject.eContainer() and EObject.eContainmentFeature() for it?
Prateek wrote:
> Hello,
> I have a condition where I have an EPackage(OriginPackage) with some
> EClassifiers in it.
> Now using Dynamic EMF we are trying to create a new package with
> details from OriginPackage like EClassifiers,name,uri,nsURI.
>
> Code Snipplet:
>
> for (Iterator iter = oldSubpackage.getEClassifiers().iterator();
> iter.hasNext();) {
>
> // Object container = element.getEClassifiers().get(i);
> Object container = iter.next();
> if (container instanceof EClass) {
> EClass newClass = EcoreFactory.eINSTANCE.createEClass();
> newClass.setName("_" + ((EClass) container).getName());
> newClass.getESuperTypes().add(container);
> newSubPackage.getEClassifiers().add(newClass);
> } else {
> EEnum tempEnum = EcoreFactory.eINSTANCE.createEEnum();
> tempEnum.setName(((EEnum) container).getName());
> tempEnum.getELiterals().addAll(((EEnum)
> container).getELiterals());
> newSubPackage.getEClassifiers().add(tempEnum);
> }
> }
>
>
> When this code is executed for the EEnum classifiers the EPackage is
> not set. That is if i try to do eenum.getEPackage() it return null.
>
>
> Any solutions?
>
|
|
|
Re: EEnum to Epackage relationship lost [message #603163 is a reply to message #73745] |
Tue, 06 March 2007 14:15 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
Prateek,
It looks like this code wouldn't work if the EClassifier is an
EDataType. It also looks like you will move the EEnumLiterals from the
original to the copy; you should use EcoreUtil.copy to copy each
literal. It should not be possible for tempEnum to have no containing
EPackage after you add it to the classifiers of a package. What's the
value of EObject.eContainer() and EObject.eContainmentFeature() for it?
Prateek wrote:
> Hello,
> I have a condition where I have an EPackage(OriginPackage) with some
> EClassifiers in it.
> Now using Dynamic EMF we are trying to create a new package with
> details from OriginPackage like EClassifiers,name,uri,nsURI.
>
> Code Snipplet:
>
> for (Iterator iter = oldSubpackage.getEClassifiers().iterator();
> iter.hasNext();) {
>
> // Object container = element.getEClassifiers().get(i);
> Object container = iter.next();
> if (container instanceof EClass) {
> EClass newClass = EcoreFactory.eINSTANCE.createEClass();
> newClass.setName("_" + ((EClass) container).getName());
> newClass.getESuperTypes().add(container);
> newSubPackage.getEClassifiers().add(newClass);
> } else {
> EEnum tempEnum = EcoreFactory.eINSTANCE.createEEnum();
> tempEnum.setName(((EEnum) container).getName());
> tempEnum.getELiterals().addAll(((EEnum)
> container).getELiterals());
> newSubPackage.getEClassifiers().add(tempEnum);
> }
> }
>
>
> When this code is executed for the EEnum classifiers the EPackage is
> not set. That is if i try to do eenum.getEPackage() it return null.
>
>
> Any solutions?
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02686 seconds