Setting different default values for Inherited attributes [message #698980] |
Wed, 20 July 2011 15:28 |
Arun Messages: 16 Registered: October 2010 |
Junior Member |
|
|
Hi All,
I have a unique problem. Consider the following Ecore meta-model. I have two classes with a common attribute 'm'. The m in Class A takes a default value, say 'Value1' and the m in Class B takes a default value, say 'Value2'.
<?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="Example"
nsURI="http:///example" nsPrefix="ex">
<eClassifiers xsi:type="ecore:EClass" name="A">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="m" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="Value1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="n" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="n1value"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="B">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="m" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="Value2"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="p" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="p1value"/>
</eClassifiers>
</ecore:EPackage>
As there is a common feature, I moved the attribute 'm' to an Abstract Class - Class C and make Class A and Class B to inherit from it, as shown below.
<?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="Example"
nsURI="http:///example" nsPrefix="ex">
<eClassifiers xsi:type="ecore:EClass" name="A" eSuperTypes="#//C">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="n" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="n1Value"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="B" eSuperTypes="#//C">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="p" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="p1Value"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="C" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="m" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="Value1"/>
</eClassifiers>
</ecore:EPackage>
However doing so, I lose the default values specified for the attribute 'm' in the context of Class A and Class B.
Can someone share some ideas or give hints how I can retain the default values for an attribute when it is moved to a Super Class or in other words how one can specify different default values for an attribute inherited from the Super class.
and btw, is there a possiblility to override an eattribute in emf/ecore? From what I read in the link
http://www.eclipsezone.com/eclipse/forums/t109339.html, i guess its not possible.
All suggestions and hints are welcome.
Thanks & Regards
Arun
ps:
i found this an interesting approach
[Updated on: Wed, 20 July 2011 15:40] Report message to a moderator
|
|
|
Re: Setting different default values for Inherited attributes [message #698994 is a reply to message #698980] |
Wed, 20 July 2011 15:40 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Arun,
Sorry, it's just not supported. The default is part of the attribute
definition and there can only be one. You might just define EOperations
in the super type that are implemented by different features with
different defaults in different subclasses.
On 20/07/2011 8:28 AM, Arun wrote:
> Hi All,
>
> I have a unique problem. Consider the following Ecore meta-model. I
> have two classes with a common attribute 'm'. The m in Class A takes a
> default value, say 'Value1' and the m in Class B takes a default
> value, say 'Value2'.
>
> http://imageshack.us/photo/my-images/714/model1o.png/
>
>
> <?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="Example"
> nsURI="http:///example" nsPrefix="ex">
> <eClassifiers xsi:type="ecore:EClass" name="A">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="m"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Value1"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="n"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="n1value"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="B">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="m"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Value2"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="p"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="p1value"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> As there is a common feature, I moved the attribute 'm' to an Abstract
> Class - Class C and make Class A and Class B to inherit from it, as
> shown below.
>
> http://imageshack.us/photo/my-images/841/model2.png/
>
>
> <?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="Example"
> nsURI="http:///example" nsPrefix="ex">
> <eClassifiers xsi:type="ecore:EClass" name="A" eSuperTypes="#//C">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="n"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="n1Value"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="B" eSuperTypes="#//C">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="p"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="p1Value"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="C" abstract="true">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="m"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="Value1"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> However doing so, I lose the default values specified for the
> attribute 'm' in the context of Class A and Class B.
>
> Can someone share some ideas or give hints how I can retain the
> default values for an attribute when it is moved to a Super Class or
> in other words how one can specify different default values for an
> attribute inherited from the Super class.
>
> All suggestions and hints are welcome.
>
> Thanks & Regards
> Arun
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Setting different default values for Inherited attributes [message #699052 is a reply to message #699013] |
Wed, 20 July 2011 18:07 |
Arun Messages: 16 Registered: October 2010 |
Junior Member |
|
|
Ed,
On the same note, I found that one could fully specify the EOperation through the model, using annotations (body->{implementation details} key, value pair), without actually touching the generated code.
I was wondering if it is somehow possible to invoke this EOperation when changes to the model are made. I mean with some parameter setting in the GenModel or is it only feasible through extension points ?
thanks & regards
Arun
UPDATE:
I managed to write a class that implements IResourceChangeListener and can now get notified with respect to the changes to the resource. probably i can also find out which element was changed and invoke the eoperation on it.
was just wondering if there is better/simpler way to do it.
thanks & regards
Arun
[Updated on: Wed, 20 July 2011 18:26] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02770 seconds