Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Urgent : How to Read the Ecore Model(Reading the Ecore Model)
icon9.gif  Urgent : How to Read the Ecore Model [message #872489] Wed, 16 May 2012 04:09 Go to next message
Sriram Ramanujam is currently offline Sriram Ramanujam
Messages: 7
Registered: May 2012
Junior Member
Hi frnds,
I am newbie in Eclipse developments,
Right Now i was comfortable in creating a ecore model fully,
Now i need to READ THE ATTRIBUTES,CLASSES,REFERNCES which are present in the model Programmatically..

Could able to post a kind small code snippets and detailed procedures like how and where to use it..

Thanks

--
Sriram
Re: Urgent : How to Read the Ecore Model [message #872531 is a reply to message #872489] Wed, 16 May 2012 05:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Have a look at this article:

http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/

Reading an Ecore model is a matter of registering
EcoreResourceFactoryImpl to handle "ecore" extension, using a resource
set to load the resource, and then pulling the EPackage from the
resource.getContents()...



On 16/05/2012 10:09 AM, Sriram Ramanujam wrote:
> Hi frnds,
> I am newbie in Eclipse developments, Right Now i was comfortable in
> creating a ecore model fully,
> Now i need to READ THE ATTRIBUTES,CLASSES,REFERNCES which are present
> in the model Programmatically..
> Could able to post a kind small code snippets and detailed procedures
> like how and where to use it..
> Thanks
> --
> Sriram
Re: Urgent : How to Read the Ecore Model [message #872923 is a reply to message #872531] Thu, 17 May 2012 01:22 Go to previous messageGo to next message
Sriram Ramanujam is currently offline Sriram Ramanujam
Messages: 7
Registered: May 2012
Junior Member
Thanks Ed Merks !!

Actually, I finished the Code by the above mentioned link and also from the EMF 2nd Edition.. it looks something like this...
--------------------------------------------------------
public static void printClasses(EPackage ePackage)
{
for (Iterator iter =
ePackage.getEClassifiers().iterator(); iter.hasNext(); ) {
EClassifier classifier = (EClassifier)iter.next();
System.out.println(classifier.getName());
System.out.print(" ");
if (classifier instanceof EClass) {
EClass eClass = (EClass)classifier;
for (Iterator ai =
eClass.getEAttributes().iterator(); ai.hasNext(); ) {
EAttribute attribute = (EAttribute)ai.next();
System.out.print(attribute.getName() + " ");
}
for (Iterator ri =
eClass.getEReferences().iterator(); ri.hasNext(); ) {
EReference reference = (EReference)ri.next();
System.out.print(reference.getName() + " ");
}
}
else if (classifier instanceof EEnum) {
EEnum eEnum = (EEnum)classifier;
for (Iterator ei =
eEnum.getELiterals().iterator(); ei.hasNext(); ) {
EEnumLiteral literal = (EEnumLiteral)ei.next();
System.out.print(literal.getName() + " ");
}
}
else if (classifier instanceof EDataType) {
EDataType eDataType = (EDataType)classifier;
System.out.print(eDataType.getInstanceClassName() + " ");
}
System.out.println();
}
}
---------------------------------------------------

The above code will read the whole Model and it will print it...

QUESTION :

Where to write this code ? how and where i will get the output ?
Either inside/outside the "src" folder ?
or Inside the package which representing the model ?
or By creating the new package inside the "src" and write this code ?
or else i want to write this code within the EPO2Package/EPO2Factory ??


Sorry, I was structed up some where in this area !!
Thanks
--
Sriram R.
Re: Urgent : How to Read the Ecore Model [message #872927 is a reply to message #872923] Thu, 17 May 2012 01:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Sriram,

Comments below.

On 17/05/2012 7:22 AM, Sriram Ramanujam wrote:
> Thanks Ed Merks !!
> Actually, I finished the Code by the above mentioned link and also
> from the EMF 2nd Edition.. it looks something like this...
> --------------------------------------------------------
> public static void printClasses(EPackage ePackage)
> {
> for (Iterator iter =
> ePackage.getEClassifiers().iterator(); iter.hasNext(); ) {
> EClassifier classifier = (EClassifier)iter.next();
> System.out.println(classifier.getName());
> System.out.print(" ");
> if (classifier instanceof EClass) {
> EClass eClass = (EClass)classifier;
> for (Iterator ai =
> eClass.getEAttributes().iterator(); ai.hasNext(); ) {
> EAttribute attribute = (EAttribute)ai.next();
> System.out.print(attribute.getName() + " ");
> }
> for (Iterator ri =
> eClass.getEReferences().iterator(); ri.hasNext(); ) {
> EReference reference = (EReference)ri.next();
> System.out.print(reference.getName() + " ");
> }
> }
> else if (classifier instanceof EEnum) {
> EEnum eEnum = (EEnum)classifier;
> for (Iterator ei =
> eEnum.getELiterals().iterator(); ei.hasNext(); ) {
> EEnumLiteral literal = (EEnumLiteral)ei.next();
> System.out.print(literal.getName() + " ");
> }
> }
> else if (classifier instanceof EDataType) {
> EDataType eDataType = (EDataType)classifier;
> System.out.print(eDataType.getInstanceClassName() + " ");
> }
> System.out.println();
> }
> }
> ---------------------------------------------------
>
> The above code will read the whole Model and it will print it...
>
> QUESTION :
> Where to write this code ?
I don't follow your question.
> how and where i will get the output ?
In the output stream? On the console?
> Either inside/outside the "src" folder ? or Inside the package which
> representing the model ? or By creating the new package inside the
> "src" and write this code ?
You put it in whatever method in whatever class in whatever Java
project's source folder you want.
> or else i want to write this code within the EPO2Package/EPO2Factory ??
If you have a generated package, you can always use
EOP2Package.eINSTANCE.eResource().save(System.out, null) to print out
the XMI serialization of the package and its contents.
>
> Sorry, I was structed up some where in this area !! Thanks --
> Sriram R.
Re: Urgent : How to Read the Ecore Model [message #872935 is a reply to message #872927] Thu, 17 May 2012 02:07 Go to previous messageGo to next message
Sriram Ramanujam is currently offline Sriram Ramanujam
Messages: 7
Registered: May 2012
Junior Member
Thanks for your reply Ed Merks !!

Let me explain it clearly...

After writing Annotated Java code in Empty EMF Project by adding a Package "com.eclipse.epo2" and the corresponding classes to them. I generated the Model, by RIGHT Clicking the generated "epo2.genmodel" and with "generate all" Option.

Now when you look at the Package explorer we will have four folders which look like
com.eclipse.epo2 (3 Packages )
com.eclipse.epo2.edit ( 1 package )
com.eclipse.epo2.editor ( 1 Package)
com.eclipse.epo2.tests (1 package)
till this point i was fine.
QUESTION 1:

Now i just want know in which package i want to add this above mentioned code(in previous post) ?
Whether i want to add it to the .edit project (or) .editor project (or) .tests project or else
with the model (i.e., com.eclipse.epo2) ??

QUESTION 2:
If
i want to write in any one of the package mentioned above..
then
in which package ?
whether i want to create some new classes ?
Or else i want to over ride in some of the existing classes ?

Thanks
--
Sriram R
Re: Urgent : How to Read the Ecore Model [message #872941 is a reply to message #872927] Thu, 17 May 2012 02:28 Go to previous messageGo to next message
Sriram Ramanujam is currently offline Sriram Ramanujam
Messages: 7
Registered: May 2012
Junior Member
Rather confusing you let me share my Project Objective :

Problem Statement:
I just need to Create Eclipse Plugin which should Read and Write the Ecore model programmatically.

From User point of View these are the following things that the PLUG IN should deliver:
i) User need to Create/Import the Ecore Model
ii) User can Select the Variation Points (He can select what are the classes or attributes.. etc., needed),
iii) After Selecting that My program should able to Write it back to the same model (Remove the UNCHECKED classes)
iv) Such that User can able to get the output which is derived from this variations.

For eg.,
i) If User has a model with some three classes such as X,Y,Z. (My Program should read that model with all three classes X,Y,Z)
ii) It Should allow the user to select the variations (If user selects X & Z only two classes if he dont need Y).
iii) Then my Program should write it back to model (final model will going give the output of the two classes 'X & Z' only; not 'Y')

