Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to import existing metamodel (UML)?
How to import existing metamodel (UML)? [message #58542] Tue, 14 July 2009 14:33 Go to next message
Ilyas Keser is currently offline Ilyas KeserFriend
Messages: 85
Registered: July 2009
Member
- Created a new Xtext Project.

- Modified the grammar:

grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/uml2/3.0.0/UML" as umlMM

generate myDsl "http://www.xtext.org/example/MyDsl"

Model :
(imports+=Import)*
(elements+=MyClassRef)*;

Import :
'import' importURI=STRING;

MyClassRef:
'classRef' referencedClass=[umlMM::Class];

- Copied Ecore.ecore, UML.ecore and UML.genmodel to
.../src/org/xtext/example

- Modified the workflow file:

<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
<platformUri value="${runtimeProject}/.." />
<registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
</bean>

...


<fragment class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment ">
<genModels
value=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "
/>
</fragment>


- added following dependency to mydsl project: org.eclipse.uml2.uml

- running the workflow is successful!

Are there additional steps to define cross references to UML metamodel
elements? Eclipse reports following errors:

- src-gen/org/xtext/example/myDsl/MyClassRef.java
uml.Class getReferencedClass(); --> uml cannot be resolved to a
type

- src-gen/org/xtext/example/myDsl/impl/MyClassRefImpl.java
- The type MyClassRefImpl must implement the inherited abstract method
MyClassRef.setReferencedClass(Class)
- The type MyClassRefImpl must implement the inherited abstract method
MyClassRef.getReferencedClass()

- src-gen/org/xtext/example/myDsl/impl/MyDslPackageImpl.java
The import uml.UmlPackage cannot be resolved


Thanks
Ilyas
Re: How to import existing metamodel (UML)? [message #58781 is a reply to message #58542] Wed, 15 July 2009 08:25 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ilyas,

please find my answer inline.

Am 14.07.2009 16:33 Uhr, schrieb Ilyas Keser:
>
> - Created a new Xtext Project.
>
> - Modified the grammar:
>
> grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals
>
> import "http://www.eclipse.org/uml2/3.0.0/UML" as umlMM
>
> generate myDsl "http://www.xtext.org/example/MyDsl"
>
> Model :
> (imports+=Import)*
> (elements+=MyClassRef)*;
>
> Import :
> 'import' importURI=STRING;
>
> MyClassRef: 'classRef' referencedClass=[umlMM::Class];
> - Copied Ecore.ecore, UML.ecore and UML.genmodel to

You'ld have to copy Ecore.genmodel as well

> .../src/org/xtext/example
>
> - Modified the workflow file:
>
> <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
> <platformUri value="${runtimeProject}/.." />
> <registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
> </bean>
>

Please try something like this intead:

<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
platformUri="${runtimeProject}/..">
<registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
<registerGeneratedEPackage
value="org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage "/>
<uriMap
from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.genmodel "/>
<uriMap
from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.ecore "/>
</bean>

>
>
> <fragment class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment ">
> <genModels
> value=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "
> />
> </fragment>
>
>
> - added following dependency to mydsl project: org.eclipse.uml2.uml
>

Add the following dependency, too:

org.eclipse.uml2.codegen.ecore

> - running the workflow is successful!

Strange enough, I've had tons of exception without the above mentioned
modifications.

>
> Are there additional steps to define cross references to UML metamodel
> elements? Eclipse reports following errors:
>
> - src-gen/org/xtext/example/myDsl/MyClassRef.java uml.Class
> getReferencedClass(); --> uml cannot be resolved to a type
>
> - src-gen/org/xtext/example/myDsl/impl/MyClassRefImpl.java
> - The type MyClassRefImpl must implement the inherited abstract method
> MyClassRef.setReferencedClass(Class)
> - The type MyClassRefImpl must implement the inherited abstract method
> MyClassRef.getReferencedClass()
>
> - src-gen/org/xtext/example/myDsl/impl/MyDslPackageImpl.java
> The import uml.UmlPackage cannot be resolved
>
>
> Thanks
> Ilyas
>

Please note that it is propably better to not copy the *.ecore and
*.genmodel files, but refer to them in the jar files instead. EMF can
handle archive uris pretty well. However, the mapping information has to
be provided in both cases.

Hope that helps,
Sebastian
Re: How to import existing metamodel (UML)? [message #59027 is a reply to message #58781] Wed, 15 July 2009 09:55 Go to previous messageGo to next message
Ilyas Keser is currently offline Ilyas KeserFriend
Messages: 85
Registered: July 2009
Member
Hi Sebastian,

after running the workflow the generated sources have 3 errors:

file: src-gen/org/xtext/example/myDsl/MyClassRef.java:
error: uml.Class getReferencedClass(); --> uml cannot be resolved to a type

file: src-gen/org/xtext/example/myDsl/impl/MyClassRefImpl.java
error: The type MyClassRefImpl must implement the inherited abstract
method MyClassRef.setReferencedClass(Class)
error: The type MyClassRefImpl must implement the inherited abstract
method MyClassRef.getReferencedClass()

file: src-gen/org/xtext/example/myDsl/impl/MyDslPackageImpl.java
error: import uml.UmlPackage; --> The import uml.UmlPackage cannot be
resolved
error: import ecore.EcorePackage; --> The import ecore cannot be resolved
Here, it tries to find the packages uml.UmlPackage and ecore.EcorePackage.
The interface uml.UmlPackage is in plugin org.eclipse.uml2.uml and its
correct name is UMLPackage and not UmlPackage.

Should I try to generate the uml package with UML.genmodel?

I also tried to use archive uris for UML.genmodel and UML.ecore:

<uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "/>
<uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.ecore "/>


Thanks
ILyas
Re: How to import existing metamodel (UML)? [message #59075 is a reply to message #59027] Wed, 15 July 2009 11:34 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ilyas,

there seem to be still some issues with your project setup.

Please attach your workflow and your manifest. Thanks.

Regards,
Sebastian

Am 15.07.2009 11:55 Uhr, schrieb Ilyas Keser:
> Hi Sebastian,
>
> after running the workflow the generated sources have 3 errors:
>
> file: src-gen/org/xtext/example/myDsl/MyClassRef.java:
> error: uml.Class getReferencedClass(); --> uml cannot be resolved to a type
>
> file: src-gen/org/xtext/example/myDsl/impl/MyClassRefImpl.java
> error: The type MyClassRefImpl must implement the inherited abstract
> method MyClassRef.setReferencedClass(Class)
> error: The type MyClassRefImpl must implement the inherited abstract
> method MyClassRef.getReferencedClass()
>
> file: src-gen/org/xtext/example/myDsl/impl/MyDslPackageImpl.java
> error: import uml.UmlPackage; --> The import uml.UmlPackage cannot be
> resolved
> error: import ecore.EcorePackage; --> The import ecore cannot be resolved
> Here, it tries to find the packages uml.UmlPackage and
> ecore.EcorePackage. The interface uml.UmlPackage is in plugin
> org.eclipse.uml2.uml and its correct name is UMLPackage and not UmlPackage.
> Should I try to generate the uml package with UML.genmodel?
>
> I also tried to use archive uris for UML.genmodel and UML.ecore:
>
> <uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "/>
>
> <uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.ecore "/>
>
>
>
> Thanks
> ILyas
>
Re: How to import existing metamodel (UML)? [message #59100 is a reply to message #59075] Wed, 15 July 2009 12:01 Go to previous messageGo to next message
Ilyas Keser is currently offline Ilyas KeserFriend
Messages: 85
Registered: July 2009
Member
Hi Sebastian,

thanks for your help.

Here, my workflow:

<workflow>
<property file="org/xtext/example/GenerateMyDsl.properties"/>

<property name="runtimeProject" value="../${projectName}"/>

<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
platformUri="${runtimeProject}/..">
<registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
<!--
<uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "/>
<uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.ecore "/>
-->
<registerGeneratedEPackage
value="org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage "/>
<uriMap
from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.genmodel "/>
<uriMap from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore "
to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.ecore "/>
</bean>

<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner"
directory="${runtimeProject}/src-gen"/>
<component class="org.eclipse.emf.mwe.utils.DirectoryCleaner"
directory="${runtimeProject}.ui/src-gen"/>

<component class="org.eclipse.xtext.generator.Generator">
<pathRtProject value="${runtimeProject}"/>
<pathUiProject value="${runtimeProject}.ui"/>
<projectNameRt value="${projectName}"/>
<projectNameUi value="${projectName}.ui"/>

<language uri="${grammarURI}" fileExtensions="${file.extensions}">
<!-- Java API to access grammar elements (required by several other
fragments) -->
<fragment
class=" org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragm ent "/>

<!-- generates Java API for the generated EPackages -->
<fragment
class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment ">
<genModels
value=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "
/>
</fragment>

<!-- the serialization component -->
<fragment
class=" org.eclipse.xtext.generator.parseTreeConstructor.ParseTreeCo nstructorFragment "/>

<!-- a custom ResourceFactory for use with EMF -->
<fragment
class=" org.eclipse.xtext.generator.resourceFactory.ResourceFactoryF ragment "
fileExtensions="${file.extensions}"/>

<!-- the following fragment tries to use the Antlr Generator fragment
which can be installed via update manager from
http://download.itemis.com/updates -->
<fragment class="org.eclipse.xtext.generator.AntlrDelegatingFragment" />

<!-- If you don't want to use the Antlr fragment for some reason,
remove the antlr fragment and uncomment the packrat parser fragment below.
<fragment
class="org.eclipse.xtext.generator.parser.PackratParserFragment "/>
-->


<!-- java-based API for validation -->
<fragment
class=" org.eclipse.xtext.generator.validation.JavaValidatorFragment ">
<composedCheck
value="org.eclipse.xtext.validation.ImportUriValidator"/>
</fragment>


<!-- scoping API -->
<fragment
class="org.eclipse.xtext.generator.scoping.JavaScopingFragment "/>

<!-- formatter API -->
<fragment
class="org.eclipse.xtext.generator.formatting.FormatterFragment "/>

<!-- labeling API -->
<fragment
class=" org.eclipse.xtext.ui.generator.labeling.LabelProviderFragmen t "/>

<!-- outline API -->
<fragment
class="org.eclipse.xtext.ui.generator.outline.TransformerFragment "/>
<fragment
class=" org.eclipse.xtext.ui.generator.outline.OutlineNodeAdapterFac toryFragment "/>


<!-- java-based API for content assistance -->
<fragment
class=" org.eclipse.xtext.ui.generator.contentAssist.JavaBasedConten tAssistFragment "/>
<!-- the following fragment tries to use the Antlr based content assist
fragment which can be downloaded from http://www.itemis.com
and will be ignored if it's not available. -->
<fragment
class="org.eclipse.xtext.generator.DelegatingGeneratorFragment "
delegate="de.itemis.xtext.antlr.XtextAntlrUiGeneratorFragment "
message="You are generating without ANTLR. It is highly recommended to
download and use the plugin 'de.itemis.xtext.antlr' \n\t using the update
site http://download.itemis.com/updates/milestones.">
</fragment>
<!-- <fragment
class="de.itemis.xtext.antlr.XtextAntlrUiGeneratorFragment"/ > -->

</language>
</component>
</workflow>


Manifest of org.xtext.example.mydsl


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.xtext.example.mydsl
Bundle-Vendor: My Company
Bundle-Version: 1.0.0
Bundle-SymbolicName: org.xtext.example.mydsl; singleton:=true
Eclipse-RegisterBuddy: org.eclipse.xtext.log4j
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.xtext,
org.eclipse.xtext.generator;resolution:=optional,
de.itemis.xtext.antlr;resolution:=optional,
org.apache.commons.logging;resolution:=optional,
org.eclipse.emf.codegen.ecore;resolution:=optional,
org.eclipse.xtext.log4j;resolution:=optional,
org.eclipse.emf.mwe.utils;resolution:=optional,
org.eclipse.emf.mwe.core;resolution:=optional,
com.ibm.icu;resolution:=optional,
org.eclipse.xtext.xtend;resolution:=optional,
org.eclipse.uml2.uml;bundle-version="3.0.0",
org.eclipse.uml2;bundle-version="3.0.0",
org.eclipse.xtext.util,
org.eclipse.emf.ecore,
org.eclipse.emf.common,
org.antlr.runtime,
org.eclipse.uml2.codegen.ecore;bundle-version="1.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.xtext.example,
org.xtext.example.services,
org.xtext.example.myDsl,
org.xtext.example.myDsl.impl,
org.xtext.example.myDsl.util,
org.xtext.example.parseTreeConstruction,
org.xtext.example.parser.antlr,
org.xtext.example.validation
Re: How to import existing metamodel (UML)? [message #59150 is a reply to message #59100] Wed, 15 July 2009 12:26 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Ilyas,

mwe and Manifest look fine, but the content of UML.ecore and
UML.genmodel seem to differ from mine.

I've taken the files from:
eclipse/plugins/org.eclipse.uml2.uml_3.0.0.v200905151700.jar

If you replace your somehow corrupt files with the ones from the jar,
everything should work like a charm.

Regards,
Sebastian

Am 15.07.2009 14:01 Uhr, schrieb Ilyas Keser:
> Hi Sebastian,
>
> thanks for your help.
>
> Here, my workflow:
>
> <workflow>
> <property file="org/xtext/example/GenerateMyDsl.properties"/>
>
> <property name="runtimeProject" value="../${projectName}"/>
>
> <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
> platformUri="${runtimeProject}/..">
> <registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
> <!--
> <uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.genmodel "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "/>
>
> <uriMap from="platform:/plugin/org.eclipse.uml2.uml/model/UML.ecore "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.ecore "/>
>
> -->
> <registerGeneratedEPackage
> value="org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage "/>
> <uriMap
> from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.genmodel "/>
>
> <uriMap from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.ecore "/>
>
> </bean>
>
> <component class="org.eclipse.emf.mwe.utils.DirectoryCleaner"
> directory="${runtimeProject}/src-gen"/>
> <component class="org.eclipse.emf.mwe.utils.DirectoryCleaner"
> directory="${runtimeProject}.ui/src-gen"/>
>
> <component class="org.eclipse.xtext.generator.Generator">
> <pathRtProject value="${runtimeProject}"/>
> <pathUiProject value="${runtimeProject}.ui"/>
> <projectNameRt value="${projectName}"/>
> <projectNameUi value="${projectName}.ui"/>
>
> <language uri="${grammarURI}" fileExtensions="${file.extensions}">
> <!-- Java API to access grammar elements (required by several other
> fragments) -->
> <fragment
> class=" org.eclipse.xtext.generator.grammarAccess.GrammarAccessFragm ent "/>
>
> <!-- generates Java API for the generated EPackages -->
> <fragment class="org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment ">
> <genModels
> value=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/UML.genmodel "
> />
> </fragment>
>
> <!-- the serialization component -->
> <fragment
> class=" org.eclipse.xtext.generator.parseTreeConstructor.ParseTreeCo nstructorFragment "/>
>
>
> <!-- a custom ResourceFactory for use with EMF -->
> <fragment
> class=" org.eclipse.xtext.generator.resourceFactory.ResourceFactoryF ragment "
> fileExtensions="${file.extensions}"/>
>
> <!-- the following fragment tries to use the Antlr Generator fragment
> which can be installed via update manager from
> http://download.itemis.com/updates -->
> <fragment class="org.eclipse.xtext.generator.AntlrDelegatingFragment" />
>
> <!-- If you don't want to use the Antlr fragment for some reason, remove
> the antlr fragment and uncomment the packrat parser fragment below.
> <fragment
> class="org.eclipse.xtext.generator.parser.PackratParserFragment "/>
> -->
>
>
> <!-- java-based API for validation -->
> <fragment
> class=" org.eclipse.xtext.generator.validation.JavaValidatorFragment ">
> <composedCheck value="org.eclipse.xtext.validation.ImportUriValidator"/>
> </fragment>
>
> <!-- scoping API -->
> <fragment class="org.eclipse.xtext.generator.scoping.JavaScopingFragment "/>
>
> <!-- formatter API -->
> <fragment
> class="org.eclipse.xtext.generator.formatting.FormatterFragment "/>
>
> <!-- labeling API -->
> <fragment
> class=" org.eclipse.xtext.ui.generator.labeling.LabelProviderFragmen t "/>
>
> <!-- outline API -->
> <fragment
> class="org.eclipse.xtext.ui.generator.outline.TransformerFragment "/>
> <fragment
> class=" org.eclipse.xtext.ui.generator.outline.OutlineNodeAdapterFac toryFragment "/>
>
>
>
> <!-- java-based API for content assistance -->
> <fragment
> class=" org.eclipse.xtext.ui.generator.contentAssist.JavaBasedConten tAssistFragment "/>
>
> <!-- the following fragment tries to use the Antlr based content assist
> fragment which can be downloaded from http://www.itemis.com and will be
> ignored if it's not available. -->
> <fragment
> class="org.eclipse.xtext.generator.DelegatingGeneratorFragment "
> delegate="de.itemis.xtext.antlr.XtextAntlrUiGeneratorFragment "
> message="You are generating without ANTLR. It is highly recommended to
> download and use the plugin 'de.itemis.xtext.antlr' \n\t using the
> update site http://download.itemis.com/updates/milestones.">
> </fragment>
> <!-- <fragment
> class="de.itemis.xtext.antlr.XtextAntlrUiGeneratorFragment"/ > -->
> </language>
> </component>
> </workflow>
>
>
> Manifest of org.xtext.example.mydsl
>
>
> Manifest-Version: 1.0
> Bundle-ManifestVersion: 2
> Bundle-Name: org.xtext.example.mydsl
> Bundle-Vendor: My Company
> Bundle-Version: 1.0.0
> Bundle-SymbolicName: org.xtext.example.mydsl; singleton:=true
> Eclipse-RegisterBuddy: org.eclipse.xtext.log4j
> Bundle-ActivationPolicy: lazy
> Require-Bundle: org.eclipse.xtext,
> org.eclipse.xtext.generator;resolution:=optional,
> de.itemis.xtext.antlr;resolution:=optional,
> org.apache.commons.logging;resolution:=optional,
> org.eclipse.emf.codegen.ecore;resolution:=optional,
> org.eclipse.xtext.log4j;resolution:=optional,
> org.eclipse.emf.mwe.utils;resolution:=optional,
> org.eclipse.emf.mwe.core;resolution:=optional,
> com.ibm.icu;resolution:=optional,
> org.eclipse.xtext.xtend;resolution:=optional,
> org.eclipse.uml2.uml;bundle-version="3.0.0",
> org.eclipse.uml2;bundle-version="3.0.0",
> org.eclipse.xtext.util,
> org.eclipse.emf.ecore,
> org.eclipse.emf.common,
> org.antlr.runtime,
> org.eclipse.uml2.codegen.ecore;bundle-version="1.5.0"
> Bundle-RequiredExecutionEnvironment: J2SE-1.5
> Export-Package: org.xtext.example,
> org.xtext.example.services,
> org.xtext.example.myDsl,
> org.xtext.example.myDsl.impl,
> org.xtext.example.myDsl.util,
> org.xtext.example.parseTreeConstruction,
> org.xtext.example.parser.antlr,
> org.xtext.example.validation
>
>
>
Re: How to import existing metamodel (UML)? [message #59174 is a reply to message #59150] Wed, 15 July 2009 12:45 Go to previous messageGo to next message
Ilyas Keser is currently offline Ilyas KeserFriend
Messages: 85
Registered: July 2009
Member
Thanks Sebastian. It works! I think I have taken the files from the same
plugin (yesterday). Maybe I changed one of them unconsciously. Strange.

But it works.
Thanks again!

ILyas
Re: How to import existing metamodel (UML)? [message #59567 is a reply to message #58781] Thu, 16 July 2009 18:31 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
On 2009-07-15 01:25:44 -0700, Sebastian Zarnekow
<Sebastian.Zarnekow@itemis.de> said:
> Please try something like this intead:
>
> <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
> platformUri="${runtimeProject}/..">
> <registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
> <registerGeneratedEPackage
> value="org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage "/>
> <uriMap
> from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.genmodel "/>
<uriMap
>
> from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore "
> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.ecore "/>
</bean>

Sebastian,

Can
>
you explain what is accomplished by the last two lines? Is this an
issue for UML only? I haven't found any problem w/ not using them for
my ecore imports (but perhaps that explains some linking issues I've
been having) and the workflow builds just fine.

As you mention below, I can't think of why you would want or need to
keep the imported ecore models in your calling project...?
Re: How to import existing metamodel (UML)? [message #59670 is a reply to message #59567] Thu, 16 July 2009 20:25 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Miles,

please find my answer below.

Am 16.07.2009 20:31 Uhr, schrieb Miles Parker:
> On 2009-07-15 01:25:44 -0700, Sebastian Zarnekow
> <Sebastian.Zarnekow@itemis.de> said:
>> Please try something like this intead:
>>
>> <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup"
>> platformUri="${runtimeProject}/..">
>> <registerGeneratedEPackage value="org.eclipse.uml2.uml.UMLPackage"/>
>> <registerGeneratedEPackage
>> value="org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage "/>
>> <uriMap
>> from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel "
>> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.genmodel "/>
>>
> <uriMap
>>
>> from="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore "
>> to=" platform:/resource/org.xtext.example.mydsl/src/org/xtext/exa mple/Ecore.ecore "/>
>>
> </bean>
>
> Sebastian,
>
> Can
>
> you explain what is accomplished by the last two lines? Is this an issue
> for UML only? I haven't found any problem w/ not using them for my ecore
> imports (but perhaps that explains some linking issues I've been having)
> and the workflow builds just fine.
>
The UML genmodel refers to other models via platform:/plugin uris. These
cannot be resolved in plain vanilla java runtimes, as they rely on OSGi
und extension point mechanisms. EMF allows to map arbitrary uri to other
uris. This is what this two lines do. When ommitted, you may end up with
obscure NPEs due to unresolved EMF proxies.

> As you mention below, I can't think of why you would want or need to
> keep the imported ecore models in your calling project...?
>
That's right. I'ld prefer archive uris and refer to the contents of the
uml jars directly. However, I do not know the root directory of your
Eclipse installation and therefore cannot provide a valid mwe setup. To
make it as easy as possible, I suggested to copy the existing model
files into the project and refer to them via platform:/resource uri.

If anything remains unclear please don't hesitate to ask further questions.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: How to import existing metamodel (UML)? [message #59789 is a reply to message #59670] Thu, 16 July 2009 23:21 Go to previous messageGo to next message
Miles Parker is currently offline Miles ParkerFriend
Messages: 1341
Registered: July 2009
Senior Member
On 2009-07-16 13:25:48 -0700, Sebastian Zarnekow
<Sebastian.Zarnekow@itemis.de> said:
>>
>> you explain what is accomplished by the last two lines? Is this an issue
>> for UML only? I haven't found any problem w/ not using them for my ecore
>> imports (but perhaps that explains some linking issues I've been having)
>> and the workflow builds just fine.
>>
> The UML genmodel refers to other models via platform:/plugin uris.
> These cannot be resolved in plain vanilla java runtimes, as they rely
> on OSGi und extension point mechanisms. EMF allows to map arbitrary uri
> to other uris. This is what this two lines do. When ommitted, you may
> end up with obscure NPEs due to unresolved EMF proxies.

Thanks Sebastian, I'm not the original poster, just trying to get a
handle on the logic there, and I see that this doesn't have anything to
do with my usage. So sorry to butt in. But perhaps this is a good
argument for the practice of using web URLs for refererences and then
mapping them back to platform:/plugin within the eclipse environment..
Re: How to import existing metamodel (UML)? [message #636247 is a reply to message #59789] Fri, 29 October 2010 20:34 Go to previous messageGo to next message
Roque Pinel is currently offline Roque PinelFriend
Messages: 14
Registered: October 2010
Location: Rio de Janeiro
Junior Member
Hi guys,

I'm trying to import UML models use this same approach. I also found some related articles:

http://chilifreak.wordpress.com/2009/11/06/xtext-using-uml-m odels/
http://www.virage-it.be/2010/05/the-definition-and-the-imple mentation-of-the-software-analysis-dsl-using-xtext/

But the reference to the model doesn't seem to be working.

I'm using the UML.ecore and UML.genmodel from the "org.eclipse.uml2.uml_3.1.0.v201006071150.jar". And using the Ecore.ecore and Ecore.genmodel from the "org.eclipse.emf.ecore_2.6.0.v20100614-1136.jar".

I'm also using the Eclipse (Helios) distribution with Xtext 1.0.1, from itemis.

My workflow.
module org.xtext.example.mydsl.MyDsl

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/org/xtext/example/mydsl/MyDsl.xtext"
var file.extensions = "mydsl"
var projectName = "org.xtext.example.mydsl"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
		platformUri = "${runtimeProject}/.."

		registerGeneratedEPackage = "org.eclipse.uml2.uml.UMLPackage"
		registerGeneratedEPackage = "org.eclipse.uml2.codegen.ecore.genmodel.GenModelPackage"

		uriMap = {
			from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore"
			to = "platform:/resource/org.xtext.example.mydsl/model/Ecore.ecore"			
		}
		uriMap = {
			from = "platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel"
			to = "platform:/resource/org.xtext.example.mydsl/model/Ecore.genmodel"			
		}
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}/src-gen"
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}.ui/src-gen"
	}

	component = Generator {
		pathRtProject = runtimeProject
		pathUiProject = "${runtimeProject}.ui"
		projectNameRt = projectName
		projectNameUi = "${projectName}.ui"
		language = {
			uri = grammarURI
			fileExtensions = file.extensions

			// Java API to access grammar elements (required by several other fragments)
			fragment = grammarAccess.GrammarAccessFragment {}

			// generates Java API for the generated EPackages 
			fragment = ecore.EcoreGeneratorFragment {
				// referencedGenModels = "uri to genmodel, uri to next genmodel"
				genModels = "platform:/resource/org.xtext.example.mydsl/model/UML.genmodel"
			}

			// the serialization component
			fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

			// a custom ResourceFactory for use with EMF 
			fragment = resourceFactory.ResourceFactoryFragment {
				fileExtensions = file.extensions
			}

			// The antlr parser generator fragment.
			fragment = parser.antlr.XtextAntlrGeneratorFragment {
			//  options = {
			//		backtrack = true
			//	}
			}

			// java-based API for validation 
			fragment = validation.JavaValidatorFragment {
				composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
				composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
				// registerForImportedPackages = true
			}

			// scoping and exporting API
			// fragment = scoping.ImportURIScopingFragment {}
			// fragment = exporting.SimpleNamesFragment {}

			// scoping and exporting API 
			fragment = scoping.ImportNamespacesScopingFragment {}
			fragment = exporting.QualifiedNamesFragment {}
			fragment = builder.BuilderIntegrationFragment {}

			// formatter API 
			fragment = formatting.FormatterFragment {}

			// labeling API 
			fragment = labeling.LabelProviderFragment {}

			// outline API 
			fragment = outline.TransformerFragment {}
			fragment = outline.OutlineNodeAdapterFactoryFragment {}
			fragment = outline.QuickOutlineFragment {}

			// quickfix API 
			fragment = quickfix.QuickfixProviderFragment {}

			// content assist API  
			fragment = contentAssist.JavaBasedContentAssistFragment {}

			// generates a more lightweight Antlr parser and lexer tailored for content assist  
			fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}

			// project wizard (optional) 
			// fragment = projectWizard.SimpleProjectWizardFragment {
			// 		generatorProjectName = "${projectName}.generator" 
			//		modelFileExtension = file.extensions
			// }
		}
	}
}


My manifest.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.xtext.example.mydsl
Bundle-Vendor: My Company
Bundle-Version: 1.0.0
Bundle-SymbolicName: org.xtext.example.mydsl; singleton:=true
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.xtext,
 org.eclipse.xtext.generator;resolution:=optional,
 org.apache.commons.logging;resolution:=optional,
 org.eclipse.emf.codegen.ecore;resolution:=optional,
 org.eclipse.emf.mwe.utils;resolution:=optional,
 org.eclipse.emf.mwe2.launch;resolution:=optional,
 com.ibm.icu;resolution:=optional,
 org.eclipse.xtext.xtend;resolution:=optional,
 org.eclipse.xtext.util,
 org.eclipse.emf.ecore,
 org.eclipse.emf.common,
 org.antlr.runtime,
 org.eclipse.uml2.codegen.ecore;bundle-version="1.6.0",
 org.eclipse.uml2.uml;bundle-version="3.1.0"
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.xtext.example.mydsl,
 org.xtext.example.mydsl.services,
 org.xtext.example.mydsl.myDsl,
 org.xtext.example.mydsl.myDsl.impl,
 org.xtext.example.mydsl.myDsl.util,
 org.xtext.example.mydsl.parseTreeConstruction,
 org.xtext.example.mydsl.parser.antlr,
 org.xtext.example.mydsl.parser.antlr.internal,
 org.xtext.example.mydsl.validation


My grammar.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import 'http://www.eclipse.org/uml2/3.0.0/UML' as umlMM

Model :
	(imports+=Import)*
	(rules+=Rule)*;
	
Import :
	'import' importURI=STRING;
	
Rule:
	'references' umlClass=[umlMM::Class];


Thanks for any help.
Re: How to import existing metamodel (UML)? [message #636256 is a reply to message #636247] Fri, 29 October 2010 21:36 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
With Xtext 1.0.0 you seem to need IResourceProviders for UML, which are not part of the standard distribution. I did some basic implementation which I will blog next week.
Re: How to import existing metamodel (UML)? [message #636379 is a reply to message #636256] Sun, 31 October 2010 21:42 Go to previous message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Here it is:
http://5ise.quanxinquanyi.de/2010/10/31/xtext-1-0-0-and-uml- xpand-on-top/
Previous Topic:How to define a rule for a version?
Next Topic:Defining datatypes (terminals)
Goto Forum:
  


Current Time: Thu Mar 28 13:07:33 GMT 2024

Powered by FUDForum. Page generated in 0.03020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top