Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EAnnotation and Cross document reference
EAnnotation and Cross document reference [message #420697] Tue, 08 July 2008 05:57 Go to next message
Sushant Sirsikar is currently offline Sushant SirsikarFriend
Messages: 5
Registered: July 2009
Junior Member
Hi All,
I am working on project which uses cross document reference
functionality of EMF. I have two models
1) UML2.0 model. (Which is uml model created by emf’s tool project)
2) Description model (This model is create using emf to store
description of Uml model).
Both the models are in different resource and using EMF version
2.2. There is one constraint, that I can not change the UML2.0 model
because of dependency with other code.
Now problem is, I need to attach this new “Description” model to
UML2.0 model. I am trying to add this model inside the EMF model using
EAnnotation. EAnnotation has ‘details’ field which returns ECoreEMap,
which delegates to EStringTOStringMap as …

public class EAnnotationImpl extends EModelElementImpl implements
EAnnotation
{
………
---
public EMap getDetails()
{
if (details == null)
{
details = new
EcoreEMap(EcorePackage.eINSTANCE.getEStringToStringMapEntry( ),
EStringToStringMapEntryImpl.class, this,
EcorePackage.EANNOTATION__DETAILS);
}
return details;
}
--
--
--
}

Above is default implementation provided in
org.eclipse.emf.ecore.impl.EAnnotationImpl. Now I want my details contains
map which can take ‘object’ as key and value instead of String which is
provided by EStringTOStringMap. To achieve this I override details()
method as

EAnnotaion annotation = new EAnnotationImpl(){
@Override
public EMap getDetails() {
if(this.details==null){
this.details = new
EcoreEMap(Uml2docPackage.eINSTANCE.getObjectMap(), ObjectMapImpl.class,
this, EcorePackage.EANNOTATION__DETAILS);
}
return this.details;
}
};
annotation.setSource(IAnnotationConstants.DOCUMENTATION_SOUR CE);
umlelement.getEAnnotations().add(annotation);
This details method delegates to ObjectMap which is inside “Description”
model. So when I save my resources, my .uml file looks like bellow :

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:com.zensar.sbp.modelTransformation.model="http://zensar.com"
xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML"
xmi:id="_x2a-IEvrEd2X0eL_8jpS4A">
<eAnnotations xmi:id="_0UEsUEvrEd2X0eL_8jpS4A"
source="http://www.zensar.com/uuid">
<details xmi:id="_0UEsUUvrEd2X0eL_8jpS4A" key="uuid"
value="12154112091090"/>
</eAnnotations>
-------------------------------
-----------Some serialized model-----------------------
-------------------------------
<ownedMember xmi:type="uml:UseCase" xmi:id="_yy6bkEvrEd2X0eL_8jpS4A"
name="UseCase1">
<eAnnotations xmi:id="_zlSTsEvrEd2X0eL_8jpS4A"
source="http://www.zensar.com/documentation">
<eAnnotations xmi:id="_0UEsWEvrEd2X0eL_8jpS4A"
source="http://www.zensar.com/uuid">
<details xmi:id="_0UEsWUvrEd2X0eL_8jpS4A" key="uuid"
value="12154112091095"/>
</eAnnotations>
<details
xmi:type="com.zensar.sbp.modelTransformation.model:ObjectMap "
xmi:id="_zlSTsUvrEd2X0eL_8jpS4A" key="documentation">
<value
xmi:type="com.zensar.sbp.modelTransformation.model:Documentation "
href="file:/c:/docTest.uml2doc#/"/>
</details>
</eAnnotations>
<eAnnotations xmi:id="_0UEsVkvrEd2X0eL_8jpS4A"
source="http://www.zensar.com/uuid">
<details xmi:id="_0UEsV0vrEd2X0eL_8jpS4A" key="uuid"
value="12154112091094"/>
</eAnnotations>
</ownedMember>
</ownedMember>
</uml:Model>

So my problem is :
1) When I load the uml and description model in resource set, it loads
object map with key but it doesn’t load value, which is cross document
reference to ‘description’ model.
2) What is the way to register my new annotationimpl inside EcoreFactory
and package.? Because when I load uml model, it again creates
EStringToString map and could not store my ObjectMap which in terns gives
ArrayStoreExcption.

