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 |
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 |
Ed Merks Messages: 33216 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: EcoreUtil.equals for xsd:list type [message #986617 is a reply to message #986594] |
Wed, 21 November 2012 08:24 |
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 |
Ed Merks Messages: 33216 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: EcoreUtil.equals for xsd:list type [message #986819 is a reply to message #986814] |
Wed, 21 November 2012 18:13 |
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 |
Ed Merks Messages: 33216 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Goto Forum:
Current Time: Thu Sep 19 03:59:52 GMT 2024
Powered by FUDForum. Page generated in 0.05059 seconds
|