Retrieving eObject From Ecore File [message #634704] |
Fri, 22 October 2010 19:08 |
|
Hi,
I was trying to get EObjects from an Ecore file but could not succeed as i was getting a class cast exception.
I used the following code:-
String pathName = textForModelSelection.getText();// Full path of a .ecore file
Resource fileResource;
ResourceSet rSet = new ResourceSetImpl();
if (rSet != null) {
uri = URI.createFileURI(pathName);
fileResource = rSet.getResource(uri, true);
EPackage ecorepack = (EPackage) fileResource.getContents().get(0);
int i = 0;
List<EClass> classes = new ArrayList<EClass>();
EClassifier classifier = ecorepack.getEClassifiers().get(i);
while (classifier != null) {
if (classifier instanceof EClass) {
EClass modelClass = (EClass) ecorepack.getEClassifiers().get(i);
classes.add(modelClass);
}
classifier = ecorepack.getEClassifiers().get(i++);
}
}
I got the following Exception:
java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EEnumImpl cannot be cast to org.eclipse.emf.ecore.EClass
Please suggest me how else can i retrieve EObjects or EClass from .ecore file.
Also i have one more constraint and that is that i want to add only those classes who don't have any supertypes( classes that were not extended by any other class).
Regards,
Animesh
[Updated on: Fri, 22 October 2010 19:10] Report message to a moderator
|
|
|
|
Re: Retrievinf eObject From Ecore File [message #634830 is a reply to message #634714] |
Sun, 24 October 2010 06:47 |
|
Thanks for the reply. That was a silly mistake of mine. But about the second question i had asked:-
I want list of only those classes which are not inherited by any other class.
For ex: I am working on the Extended Library Model.... In that model there are numerous classes like Library, Book, CirculatingItem, Person, Employee, Borrower etc. But I want to retrieve only classes like Library, Book, Employee and Borrower and don't want classes like CircultatingItem and Person. How can i do this???
Regards,
Animesh
|
|
|
Re: Retrievinf eObject From Ecore File [message #634855 is a reply to message #634830] |
Sun, 24 October 2010 16:24 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Animesh,
Comments below.
Animesh Kumar wrote:
> Thanks for the reply. That was a silly mistake of mine. But about the
> second question i had asked:-
>
> I want list of only those classes which are not inherited by any other
> class.
Oh, leaf classes, so to speak.
> For ex: I am working on the Extended Library Model.... In that model
> there are numerous classes like Library, Book, CirculatingItem,
> Person, Employee, Borrower etc. But I want to retrieve only classes
> like Library, Book, Employee and Borrower and don't want classes like
> CircultatingItem and Person. How can i do this???
First consider your comment about "inherited by any other class".
You'll need to define what that means. I.e., what are all classes?
Once you bound that space, you can create a set of all classes, iterate
over them, and remove from that set, the getEAllSuperTypes of each and
every class in the set. The ones left in the set at the end, will be
the ones that don't appear in any EClass' eAllSuperTypes.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02778 seconds