Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [emf] cannot control type of id attribute in ecore model
[emf] cannot control type of id attribute in ecore model [message #719793] Mon, 29 August 2011 04:08 Go to next message
tsurdilo  is currently offline tsurdilo Friend
Messages: 41
Registered: February 2011
Member
Hi all, I am working with the eclipse.bpmn2 ecore model and it has defined Definitions element:

http://i.imgur.com/9bymc.png

and the BaseElement which it extends has the id attribute among other:

http://i.imgur.com/0YnyU.png

After creating the model I can get to the Definitions element (root element of the output bpmn2 with for example:

Definitions definitions = ((Definitions) unmarshaller.unmarshall(myJsonSring, "").getContents().get(0)); // unmarshaller.unmarshall returns type Resource


What I am unable to figure out what sets the id of Definitions element. If I change the type of the id attribute in BaseElement in the ecore from EString to NCName, this change takes affect for all of the elements that extend BaseElement in the ecore model _but not_ the root element (Definitions). It seems nothing that I change in the ecore seems to affect the type of the id attribute of the root element. Was wondering if there is anything in EMF that sets this that I am missing?

Sorry that I am posting eclipse.bpmn2 questions here, but I am not getting any responses in their forum, and maybe this is an EMF-specific question .. any input is more than welcome.

Thanks.


Re: [emf] cannot control type of id attribute in ecore model [message #719797 is a reply to message #719793] Mon, 29 August 2011 04:43 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

On 28/08/2011 9:08 PM, tsurdilo wrote:
> Hi all, I am working with the eclipse.bpmn2 ecore model and it has
> defined Definitions element:
>
>
>
> and the BaseElement which it extends has the id attribute among other:
So EAttribute.iD is set to true?
>
>
>
> After creating the model I can get to the Definitions element (root
> element of the output bpmn2 with for example:
>
>
> Definitions definitions = ((Definitions)
> unmarshaller.unmarshall(myJsonSring, "").getContents().get(0)); //
> unmarshaller.unmarshall returns type Resource
So you're getting the first root object from the resource.
>
>
> What I am unable to figure out what sets the id of Definitions element.
The value is in the XML? It's set just like any other feature's value
is set...
> If I change the type of the id attribute in BaseElement in the ecore
> from EString to NCName, this change takes affect for all of the
> elements that extend BaseElement in the ecore model _but not_ the root
> element (Definitions).
I can't imagine how that's the case. It inherits id from BaseElement so
how can it possibly not be affected?
> It seems nothing that I change in the ecore seems to affect the type
> of the id attribute of the root element.
Both end up mapping to java.lang.String so what exactly are you
expecting to see?
> Was wondering if there is anything in EMF that sets this that I am
> missing?
What are you trying to achieve?
>
> Sorry that I am posting eclipse.bpmn2 questions here, but I am not
> getting any responses in their forum, and maybe this is an
> EMF-specific question .. any input is more than welcome.
I'm a little confused about what you're asking...
>
> Thanks.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [emf] cannot control type of id attribute in ecore model [message #719804 is a reply to message #719797] Mon, 29 August 2011 05:18 Go to previous messageGo to next message
tsurdilo  is currently offline tsurdilo Friend
Messages: 41
Registered: February 2011
Member
>> So EAttribute.iD is set to true? -- Yes it is.
>> Both end up mapping to java.lang.String so what exactly are you
expecting to see? -- The difference is that NCName cannot begin with a number, whereas from what I see if I change the type to EString, or ID, the id begins with a number, or it does not, seems random.
This goes back to the useless Semantic.xsd OMG schema which I have to adhere to and it forces me to use NCName for the definitions element id type. What I see is the following: if I set BaseElement id type to NCName in the ecore, I get the following output for example:

<bpmn2:definitions ... id="87B71DAE-7756-41DC-9094-3C02B29C595C">
...
   <bpmn2:process ... id="_EB49660E-9F68-4B44-85F7-143F50D54961">
      <bpmn2:startEvent id="_0743078E-C560-43C8-A3D8-F7937E09B955" name="">
      ...
      </bpmn2:startEvent>
      <bpmn2:endEvent id="_97B71DAE-7756-41DC-9094-3C02B29C594B" name="">
      ...
      </bpmn2:endEvent>
   </bpmn2:process>
...
</bpmn2:definitions>


All ids, except definitions root element id start with "_". This made me believe that emf adds this underscore to make sure the id does not begin with a number. However it does not apply to Definitions for some reason which also extends BaseElement, just like StartEvent, and EndEvent. The only thing I could think of was that emf generates the id of the root element differently, but as you mention that should not be so, so I'll keep digging.

Sorry if my question is confusing.
Thanks.

[Updated on: Mon, 29 August 2011 05:32]

Report message to a moderator

Re: [emf] cannot control type of id attribute in ecore model [message #720015 is a reply to message #719804] Mon, 29 August 2011 16:56 Go to previous messageGo to next message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Comments below.

On 28/08/2011 10:18 PM, tsurdilo wrote:
>>> So EAttribute.iD is set to true? -- Yes it is.
>>> Both end up mapping to java.lang.String so what exactly are you
> expecting to see? -- The difference is that NCName cannot begin with a
> number, whereas from what I see if I change the type to EString, or
> ID, the id begins with a number, or it does not, seems random.
Indeed NCName is more restrictive than EString in terms of associated
EMF constraints; what BPMN2 does with that knowledge, I can't comment on.
> This goes back to the useless Semantic.xsd OMG schema which I have to
> adhere to and it forces me to use NCName for the definitions element
> id type. What I see is the following: if I set BaseElement id type to
> NCName, I get the following output for example:
>
>
> <bpmn2:definitions ... id="87B71DAE-7756-41DC-9094-3C02B29C595C">
Some type of horrible non-human readable UUID...
> ..
> <bpmn2:process ... id="_EB49660E-9F68-4B44-85F7-143F50D54961">
> <bpmn2:startEvent id="_0743078E-C560-43C8-A3D8-F7937E09B955" name="">
> ...
> </bpmn2:startEvent>
> <bpmn2:endEvent id="_97B71DAE-7756-41DC-9094-3C02B29C594B" name="">
> ...
> </bpmn2:endEvent>
> </bpmn2:process>
> ..
> </bpmn2:definitions>
>
>
> All elements, except definitions root element start with "_". I deal
> with this now by just hard-coding the id to some string value.
> Sorry if my question is confusing. Thanks.
How BPMN2 assigns IDs is fundamentally a question those folks must
answer for you. In an ideal world, human readable IDs would be assigned...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [emf] cannot control type of id attribute in ecore model [message #720364 is a reply to message #720015] Tue, 30 August 2011 13:15 Go to previous messageGo to next message
tsurdilo  is currently offline tsurdilo Friend
Messages: 41
Registered: February 2011
Member
>> How BPMN2 assigns IDs is fundamentally a question those folks must
answer for you. In an ideal world, human readable IDs would be assigned... <<
The API has a class I am using:

Bpmn2ResourceImpl extends XMLResourceImpl implements Bpmn2Resource { ... }


however it does not overwrite the generateUUID() method. It does override the createXMLSave() method in which the code makes sure all the id's are set using EcoreUtil.generateUUID():

EObject cur;
        Definitions thisDefinitions = ImportHelper.getDefinitions(this);
        for (Iterator<EObject> iter = getAllContents(); iter.hasNext();) {
            cur = iter.next();

            setIdIfNotSet(cur);
.....



 protected static void setIdIfNotSet(EObject obj) {
        if (obj.eClass() != null) {
            EStructuralFeature idAttr = obj.eClass().getEIDAttribute();
            if (idAttr != null && !obj.eIsSet(idAttr)) {
                obj.eSet(idAttr, EcoreUtil.generateUUID());
            }
        }
    }


Seems the id generation is completely deferred to EMF, there is nothing custom. I will create small test to try to reproduce the issue I am seeing and upload.
Re: [emf] cannot control type of id attribute in ecore model [message #720486 is a reply to message #720364] Tue, 30 August 2011 17:12 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
EMF's generated UUIDs don't have "-" in them like you've shown so it's
unlikely that the "obj.eSet(idAttr, EcoreUtil.generateUUID())" logic is
being reached. Try setting a breakpoint in the setID method to see who
is setting it when...


On 30/08/2011 6:15 AM, tsurdilo wrote:
>>> How BPMN2 assigns IDs is fundamentally a question those folks must
> answer for you. In an ideal world, human readable IDs would be
> assigned... << The API has a class I am using:
> Bpmn2ResourceImpl extends XMLResourceImpl implements Bpmn2Resource {
> ... }
>
> however it does not overwrite the generateUUID() method. It does
> override the createXMLSave() method in which the code makes sure all
> the id's are set using EcoreUtil.generateUUID():
>
> EObject cur;
> Definitions thisDefinitions = ImportHelper.getDefinitions(this);
> for (Iterator<EObject> iter = getAllContents(); iter.hasNext();) {
> cur = iter.next();
>
> setIdIfNotSet(cur);
> ....
>
>
>
> protected static void setIdIfNotSet(EObject obj) {
> if (obj.eClass() != null) {
> EStructuralFeature idAttr = obj.eClass().getEIDAttribute();
> if (idAttr != null && !obj.eIsSet(idAttr)) {
> obj.eSet(idAttr, EcoreUtil.generateUUID());
> }
> }
> }
>
> Seems the id generation is completely deferred to EMF, there is
> nothing custom. I will create small test to try to reproduce the issue
> I am seeing and upload.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Exception with queryXRefs and teneo Annotation @Transient
Next Topic:(no subject)
Goto Forum:
  


Current Time: Fri Apr 19 05:46:01 GMT 2024

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

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

Back to the top