Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Re: EAnnotations and their contents
Re: EAnnotations and their contents [message #533243] Wed, 12 May 2010 16:54 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030208070002070708040800
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Philipp,

OCL is doing some pretty funky stuff computing a name when the name is
null. Even worse it the caches the result of that computation so that
the feature behaves as if it's been set explicitly to that computed name
and therefore doesn't change later when the things it's computed from
have changed.

public String getName() {
if (name == null) {
StringBuffer myName = new StringBuffer();

switch (getKind()) {
case SET_LITERAL :
myName.append(SetType.SINGLETON_NAME);
break;
case ORDERED_SET_LITERAL :
myName.append(OrderedSetType.SINGLETON_NAME);
break;
case BAG_LITERAL :
myName.append(BagType.SINGLETON_NAME);
break;
case SEQUENCE_LITERAL :
myName.append(SequenceType.SINGLETON_NAME);
break;
default :
myName

.append(org.eclipse.ocl.types.CollectionType.SINGLETON_NAME) ;
break;
}

myName.append('(');

EClassifier elementType = getElementType();
String elementTypeName;
if (elementType != null) {
elementTypeName = elementType.getName();
} else {
elementTypeName = ""; //$NON-NLS-1$
}

myName.append(elementTypeName);
myName.append(')');

name = myName.toString();
}

return name;
}

Changing it to this


set2.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RES OLUTION,
Boolean.TRUE);
Resource actual = set2.getResource(URI.createFileURI(new
File("test.ecore").getAbsolutePath()), true);

I.e., deferring ID resolution so that getName isn't called until after
the resource is fully loaded avoids this problem.

Why aren't you giving this thing a name? That seems to be the root
problem...


Philipp Berger wrote:
> Hey Ed,
> sorry for my confusing error discriptions.
>
> Here is the Code which throws an unexpected
> UnresolvedReferenceException on reloading the resource.
>
> I figured out that this is caused by the ocl BagType itself, in
> contrast to the normal Ecore DataType, the BagType get not enumeratet
> if there is no name.
> So for DataType without name the URI will be (...contents/.0), but for
> an BagType an unresolvable URI like (.../Bag(ElementType)) is created.
> The actual Element has no name, as consequence the link is not
> resolvable.
>
> My Quickfix was to ask the executed EcoreUtil.getUri(type), actual I
> don't no why as side effect the BagType get a name but it works.
>
> Best regards,
> Phil
>
>
>
>
>
> ResourceSet set = new ResourceSetImpl();
>
> /*
> * Create resource
> */
>
> set.getResourceFactoryRegistry().getExtensionToFactoryMap(). put( "*",
> new EcoreResourceFactoryImpl());
> Resource r = set.createResource(URI.createFileURI(new
> File("test.ecore").getAbsolutePath()));
>
> EPackage myPkg = EcoreFactory.eINSTANCE.createEPackage();
> myPkg.setName("p");
> r.getContents().add(myPkg);
>
>
> EClass myClass = EcoreFactory.eINSTANCE.createEClass();
> myClass.setName("class2");
> EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
> attr.setName("link");
>
> myClass.getEStructuralFeatures().add(attr);
> myPkg.getEClassifiers().add(myClass);
>
>
> EAnnotation annotation =
> EcoreFactory.eINSTANCE.createEAnnotation();
> annotation.setSource("mySource");
> BagType bag =
> org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createBagType() ;
> bag.setInstanceClassName("org.eclipse.ocl.util.Bag");
> bag.setElementType(myClass);
> attr.setEType(bag);
> /*
> * add Bag to EAnnotation
> */
> annotation.getContents().add(bag);
> myPkg.getEAnnotations().add(annotation);
>
> try {
> r.save(null);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> ResourceSet set2 = new ResourceSetImpl();
>
> /*
> * Unable to load resource UnResolvedReference Error
> */
>
> set2.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
> new EcoreResourceFactoryImpl());
> Resource actual = set2.getResource(URI.createFileURI(new
> File("test.ecore").getAbsolutePath()), true);
> return null;
>
>
>
> Am 12.05.2010 12:12, schrieb Ed Merks:
>> Philipp,
>>
>> Please create a test case that demonstrates the problem you're actually
>> having and then I can have a look at that.
>>
>>
>> Philipp Berger wrote:
>>> Hey Ed,
>>> thanks for the hint, but but my problem is not that the Annotations
>>> are not present after generating (sure this problem will be the next
>>> step). My Problem is more about loading an .ecore File, manipulating
>>> the Annotations of some classes and have links between the
>>> AnnotationsContents of differnent classes (or between classes and
>>> package annotations).
>>>
>>> Beste Regards and thanks for your fast reply,
>>> Phil
>>>
>>>
>>> Am 06.05.2010 11:10, schrieb Ed Merks:
>>>> Phil,
>>>>
>>>> If you look at generated packages, you'll see that the contents of
>>>> annotations aren't present in the generated instances. If you use the
>>>> GenPackage's Initialize by Loading property, you should end up with
>>>> generated packages that contain the full annotation structure.
>>>>
>>>>
>>>> Philipp Berger wrote:
>>>>> Hey guys,
>>>>> I currently playing around with EAnnotations and their content
>>>>> reference.
>>>>> So my scenario:
>>>>> I have elements A, B and C. A and B are contained in the same
>>>>> Package,
>>>>> but C is contained in an Annotation from A.
>>>>> My problem:
>>>>> When B has a reference to C, I get an UnresolvedReferenceException.
>>>>> that one is not able to resolve '//{sourceOfTheAnnotation}/C'.
>>>>>
>>>>> Has anyone an idea how to make this stuff work?
>>>>>
>>>>> Best Regards,
>>>>> Phil
>>>
>

