Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Uniqueness not enforced by Validate(When using validate it does not check for required uniqueness)
Uniqueness not enforced by Validate [message #559905] Mon, 20 September 2010 10:30 Go to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi, I'm hoping that some-one can suggest something that I may be doing wrong, or if what I am trying is not supported. I have a schema that looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com/Unique" targetNamespace="http://example.com/Unique">
    <xs:complexType name="customerOrderType">
        <xs:attribute name="CustomerID" type="xs:string"/>
    </xs:complexType>
    <xs:element name="ordersByCustomer">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="customerOrders" type="customerOrderType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="oneCustomerOrdersforEachCustomerID">
            <xs:selector xpath="customerOrders"/>
            <xs:field xpath="@CustomerID"/>
        </xs:unique>
    </xs:element>
</xs:schema>


If I then populate it as follows:

<?xml version="1.0" encoding="UTF-8"?>
<unique:ordersByCustomer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:unique="http://example.com/Unique">
    <customerOrders xsi:type="unique:customerOrderType" CustomerID="ID1"/>
    <customerOrders xsi:type="unique:customerOrderType" CustomerID="ID1"/>
</unique:ordersByCustomer>


and then call

Diagnostician.INSTANCE.validate(object);


And the vaidation does not fail as I would expect, as the CustomerID is not unique. (This will fail validation in XMLSpy).
Re: Uniqueness not enforced by Validate [message #560006 is a reply to message #559905] Mon, 20 September 2010 17:04 Go to previous messageGo to next message
Jay Norwood is currently offline Jay NorwoodFriend
Messages: 155
Registered: July 2009
Senior Member
In the ecore model there is an ID boolean attribute. I tested setting that to true on an integer attribute in the model, and validate does detect a collision if I set two integer values the same in that case.

Here is the excerpt from the ecore model for the field. I'm testing with the emf that comes with Helios

<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
iD="true"/>

I changed it to a String attribute, and it also detected the collision, so I think you just need to enable that boolean attribute, ID, in the ecore model.

<eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"/>

Re: Uniqueness not enforced by Validate [message #560106 is a reply to message #559905] Tue, 21 September 2010 08:49 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
I'm using version 2.4.2

After importing the XSD, the eCore shows:

    <eStructuralFeatures xsi:type="ecore:EReference" name="ordersByCustomer" upperBound="-2" eType="//OrdersByCustomerType" volatile="true" transient="true" derived="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="ordersByCustomer"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>


If you use the graphical properties tab, it shows Unique=true

However it does not seem to enforce this on a validate.
Re: Uniqueness not enforced by Validate [message #629449 is a reply to message #559905] Tue, 28 September 2010 10:41 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi,

Does anyone have any more thoughts on this? Is this a bug in EMF?

Thank you

Rob
Re: Uniqueness not enforced by Validate [message #629632 is a reply to message #629449] Wed, 29 September 2010 03:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
Rob,

I'm not sure the context of your question. It should be virtually
impossible to have duplicates if they aren't allowed because the lists
check while adding so we don't check for it as part of validation...


Rob wrote:
> Hi,
>
> Does anyone have any more thoughts on this? Is this a bug in EMF?
>
> Thank you
>
> Rob
>
Re: Uniqueness not enforced by Validate [message #629686 is a reply to message #629632] Wed, 29 September 2010 09:07 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Ed, thanks for taking the time to reply.

I do not seem to be getting any restrictions when creating or adding a list, for example if I use the previously defined schema and then the following code:

OrdersByCustomerType createOrdersByCustomerType = UniqueFactory.eINSTANCE.createOrdersByCustomerType();
EList<CustomerOrderType> customerOrders = createOrdersByCustomerType.getCustomerOrders();
        
CustomerOrderType custOrderType1 = UniqueFactory.eINSTANCE.createCustomerOrderType();
custOrderType1.setCustomerID("ID1");
CustomerOrderType custOrderType2 = UniqueFactory.eINSTANCE.createCustomerOrderType();
custOrderType2.setCustomerID("ID1");
        
customerOrders.add(custOrderType1);
customerOrders.add(custOrderType2);


There is no probelm constructing the data with the duplicate ID, and I can also validate it without a problem.

Diagnostician.INSTANCE.validate(createOrdersByCustomerType);


I was expecting something some-where to stop me, either with the construction or ideally with the validation.

Thank, Rob
Re: Uniqueness not enforced by Validate [message #629774 is a reply to message #629686] Wed, 29 September 2010 14:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
Rob,

Comments below.

Rob wrote:
> Hi Ed, thanks for taking the time to reply.
>
> I do not seem to be getting any restrictions when creating or adding a
> list, for example if I use the previously defined schema and then the
> following code:
>
> OrdersByCustomerType createOrdersByCustomerType =
> UniqueFactory.eINSTANCE.createOrdersByCustomerType();
> EList<CustomerOrderType> customerOrders =
> createOrdersByCustomerType.getCustomerOrders();
> CustomerOrderType custOrderType1 =
> UniqueFactory.eINSTANCE.createCustomerOrderType();
> custOrderType1.setCustomerID("ID1");
> CustomerOrderType custOrderType2 =
> UniqueFactory.eINSTANCE.createCustomerOrderType();
> custOrderType2.setCustomerID("ID1");
> customerOrders.add(custOrderType1);
> customerOrders.add(custOrderType2);
>
>
> There is no probelm constructing the data with the duplicate ID, and I
> can also validate it without a problem.
>
> Diagnostician.INSTANCE.validate(createOrdersByCustomerType);
You're talking about uniqueness of IDs rather than uniqueness of
instances, i.e., the same object more than once in the list.
>
> I was expecting something some-where to stop me, either with the
> construction or ideally with the validation.
If you look at EObjectValidator.validate_UniqueID you'll see it's done
only checked the context of a resource.
>
> Thank, Rob
Re: Uniqueness not enforced by Validate [message #631236 is a reply to message #559905] Wed, 06 October 2010 16:16 Go to previous messageGo to next message
Rob Mising name is currently offline Rob Mising nameFriend
Messages: 118
Registered: July 2010
Senior Member
Hi Ed,

Thanks again for your help, however I'm a little confused. Are you saying that EMF does not support this case where the unique constraint is put on an attribute within an ComplexType that is then used as an element.

I can't see exactly what I'm doing that isn't a valid case. I was under the belief that the validation rule was to prevent users defining this case.

So in the XML/XSD world someone could write a chunk of XML (Obviously much larger and more complicated than my little example) and then validate it against the schema to ensure that they hadn't broken any uniqueness rules.

So in the EMF world, be able to define multiple objects, and then validate it to ensure that they again haven't broken any uniqueness rules.

I would be extremely greatful if you could elaborate, I did take a look at EObjectValidator.validate_UniqueID (and ran with the debugger) however this does nothing as the object is returning an ID of null, so got going into the code, so isn't actually checking it's contents. As I haven't editted the ecore, and just generated it from import I was not expecting any probelms.

Thanks

Rob
Re: Uniqueness not enforced by Validate [message #631255 is a reply to message #631236] Wed, 06 October 2010 17:11 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30551
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040806050805040902020100
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Rob,

Comments below.


Rob wrote:
> Hi Ed,
>
> Thanks again for your help, however I'm a little confused. Are you
> saying that EMF does not support this case where the unique constraint
> is put on an attribute within an ComplexType that is then used as an
> element.
Yes, the mapping from XML Schema to Ecore ignores things identify
constraints, like xsd:unique.
>
> I can't see exactly what I'm doing that isn't a valid case. I was
> under the belief that the validation rule was to prevent users
> defining this case.
>
> So in the XML/XSD world someone could write a chunk of XML (Obviously
> much larger and more complicated than my little example) and then
> validate it against the schema to ensure that they hadn't broken any
> uniqueness rules.
>
> So in the EMF world, be able to define multiple objects, and then
> validate it to ensure that they again haven't broken any uniqueness
> rules.
Ecore has no corresponding concept. Certainly it enforces ID uniqueness
but not XML Schema identify constraints.
>
> I would be extremely greatful if you could elaborate, I did take a
> look at EObjectValidator.validate_UniqueID (and ran with the debugger)
> however this does nothing as the object is returning an ID of null, so
> got going into the code, so isn't actually checking it's contents. As
> I haven't editted the ecore, and just generated it from import I was
> not expecting any probelms.
Things like XML Schema complex type restrictions aren't supported
either. *All *the simple type constraints are.
>
> Thanks
>
> Rob
>

--------------040806050805040902020100
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Rob,<br>
<br>
Comments below.<br>
<br>
<br>
Rob wrote:
<blockquote cite="mid:i8i784$3v4$1@news.eclipse.org" type="cite">Hi Ed,
<br>
<br>
Thanks again for your help, however I'm a little confused.  Are you
saying that EMF does not support this case where the unique constraint
is put on an attribute within an ComplexType that is then used as an
element.
<br>
</blockquote>
Yes, the mapping from XML Schema to Ecore ignores things identify
constraints, like xsd:unique.<br>
<blockquote cite="mid:i8i784$3v4$1@news.eclipse.org" type="cite"><br>
I can't see exactly what I'm doing that isn't a valid case.  I was
under the belief that the validation rule was to prevent users defining
this case.
<br>
<br>
So in the XML/XSD world someone could write a chunk of XML (Obviously
much larger and more complicated than my little example) and then
validate it against the schema to ensure that they hadn't broken any
uniqueness rules.
<br>
<br>
So in the EMF world, be able to define multiple objects, and then
validate it to ensure that they again haven't broken any uniqueness
rules.
<br>
</blockquote>
Ecore has no corresponding concept.  Certainly it enforces ID
uniqueness but not XML Schema identify constraints.<br>
<blockquote cite="mid:i8i784$3v4$1@news.eclipse.org" type="cite"><br>
I would be extremely greatful if you could elaborate, I did take a look
at EObjectValidator.validate_UniqueID (and ran with the debugger)
however this does nothing as the object is returning an ID of null, so
got going into the code, so isn't actually checking it's contents.  As
I haven't editted the ecore, and just generated it from import I was
not expecting any probelms.
<br>
</blockquote>
Things like XML Schema complex type restrictions aren't supported
either.  <b>All </b>the simple type constraints are.<br>
<blockquote cite="mid:i8i784$3v4$1@news.eclipse.org" type="cite"><br>
Thanks
<br>
<br>
Rob
<br>
<br>
</blockquote>
</body>
</html>

--------------040806050805040902020100--
Previous Topic:Why i cannot see the icons from a metamodel instance at eclipse with EMF
Next Topic:[CDO] Is it possible to implement ReadAccess and WriteAccess handlers in one class?
Goto Forum:
  


Current Time: Sun Oct 20 19:18:50 GMT 2019

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

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

Back to the top