Thanks in advance for any suggestion.
Re: EAnnotation and Cross document reference [message #420700 is a reply to message #420697] Tue, 08 July 2008 11:05 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Sushant,

Comments below.

Sushant Sirsikar wrote:
> Hi All,
> I am working on project which uses cross document reference
> functionality of EMF. I have two models
> 1) UML2.0 model. (Which is uml model created by emf�s tool project)
> 2) Description model (This model is create using emf to store
> description of Uml model).
> Both the models are in different resource and using EMF version 2.2.
> There is one constraint, that I can not change the UML2.0 model
> because of dependency with other code. Now problem is, I need to
> attach this new �Description� model to UML2.0 model. I am trying to
> add this model inside the EMF model using EAnnotation. EAnnotation has
> �details� field which returns ECoreEMap, which delegates to
> EStringTOStringMap as �
> public class EAnnotationImpl extends EModelElementImpl implements
> EAnnotation
> {
> ���
> ---
> public EMap getDetails()
> {
> if (details == null)
> {
> details = new
> EcoreEMap(EcorePackage.eINSTANCE.getEStringToStringMapEntry( ),
> EStringToStringMapEntryImpl.class, this,
> EcorePackage.EANNOTATION__DETAILS);
> }
> return details;
> }
> --
> --
> --
> }
>
> Above is default implementation provided in
> org.eclipse.emf.ecore.impl.EAnnotationImpl. Now I want my details
> contains map which can take �object� as key and value instead of
> String which is provided by EStringTOStringMap. To achieve this I
> override details() method as
>
> EAnnotaion annotation = new EAnnotationImpl(){
> @Override
> public EMap getDetails() {
> if(this.details==null){
> this.details = new EcoreEMap(Uml2docPackage.eINSTANCE.getObjectMap(),
> ObjectMapImpl.class, this, EcorePackage.EANNOTATION__DETAILS);
> }
> return this.details;
> }
> };
> annotation.setSource(IAnnotationConstants.DOCUMENTATION_SOUR CE);
> umlelement.getEAnnotations().add(annotation);
No, this is not a reasonable approach. With Java 5.0 you'd find it
wouldn't work properly because the of the key and the value are revealed
in the signature. Even aside from that fact, unless your derived
EAnnotation is modeled (has it's one EClass by which it could be
recognized as a derived instance), there would be nothing to prompt
things like the deserializer or the copier to create an instance of your
derived class.
> This details method delegates to ObjectMap which is inside
> �Description� model. So when I save my resources, my .uml file looks
> like bellow :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:com.zensar.sbp.modelTransformation.model="http://zensar.com"
> xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML"
> xmi:id="_x2a-IEvrEd2X0eL_8jpS4A">
> <eAnnotations xmi:id="_0UEsUEvrEd2X0eL_8jpS4A"
> source="http://www.zensar.com/uuid">
> <details xmi:id="_0UEsUUvrEd2X0eL_8jpS4A" key="uuid"
> value="12154112091090"/>
> </eAnnotations>
> -------------------------------
> -----------Some serialized model-----------------------
> -------------------------------
> <ownedMember xmi:type="uml:UseCase" xmi:id="_yy6bkEvrEd2X0eL_8jpS4A"
> name="UseCase1">
> <eAnnotations xmi:id="_zlSTsEvrEd2X0eL_8jpS4A"
> source="http://www.zensar.com/documentation">
> <eAnnotations xmi:id="_0UEsWEvrEd2X0eL_8jpS4A"
> source="http://www.zensar.com/uuid">
> <details xmi:id="_0UEsWUvrEd2X0eL_8jpS4A" key="uuid"
> value="12154112091095"/>
> </eAnnotations>
> <details xmi:type="com.zensar.sbp.modelTransformation.model:ObjectMap "
> xmi:id="_zlSTsUvrEd2X0eL_8jpS4A" key="documentation">
> <value
> xmi:type="com.zensar.sbp.modelTransformation.model:Documentation "
> href="file:/c:/docTest.uml2doc#/"/>
> </details>
> </eAnnotations>
> <eAnnotations xmi:id="_0UEsVkvrEd2X0eL_8jpS4A"
> source="http://www.zensar.com/uuid">
> <details xmi:id="_0UEsV0vrEd2X0eL_8jpS4A" key="uuid"
> value="12154112091094"/>
> </eAnnotations>
> </ownedMember>
> </ownedMember>
> </uml:Model>
>
> So my problem is :
> 1) When I load the uml and description model in resource set, it loads
> object map with key but it doesn�t load value, which is cross document
> reference to �description� model.
> 2) What is the way to register my new annotationimpl inside
> EcoreFactory and package.? Because when I load uml model, it again
> creates EStringToString map and could not store my ObjectMap which in
> terns gives ArrayStoreExcption.
This is really completely the wrong direction in which to go. Firstly, I
always strongly advise against extending the Ecore model and to focus
instead on decorating it; you're trying to extend EAnnotation itself
rather than using it directly as a decorator. The details map is meant
only for string to string mappings; nothing more, but note that
EAnnotation has getContents and getReferences which allow you to contain
any EObjects or reference any EObjects. So if you want to build some new
type of map or something else sophisticated, define a new EClass for
that structure and nest instances of that within the getContents reference.
>
> Thanks in advance for any suggestion.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Object identity - Hibernate Entity Manager - Teneo
Next Topic:[Emf.Edit] Problem in displaying specific items
Goto Forum:
  


Current Time: Fri Apr 26 01:19:32 GMT 2024

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

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

Back to the top