Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EcoreUtil.equals for xsd:list type(EcoreUtil.equals behavior with xsd:list type )
EcoreUtil.equals for xsd:list type [message #986590] Wed, 21 November 2012 06:17 Go to next message
Arati Rahalkar is currently offline Arati Rahalkar
Messages: 12
Registered: November 2012
Junior Member
Hi,

I have a xsd with a simple type containing a xsd:list. For example, my xml contains the following:

<element1 listattribute="item1 item2 item3">
...
</element1>

The listattribute is a simple type containing a xsd:list. When I read this XML using Resource and ResourceSet, the listattribute is getting mapped to EAttributeImpl, and its instanceClassName is not java.util.List, instead it is the simple java Object.

Now, I want to compare 2 such XML files, difference in the listattribute values in the two XML files is only in the order, for example: first XML has values "item1 item2 item3" and second XML has values "item3 item1 item2". When I compare these two XMLs using EcoreUtil.equals, it just checks if the two strings are equal. Since only the order of values is different, it returns false.

I wanted to know the following:
1. Why does the instanceClassName not get set to java.util.List? If that is the case, at least I can override the equals behavior somehow.
2. The default EcoreUtil.equals implementation does not seem to handle this case at all. That is it is treating the space separated list of values as just being one string value.

Can anyone throw some light on this behavior?

Thanks,
Arati
Re: EcoreUtil.equals for xsd:list type [message #986594 is a reply to message #986590] Wed, 21 November 2012 06:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Arati,

Comments below.

On 21/11/2012 7:17 AM, Arati Rahalkar wrote:
> Hi,
>
> I have a xsd with a simple type containing a xsd:list. For example, my
> xml contains the following:
>
> <element1 listattribute="item1 item2 item3">
> ..
> </element1>
>
> The listattribute is a simple type containing a xsd:list. When I read
> this XML using Resource and ResourceSet, the listattribute is getting
> mapped to EAttributeImpl, and its instanceClassName is not
> java.util.List, instead it is the simple java Object.
Is it a multi-valued EAttibute? Without seeing the schema, it's hard to
comment.
>
> Now, I want to compare 2 such XML files, difference in the
> listattribute values in the two XML files is only in the order, for
> example: first XML has values "item1 item2 item3" and second XML has
> values "item3 item1 item2". When I compare these two XMLs using
> EcoreUtil.equals, it just checks if the two strings are equal.
You mentioned something about the type just being Object, but now you're
saying it's comparing two strings...
> Since only the order of values is different, it returns false.
>
> I wanted to know the following:
> 1. Why does the instanceClassName not get set to java.util.List?
Without seeing your schema, I can't say.
> If that is the case, at least I can override the equals behavior somehow.
Lists have a well defined equality algorithm and order is relevant.
> 2. The default EcoreUtil.equals implementation does not seem to handle
> this case at all. That is it is treating the space separated list of
> values as just being one string value.
That depends on the model and you haven't shown that.
>
> Can anyone throw some light on this behavior?
Not without accurate details about your model.
>
> Thanks,
> Arati
Re: EcoreUtil.equals for xsd:list type [message #986617 is a reply to message #986594] Wed, 21 November 2012 08:24 Go to previous messageGo to next message
Arati Rahalkar is currently offline Arati Rahalkar
Messages: 12
Registered: November 2012
Junior Member
Hi Ed,

I cannot give the whole XSD here because of confidentiality reasons. But giving snippets below if that helps.

I have the list type defined as below:
<simpleType name="listOfQNames">
<list itemType="QName"/>
</simpleType>

This simple type is used inside a ComplexType defined below:
<complexType abstract="true" name="Binding">
<sequence>
....
</sequence>
...
<attribute name="policies" type="listOfQNames" use="optional"/>
</complexType>

There is this xsd and corresponding ecore model. Note that these are written as extensions to my XML, and hence at runtime at the time of loading the XML file, I do not have the EPackage registered for it. As a result, these snippets in the XML file get mapped to AnyType, and I get FeatureMaps. In that I see that for policies, I get an EAttributeImpl, with instanceClassName as java.lang.Object.

My question is if the xsd defines policies to be of type list, why does it not get mapped to java.util.List?

Could it be because the snippet is not recognized and getting mapped to AnyType?

Thanks,
Arati
Re: EcoreUtil.equals for xsd:list type [message #986796 is a reply to message #986617] Wed, 21 November 2012 16:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Arati,

Comments below.

On 21/11/2012 9:24 AM, Arati Rahalkar wrote:
> Hi Ed,
>
> I cannot give the whole XSD here because of confidentiality reasons.
> But giving snippets below if that helps.
>
> I have the list type defined as below:
> <simpleType name="listOfQNames">
> <list itemType="QName"/>
> </simpleType>
Ah, so they're QNames. Which version of EMF are you using. In the
older versions there was no public class for representing QName so we
used an internal class and didn't surface this internal class. In the
new versions of EMF, you should see javax.xml.namespace.QName as the
instance class.
>
> This simple type is used inside a ComplexType defined below:
> <complexType abstract="true" name="Binding">
> <sequence>
> ....
> </sequence>
> ... <attribute name="policies" type="listOfQNames"
> use="optional"/>
> </complexType>
>
> There is this xsd and corresponding ecore model. Note that these are
> written as extensions to my XML, and hence at runtime at the time of
> loading the XML file, I do not have the EPackage registered for it. As
> a result, these snippets in the XML file get mapped to AnyType, and I
> get FeatureMaps. In that I see that for policies, I get an
> EAttributeImpl, with instanceClassName as java.lang.Object.
>
> My question is if the xsd defines policies to be of type list, why
> does it not get mapped to java.util.List?
I would expect a list of QNames, but even in your case, it should be a
single value that's a list of objects.
>
> Could it be because the snippet is not recognized and getting mapped
> to AnyType?
>
> Thanks,
> Arati
Re: EcoreUtil.equals for xsd:list type [message #986811 is a reply to message #986796] Wed, 21 November 2012 17:53 Go to previous messageGo to next message
Arati Rahalkar is currently offline Arati Rahalkar
Messages: 12
Registered: November 2012
Junior Member
Hi,

I am using version 2.4.2. The instanceClassName is java.lang.Object. I am not getting a List of objects, instead that feature from the feature map is not EReference, and hence directly the value is checked using ==.

Thanks,
Arati
Re: EcoreUtil.equals for xsd:list type [message #986814 is a reply to message #986811] Wed, 21 November 2012 18:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Arati,

Comments below.

On 21/11/2012 6:53 PM, Arati Rahalkar wrote:
> Hi,
>
> I am using version 2.4.2.
That's an ancient version. Better you use something newer.
> The instanceClassName is java.lang.Object.
I suppose that's because it's a QName and your version is very old.
> I am not getting a List of objects, instead that feature from the
> feature map is not EReference, and hence directly the value is checked
> using ==.
So you're saying the feature is an EAttribute? You showed an
xsd:attribute so I don't see why that would be in a feature map, from
the snippet you show. Don't you have a Binding.getPolicies() method?
What's the type of that?
> Thanks,
> Arati
Re: EcoreUtil.equals for xsd:list type [message #986819 is a reply to message #986814] Wed, 21 November 2012 18:13 Go to previous messageGo to next message
Arati Rahalkar is currently offline Arati Rahalkar
Messages: 12
Registered: November 2012
Junior Member
Hi Ed,

This is part of a big product, which uses EMF 2.4.2, so seems unlikely that I can move to a newer version.

Actually, this snippet of the XML file is part of an extension. So basically, the product let users provide extensions, and therefore the product as such does not / cannot have the EPackage registered for these extensions. As a result these snippets get mapped to AnyType, and I am fetching the EObjects using the getEObjectToExtensionMap method of XMLResource class.

Therefore, I get a FeatureMap, and the feature inside it is an EAttribute.

Thanks,
Arati
Re: EcoreUtil.equals for xsd:list type [message #986822 is a reply to message #986819] Wed, 21 November 2012 18:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Arati,

What can I say? You have so many constraints in place you'll have to
live with exactly what you see.


On 21/11/2012 7:13 PM, Arati Rahalkar wrote:
> Hi Ed,
>
> This is part of a big product, which uses EMF 2.4.2, so seems unlikely
> that I can move to a newer version.
>
> Actually, this snippet of the XML file is part of an extension. So
> basically, the product let users provide extensions, and therefore the
> product as such does not / cannot have the EPackage registered for
> these extensions. As a result these snippets get mapped to AnyType,
> and I am fetching the EObjects using the getEObjectToExtensionMap
> method of XMLResource class.
>
> Therefore, I get a FeatureMap, and the feature inside it is an
> EAttribute.
>
> Thanks,
> Arati
Re: EcoreUtil.equals for xsd:list type [message #986849 is a reply to message #986822] Thu, 22 November 2012 01:58 Go to previous message
Arati Rahalkar is currently offline Arati Rahalkar
Messages: 12
Registered: November 2012
Junior Member
Hmm.. Ok, looks like that. Thanks Ed. At least I know why it does not work.
Previous Topic:UUID eattribute conflicts in ECoreUtil.copy
Next Topic:[CDO/SWT.Virtual] Virtual tables and CDOPrefetch
Goto Forum:
  


Current Time: Thu Sep 18 13:57:28 GMT 2014

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

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