Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » How to create attributes using EMF API ?
How to create attributes using EMF API ? [message #757936] Wed, 16 November 2011 18:26 Go to next message
Eclipse UserFriend
I have an ecore model of a maven Pom (attached).

I build instances of the model using the API, usually without issue.

I need to create:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugins>
<build>

The EMF model has a number of Configuration types, each with a getAny()
method returning a FeatureMap.

How can I add the <source>1.6</source> and <target>1.6</target> Features ?



ala:
Model model = PomFactory.eINSTANCE.createModel();
model.setArtifactId(module.getName());
model.setGroupId("com.ebay." + module.getPath());
model.setName(module.getName());
model.setPackaging("jar");
model.setVersion("1.0.0");

......

Build build = PomFactory.eINSTANCE.createBuild();
model.setBuild(build);
PluginsType2 plugins = PomFactory.eINSTANCE.createPluginsType2();
build.setPlugins(plugins);
Plugin plugin = PomFactory.eINSTANCE.createPlugin();
plugins.getPlugin().add(plugin);

plugin.setGroupId("org.apache.maven.plugins");
plugin.setArtifactId("maven-compiler-plugin");
ConfigurationType2 configurationType2 = plugin.getConfiguration();
if (null == configurationType2) {
configurationType2 =
PomFactory.eINSTANCE.createConfigurationType2();
plugin.setConfiguration(configurationType2);
}

FeatureMap featureMap = configurationType2.getAny();

EAttribute sourceAttribute =
PomPackage.eINSTANCE.getConfigurationType2_Any();
sourceAttribute.setName("source");

featureMap.add(sourceAttribute, <?????>); // <-- is this even
close to being right ?

I'm not sure what types I need to create and add to the featureMap, or
even if I'm on the right track.

Thanks!!!!!


Roy
  • Attachment: pom.ecore
    (Size: 211.77KB, Downloaded 449 times)
Re: How to create attributes using EMF API ? [message #757937 is a reply to message #757936] Thu, 17 November 2011 07:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Roy,

Please use eclipse.tools.emf for EMF questions.

More comments below.

On 16/11/2011 7:26 PM, Roy Benjamin wrote:
> I have an ecore model of a maven Pom (attached).
>
> I build instances of the model using the API, usually without issue.
>
> I need to create:
>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
> <configuration>
> <source>1.6</source>
> <target>1.6</target>
> </configuration>
> </plugin>
> <plugins>
> <build>
>
> The EMF model has a number of Configuration types, each with a
> getAny() method returning a FeatureMap.
>
> How can I add the <source>1.6</source> and <target>1.6</target>
> Features ?
Are there global elements declarations for this?

This article should be helpful to answer your question:
http://www.theserverside.com/news/1364302/Binding-XML-to-Java
>
>
>
> ala:
> Model model = PomFactory.eINSTANCE.createModel();
> model.setArtifactId(module.getName());
> model.setGroupId("com.ebay." + module.getPath());
> model.setName(module.getName());
> model.setPackaging("jar");
> model.setVersion("1.0.0");
>
> .....
>
> Build build = PomFactory.eINSTANCE.createBuild();
> model.setBuild(build);
> PluginsType2 plugins = PomFactory.eINSTANCE.createPluginsType2();
> build.setPlugins(plugins);
> Plugin plugin = PomFactory.eINSTANCE.createPlugin();
> plugins.getPlugin().add(plugin);
>
> plugin.setGroupId("org.apache.maven.plugins");
> plugin.setArtifactId("maven-compiler-plugin");
> ConfigurationType2 configurationType2 = plugin.getConfiguration();
> if (null == configurationType2) {
> configurationType2 =
> PomFactory.eINSTANCE.createConfigurationType2();
> plugin.setConfiguration(configurationType2);
> }
>
> FeatureMap featureMap = configurationType2.getAny();
>
> EAttribute sourceAttribute =
> PomPackage.eINSTANCE.getConfigurationType2_Any();
> sourceAttribute.setName("source");
>
> featureMap.add(sourceAttribute, <?????>); // <-- is this even
> close to being right ?
No. The first argument will generally be something like
PomPackage.Literals.DOCUMENT_ROOT__<FOO>, where FOO is probably SOURCE
because there will be a global element called source.
>
> I'm not sure what types I need to create and add to the featureMap, or
> even if I'm on the right track.
>
> Thanks!!!!!
>
>
> Roy
>
>
>
>
>
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create attributes using EMF API ? [message #757938 is a reply to message #757936] Thu, 17 November 2011 14:39 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

Hello Benjamin,

The good practive would be that your pom.ecore contained the right
entries for these attribute so that you could manipulate then using
setSource or PomPackage.Literals.CONFIGURATION_SOURCE EAttribute.

If you cannot modify your .ecore to support this, then you are in a
tricky situation. I found a way to leverage EFeatureMaps to support
3rd-party extensions in your models. this is the issue described here:
http://www.eclipsecon.org/2012/sessions/hack-emf-models-support-vendor-specific-attributes

Is this your use-case?
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: How to create attributes using EMF API ? [message #757939 is a reply to message #757938] Thu, 17 November 2011 17:14 Go to previous message
Eclipse UserFriend
Hi Ed,

Possibly. I generated the ecore model from the pom xsd so I'd prefer
not to modify it... but it had occurred to me to do so. My guess is
this issue could arise from other xsd to ecore use cases.

Thanks!

Roy



On 11/17/2011 6:39 AM, Mickael Istria wrote:
> Hello Benjamin,
>
> The good practive would be that your pom.ecore contained the right
> entries for these attribute so that you could manipulate then using
> setSource or PomPackage.Literals.CONFIGURATION_SOURCE EAttribute.
>
> If you cannot modify your .ecore to support this, then you are in a
> tricky situation. I found a way to leverage EFeatureMaps to support
> 3rd-party extensions in your models. this is the issue described here:
> http://www.eclipsecon.org/2012/sessions/hack-emf-models-support-vendor-specific-attributes
>
>
> Is this your use-case?
Previous Topic:EclipseCon North America
Next Topic:Apply UML Profile to a model in an automatically way
Goto Forum:
  


Current Time: Wed Apr 24 20:12:10 GMT 2024

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

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

Back to the top