How to create attributes using EMF API ? [message #757936] |
Wed, 16 November 2011 18:26 |
Eclipse User |
|
|
|
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 467 times)
|
|
|
|
|
Re: How to create attributes using EMF API ? [message #757939 is a reply to message #757938] |
Thu, 17 November 2011 17:14 |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.03039 seconds