Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Assigning to a xs:any/EFeatureMapEntry with ATL(How can I relate an EClass to an EAttribute of type EFeatureMapEntry)
Assigning to a xs:any/EFeatureMapEntry with ATL [message #900943] Thu, 09 August 2012 07:46 Go to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
I cannot seem to figure out how I can assign an EObject to an EAttribute of type EFeatureMapEntry. The EFeatureMapEntry type is because my MetaModel came from an XSD with a type of xs:any

For example if I have a simplified Ecore as follows:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="w3schools"
nsURI="http://www.w3schools.com" nsPrefix="w3schools">
<eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=""/>
<details key="kind" value="mixed"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementWildcard"/>
<details key="name" value=":mixed"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xmlns:prefix"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xsi:schemaLocation"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="person" upperBound="-2"
eType="#//PersonType" volatile="true" transient="true" derived="true" containment="true"
resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="person"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="PersonType">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="person_._type"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="firstname" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="firstname"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="lastname" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//String">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="lastname"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="any" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementWildcard"/>
<details key="wildcards" value="##any"/>
<details key="name" value=":2"/>
<details key="processing" value="strict"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

How can I assign a person to the any EAttribute? Upon assignment I get org.eclipse.m2m.atl.engine.emfvm.VMException: PersonTypeImpl incompatible with org.eclipse.emf.ecore.util.FeatureMap$Entry

The ATL snippet is:

t : OUT!PersonType
(
firstname <- 'x',
lastname = 'y',
any <- OUT!PersonType.newInstance()
)

I also tried some patterns like with the XMLTypeDocumentRoot but to no avail.

Any ideas?

Regards,
Ronan
Re: Assigning to a xs:any/EFeatureMapEntry with ATL [message #900951 is a reply to message #900943] Thu, 09 August 2012 08:04 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
The easiest is to add an EOperation in your metamodel and use it in ATL.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void addPerson(PersonType person) {
	getAny().add(W3schoolsPackage.Literals.PERSON_TYPE__ANY, person);
}


and then
t : OUT!PersonType
(
firstname <- 'x',
lastname = 'y'
)
do{
t.addPerson(OUT!PersonType.newInstance());
}

[Updated on: Thu, 09 August 2012 08:05]

Report message to a moderator

Re: Assigning to a xs:any/EFeatureMapEntry with ATL [message #901013 is a reply to message #900951] Thu, 09 August 2012 12:00 Go to previous messageGo to next message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi Sylvain,
Thanks, that makes sense. However, I get the same error!

org.eclipse.m2m.atl.engine.emfvm.VMException: Exception during invocation of operation addPerson on w3schools.impl.PersonTypeImpl@36263626 (firstname: s, lastname: b, any: [])
Java Stack:
org.eclipse.m2m.atl.engine.emfvm.VMException: Exception during invocation of operation addPerson on w3schools.impl.PersonTypeImpl@36263626 (firstname: s, lastname: b, any: [])
at org.eclipse.m2m.atl.engine.emfvm.adapter.EMFModelAdapter.invoke(EMFModelAdapter.java:734)
at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:425)
at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:388)
at org.eclipse.m2m.atl.engine.emfvm.ASMOperation.exec(ASMOperation.java:388)
at org.eclipse.m2m.atl.engine.emfvm.ASM.run(ASM.java:208)
at org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMLauncher.internalLaunch(EMFVMLauncher.java:170)
at org.eclipse.m2m.atl.engine.emfvm.launch.EMFVMUILauncher.launch(EMFVMUILauncher.java:46)
at org.eclipse.m2m.atl.core.service.LauncherService.launch(LauncherService.java:136)
at org.eclipse.m2m.atl.core.ui.launch.AtlLaunchConfigurationDelegate.launchOrDebug(AtlLaunchConfigurationDelegate.java:300)
at org.eclipse.m2m.atl.core.ui.launch.AtlLaunchConfigurationDelegate.launch(AtlLaunchConfigurationDelegate.java:237)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(Unknown Source)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(Unknown Source)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(Unknown Source)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(Unknown Source)
at org.eclipse.core.internal.jobs.Worker.run(Unknown Source)
Caused by: java.lang.ClassCastException: w3schools.impl.PersonTypeImpl incompatible with org.eclipse.emf.ecore.util.FeatureMap$Entry
at org.eclipse.emf.ecore.util.BasicFeatureMap.add(Unknown Source)
at w3schools.impl.PersonTypeImpl.addPerson(PersonTypeImpl.java:172)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.m2m.atl.engine.emfvm.adapter.EMFModelAdapter.invoke(EMFModelAdapter.java:727)
... 14 more

It still sees the types as incompatible i.e. java.lang.ClassCastException: w3schools.impl.PersonTypeImpl incompatible with org.eclipse.emf.ecore.util.FeatureMap$Entry

Any ideas?
Thanks,
Ronan
Re: Assigning to a xs:any/EFeatureMapEntry with ATL [message #901183 is a reply to message #901013] Fri, 10 August 2012 08:45 Go to previous message
Ronan B is currently offline Ronan BFriend
Messages: 273
Registered: July 2009
Senior Member
Hi,
Ok I fixed this. The problem was that I needed to refer to W3schoolsPackage.Literals.DOCUMENT_ROOT__PERSON and not W3schoolsPackage.Literals.PERSON_TYPE__ANY. The former has type of PersonType while the latter is EFeatureMapEntry. This was causing the cast problems. Thanks for the great pointer Sylvain, this is a nice solution!

It might also be interesting for others to know that you can create another EAttribute off the DocumentRoot with a type of EObject. If I then use this in my EOperation I can assign any object to the any EFeatureMapEntry. For example I can now have a method like this...

public void addAny(EObject any) {
getAny().add(MyPackage.Literals.DOCUMENT_ROOT__ANY, any);
}

The ATL can now add any element by called .addAdd(XYZType.newInstance()) in a do block.

Regards,
Ronan
Previous Topic:EOperation defined at ecore need to be called at atl ?
Next Topic:GMF Transformation
Goto Forum:
  


Current Time: Fri Apr 19 19:26:36 GMT 2024

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

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

Back to the top