Skip to main content



      Home
Home » Modeling » EMF » Custom validation for ID attribute
Custom validation for ID attribute [message #1386504] Tue, 17 June 2014 20:02 Go to next message
Eclipse UserFriend
Hi everyone,

I am trying to customize the validation for every ID attribute (of every EClass) but I couldn't find the correct way to do it. I need this in order to validate the use of illegal characters like "$", "&", " " or "#".

Class A
  Att1 : ID = true
  Att2 : ID = false

Class B
  Att3 : ID = true
  Att4 : ID = false


In the above example, Att1 (Class A) and Att3 (Class B) should be validated with the custom validator.

Is this possible to do? Or anyone knows any way to do this or a better approach than custom validation?

Thanks in advance!
Re: Custom validation for ID attribute [message #1386526 is a reply to message #1386504] Wed, 18 June 2014 02:36 Go to previous messageGo to next message
Eclipse UserFriend
Agustin,

You can define your own EDataType with a constraint:

http://help.eclipse.org/kepler/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.Validation.html

You could also make use of an extended metadata annotation as created by
org.eclipse.emf.ecore.util.ExtendedMetaData.setPatternFacet(EDataType,
List<String>) to define the pattern of valid IDs on your EDataType (so
that you don't have to write the constraint logic yourself).


On 18/06/2014 2:02 AM, Agustin Vosou wrote:
> Hi everyone,
>
> I am trying to customize the validation for every ID attribute (of
> every EClass) but I couldn't find the correct way to do it. I need
> this in order to validate the use of illegal characters like "$", "&",
> " " or "#".
>
> Class A
> Att1 : ID = true
> Att2 : ID = false
>
> Class B
> Att3 : ID = true
> Att4 : ID = false
>
>
> In the above example, Att1 (Class A) and Att3 (Class B) should be
> validated with the custom validator.
>
> Is this possible to do? Or anyone knows any way to do this or a better
> approach than custom validation?
>
> Thanks in advance!
Re: Custom validation for ID attribute [message #1386527 is a reply to message #1386526] Wed, 18 June 2014 02:37 Go to previous messageGo to next message
Eclipse UserFriend
Or perhaps just use the ID EDataType from XMLType.ecore if that data
type's constraints match your needs.


On 18/06/2014 8:36 AM, Ed Merks wrote:
> Agustin,
>
> You can define your own EDataType with a constraint:
>
> http://help.eclipse.org/kepler/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.Validation.html
>
>
> You could also make use of an extended metadata annotation as created
> by
> org.eclipse.emf.ecore.util.ExtendedMetaData.setPatternFacet(EDataType,
> List<String>) to define the pattern of valid IDs on your EDataType (so
> that you don't have to write the constraint logic yourself).
>
>
> On 18/06/2014 2:02 AM, Agustin Vosou wrote:
>> Hi everyone,
>>
>> I am trying to customize the validation for every ID attribute (of
>> every EClass) but I couldn't find the correct way to do it. I need
>> this in order to validate the use of illegal characters like "$",
>> "&", " " or "#".
>>
>> Class A
>> Att1 : ID = true
>> Att2 : ID = false
>>
>> Class B
>> Att3 : ID = true
>> Att4 : ID = false
>>
>>
>> In the above example, Att1 (Class A) and Att3 (Class B) should be
>> validated with the custom validator.
>>
>> Is this possible to do? Or anyone knows any way to do this or a
>> better approach than custom validation?
>>
>> Thanks in advance!
>
Re: Custom validation for ID attribute [message #1386635 is a reply to message #1386527] Wed, 18 June 2014 18:46 Go to previous messageGo to next message
Eclipse UserFriend
Thank you Ed,

I think I am going for the second option and test if that data type's constraints fit my needs.

Regards,
Agustin.
Re: Custom validation for ID attribute [message #1387075 is a reply to message #1386635] Mon, 23 June 2014 18:58 Go to previous messageGo to next message
Eclipse UserFriend
After testing the ID EDataType from XMLType.ecore and it's constraints, I decided to go for the first option Ed gave me... So I've defined the following EDataType:

  <eClassifiers xsi:type="ecore:EDataType" name="ID" instanceClassName="java.lang.String">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="ID"/>
      <details key="baseType" value="java.lang.String"/>
      <details key="pattern" value="[a-zA-Z0-9]+"/>
    </eAnnotations>
  </eClassifiers>


As you can see, I've used an ExtendedMetadata annotation to define the accepted values with a pattern.

Thank you very much for your help and time.

Regards,
Agustin.
Re: Custom validation for ID attribute [message #1387088 is a reply to message #1387075] Tue, 24 June 2014 00:58 Go to previous message
Eclipse UserFriend
Agustin,

The pattern annotation is quite useful. Thanks for sharing your results.

On 24/06/2014 12:58 AM, Agustin Vosou wrote:
> After testing the ID EDataType from XMLType.ecore and it's
> constraints, I decided to go for the first option Ed gave me... So
> I've defined the following EDataType:
>
>
> <eClassifiers xsi:type="ecore:EDataType" name="ID"
> instanceClassName="java.lang.String">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="ID"/>
> <details key="baseType" value="java.lang.String"/>
> <details key="pattern" value="[a-zA-Z0-9]+"/>
> </eAnnotations>
> </eClassifiers>
>
>
> As you can see, I've used an ExtendedMetadata annotation to define the
> accepted values with a pattern.
>
> Thank you very much for your help and time.
>
> Regards,
> Agustin.
Previous Topic:[CDO] Collection returns contains = false for Query loaded object.
Next Topic:Command grouping in CommandStack
Goto Forum:
  


Current Time: Thu Mar 20 10:03:44 EDT 2025

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

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

Back to the top