--------------030208070002070708040800
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Philipp,<br>
<br>
OCL is doing some pretty funky stuff computing a name when the name is
null.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EAnnotations and their contents [message #533776 is a reply to message #533243] Sun, 16 May 2010 21:34 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

MDT/OCL https://bugs.eclipse.org/bugs/show_bug.cgi?id=313048 raised.

Regards

Ed Willink

On 12/05/2010 17:54, Ed Merks wrote:
> Philipp,
>
> OCL is doing some pretty funky stuff computing a name when the name is
> null. Even worse it the caches the result of that computation so that
> the feature behaves as if it's been set explicitly to that computed name
> and therefore doesn't change later when the things it's computed from
> have changed.
>
> public String getName() {
> if (name == null) {
> StringBuffer myName = new StringBuffer();
>
> switch (getKind()) {
> case SET_LITERAL :
> myName.append(SetType.SINGLETON_NAME);
> break;
> case ORDERED_SET_LITERAL :
> myName.append(OrderedSetType.SINGLETON_NAME);
> break;
> case BAG_LITERAL :
> myName.append(BagType.SINGLETON_NAME);
> break;
> case SEQUENCE_LITERAL :
> myName.append(SequenceType.SINGLETON_NAME);
> break;
> default :
> myName
>
> ..append(org.eclipse.ocl.types.CollectionType.SINGLETON_NAME );
> break;
> }
>
> myName.append('(');
>
> EClassifier elementType = getElementType();
> String elementTypeName;
> if (elementType != null) {
> elementTypeName = elementType.getName();
> } else {
> elementTypeName = ""; //$NON-NLS-1$
> }
>
> myName.append(elementTypeName);
> myName.append(')');
>
> name = myName.toString();
> }
>
> return name;
> }
>
> Changing it to this
>
>
> set2.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RES OLUTION,
> Boolean.TRUE);
> Resource actual = set2.getResource(URI.createFileURI(new
> File("test.ecore").getAbsolutePath()), true);
>
> I.e., deferring ID resolution so that getName isn't called until after
> the resource is fully loaded avoids this problem.
>
> Why aren't you giving this thing a name? That seems to be the root
> problem...
>
>
> Philipp Berger wrote:
>> Hey Ed,
>> sorry for my confusing error discriptions.
>>
>> Here is the Code which throws an unexpected
>> UnresolvedReferenceException on reloading the resource.
>>
>> I figured out that this is caused by the ocl BagType itself, in
>> contrast to the normal Ecore DataType, the BagType get not enumeratet
>> if there is no name.
>> So for DataType without name the URI will be (...contents/.0), but for
>> an BagType an unresolvable URI like (.../Bag(ElementType)) is created.
>> The actual Element has no name, as consequence the link is not
>> resolvable.
>>
>> My Quickfix was to ask the executed EcoreUtil.getUri(type), actual I
>> don't no why as side effect the BagType get a name but it works.
>>
>> Best regards,
>> Phil
>>
>>
>>
>>
>>
>> ResourceSet set = new ResourceSetImpl();
>>
>> /*
>> * Create resource
>> */
>>
>> set.getResourceFactoryRegistry().getExtensionToFactoryMap(). put( "*",
>> new EcoreResourceFactoryImpl());
>> Resource r = set.createResource(URI.createFileURI(new
>> File("test.ecore").getAbsolutePath()));
>>
>> EPackage myPkg = EcoreFactory.eINSTANCE.createEPackage();
>> myPkg.setName("p");
>> r.getContents().add(myPkg);
>>
>>
>> EClass myClass = EcoreFactory.eINSTANCE.createEClass();
>> myClass.setName("class2");
>> EAttribute attr = EcoreFactory.eINSTANCE.createEAttribute();
>> attr.setName("link");
>>
>> myClass.getEStructuralFeatures().add(attr);
>> myPkg.getEClassifiers().add(myClass);
>>
>>
>> EAnnotation annotation =
>> EcoreFactory.eINSTANCE.createEAnnotation();
>> annotation.setSource("mySource");
>> BagType bag =
>> org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createBagType() ;
>> bag.setInstanceClassName("org.eclipse.ocl.util.Bag");
>> bag.setElementType(myClass);
>> attr.setEType(bag);
>> /*
>> * add Bag to EAnnotation
>> */
>> annotation.getContents().add(bag);
>> myPkg.getEAnnotations().add(annotation);
>>
>> try {
>> r.save(null);
>> } catch (IOException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> ResourceSet set2 = new ResourceSetImpl();
>>
>> /*
>> * Unable to load resource UnResolvedReference Error
>> */
>>
>> set2.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
>> new EcoreResourceFactoryImpl());
>> Resource actual = set2.getResource(URI.createFileURI(new
>> File("test.ecore").getAbsolutePath()), true);
>> return null;
>>
>>
>>
>> Am 12.05.2010 12:12, schrieb Ed Merks:
>>> Philipp,
>>>
>>> Please create a test case that demonstrates the problem you're actually
>>> having and then I can have a look at that.
>>>
>>>
>>> Philipp Berger wrote:
>>>> Hey Ed,
>>>> thanks for the hint, but but my problem is not that the Annotations
>>>> are not present after generating (sure this problem will be the next
>>>> step). My Problem is more about loading an .ecore File, manipulating
>>>> the Annotations of some classes and have links between the
>>>> AnnotationsContents of differnent classes (or between classes and
>>>> package annotations).
>>>>
>>>> Beste Regards and thanks for your fast reply,
>>>> Phil
>>>>
>>>>
>>>> Am 06.05.2010 11:10, schrieb Ed Merks:
>>>>> Phil,
>>>>>
>>>>> If you look at generated packages, you'll see that the contents of
>>>>> annotations aren't present in the generated instances. If you use the
>>>>> GenPackage's Initialize by Loading property, you should end up with
>>>>> generated packages that contain the full annotation structure.
>>>>>
>>>>>
>>>>> Philipp Berger wrote:
>>>>>> Hey guys,
>>>>>> I currently playing around with EAnnotations and their content
>>>>>> reference.
>>>>>> So my scenario:
>>>>>> I have elements A, B and C. A and B are contained in the same
>>>>>> Package,
>>>>>> but C is contained in an Annotation from A.
>>>>>> My problem:
>>>>>> When B has a reference to C, I get an UnresolvedReferenceException.
>>>>>> that one is not able to resolve '//{sourceOfTheAnnotation}/C'.
>>>>>>
>>>>>> Has anyone an idea how to make this stuff work?
>>>>>>
>>>>>> Best Regards,
>>>>>> Phil
>>>>
>>
Previous Topic:OCl Implementation for GMF diagram
Next Topic:OCL constraint: blank character in a string
Goto Forum:
  


Current Time: Thu Mar 28 17:39:39 GMT 2024

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

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

Back to the top