Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Custom validation for ID attribute
Custom validation for ID attribute [message #1386504] Wed, 18 June 2014 00:02 Go to next message
Agustin Vosou is currently offline Agustin VosouFriend
Messages: 5
Registered: March 2014
Junior Member
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 06:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom validation for ID attribute [message #1386527 is a reply to message #1386526] Wed, 18 June 2014 06:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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!
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Custom validation for ID attribute [message #1386635 is a reply to message #1386527] Wed, 18 June 2014 22:46 Go to previous messageGo to next message
Agustin Vosou is currently offline Agustin VosouFriend
Messages: 5
Registered: March 2014
Junior Member
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 22:58 Go to previous messageGo to next message
Agustin Vosou is currently offline Agustin VosouFriend
Messages: 5
Registered: March 2014
Junior Member
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 04:58 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
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.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] Collection returns contains = false for Query loaded object.
Next Topic:Command grouping in CommandStack
Goto Forum:
  


Current Time: Tue Apr 23 09:24:48 GMT 2024

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

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

Back to the top