Sources:
1) EMF, Eclipse Modeling Frame Work, 2nd Edition
2) Eclipse Forums, Google...
3) Eclipse Indigo Help..


QUESTIONS:
1) How/from where i want to start ?
2) What are the steps i want to take ?
3) though i was newbie i got structed up some where itseems, a small idea from experienced people will be more valuable for me !!

Thanks
--
Sriram R.

Re: Urgent : How to Read the Ecore Model [message #872964 is a reply to message #872935] Thu, 17 May 2012 03:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Sriram,

Comments below.

On 17/05/2012 8:07 AM, Sriram Ramanujam wrote:
> Thanks for your reply Ed Merks !!
> Let me explain it clearly...
>
> After writing Annotated Java code in Empty EMF Project by adding a
> Package "com.eclipse.epo2" and the corresponding classes to them. I
> generated the Model, by RIGHT Clicking the generated "epo2.genmodel"
> and with "generate all" Option.
>
> Now when you look at the Package explorer we will have four folders
> which look like
> com.eclipse.epo2 (3 Packages )
> com.eclipse.epo2.edit ( 1 package )
> com.eclipse.epo2.editor ( 1 Package)
> com.eclipse.epo2.tests (1 package)
Yes, that's the basic generator-produced structure.
> till this point i was fine.
> QUESTION 1:
>
> Now i just want know in which package i want to add this above
> mentioned code(in previous post) ?
That's up to you, and it depends on how you want your clients or your
downstream code to use it.
> Whether i want to add it to the .edit project (or) .editor project
> (or) .tests project or else with the model (i.e., com.eclipse.epo2) ??
I don't see how I can answer that for you. You can put it where you
like, where it makes sense for you. You can add hand written things to
any interface or any class, even to hand generated ones...
> QUESTION 2:
> If i want to write in any one of the package mentioned above..
> then
> in which package ?
> whether i want to create some new classes ?
> Or else i want to over ride in some of the existing classes ?
There's no context for me to give advice. In Ecore itself, we had wrote
the EcoreUtil class with many useful utilities for working with Ecore
models and for working with EObject, Resource, and ResourceSet... We
also added utilities to the generated classes, e.g.,
EClass.getEStructuralFeature(String) for finding a feature with a given
name...
> Thanks --
> Sriram R
>
Re: Urgent : How to Read the Ecore Model [message #872969 is a reply to message #872941] Thu, 17 May 2012 03:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Sriram,

Commetns below.

On 17/05/2012 8:28 AM, Sriram Ramanujam wrote:
> Rather confusing you let me share my Project Objective :
>
> Problem Statement:
> I just need to Create Eclipse Plugin which should Read and Write the
> Ecore model programmatically.
> From User point of View these are the following things that the PLUG
> IN should deliver:
> i) User need to Create/Import the Ecore Model
> ii) User can Select the Variation Points (He can select what are
> the classes or attributes.. etc., needed), iii) After Selecting
> that My program should able to Write it back to the same model (Remove
> the UNCHECKED classes)
> iv) Such that User can able to get the output which is derived from
> this variations.
It sounds like you need a decorator model to record this information and
write it to a separate resource (much like the GenModel in a *.genmodel
resource is a decorator for an Ecore model and has references back to
the original Ecore model).
>
> For eg., i) If User has a model with some three classes such as
> X,Y,Z. (My Program should read that model with all three classes X,Y,Z)
> ii) It Should allow the user to select the variations (If user
> selects X & Z only two classes if he dont need Y).
> iii) Then my Program should write it back to model (final model
> will going give the output of the two classes 'X & Z' only; not 'Y')
You don't really want to overwrite the original model you read in do
you? If so, you'd just edit the instances you read in and use
Resource.save to write it back out.
>
> Sources:
> 1) EMF, Eclipse Modeling Frame Work, 2nd Edition
> 2) Eclipse Forums, Google...
> 3) Eclipse Indigo Help..
>
>
> QUESTIONS: 1) How/from where i want to start ?
> 2) What are the steps i want to take ? 3) though i was newbie i got
> structed up some where itseems, a small idea from experienced people
> will be more valuable for me !!
> Thanks
> --
> Sriram R.
>
Re: Urgent : How to Read the Ecore Model [message #874660 is a reply to message #872969] Mon, 21 May 2012 06:25 Go to previous messageGo to next message
Sriram Ramanujam is currently offline Sriram Ramanujam
Messages: 7
Registered: May 2012
Junior Member
Ya you are correct... I Want to make a decorator model to record this information and
write it to a separate resource.. I Dont want to overwrite on that, creating a new one will be fine ....

How can i do that ?
Can i get any code snippet and detailed step by step procedures are available ?


Thanks
--
Sriram R.
Re: Urgent : How to Read the Ecore Model [message #874776 is a reply to message #874660] Mon, 21 May 2012 10:25 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Sriram,

No, there's no time for me to give detailed step-by-step procedures for
each person who needs help. You need to demonstrate some
self-sufficiency and ask more specific questions.


On 21/05/2012 12:25 PM, Sriram Ramanujam wrote:
> Ya you are correct... I Want to make a decorator model to record this
> information and write it to a separate resource.. I Dont want to
> overwrite on that, creating a new one will be fine ....
> How can i do that ? Can i get any code snippet and detailed step by
> step procedures are available ?
>
>
> Thanks --
> Sriram R.
Previous Topic:[JET] "translation" code
Next Topic:Get namespaces used in xml file
Goto Forum:
  


Current Time: Sun Aug 31 04:28:21 EDT 2014

Powered by FUDForum. Page generated in 0.02702 seconds