Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Validation constraints on annotated Java
Validation constraints on annotated Java [message #420870] Tue, 15 July 2008 12:43 Go to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Hi,

I tried following the tutorial on the EMF Validation framework at
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/references/overview/EMF.Validation.html

I created a dymmy project based on the annotated Java Library example and
annotated my Library as follows;


/**
* @model
annotation="http://www.eclipse.org/emf/2002/Ecore
constraints='NonNegativeQuantity ValidShipDate'"

*/
public interface Library extends EObject
{
/**
* @model
*/
String getName();

/**
* Sets the value of the '{@link model.Library#getName <em>Name</em>}'
attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Name</em>' attribute.
* @see #getName()
* @generated
*/
void setName(String value);

/**
* @model type="Writer" containment="true"
*/
EList getWriters();

/**
* @model type="Book" containment="true"
*/
EList getBooks();

/**
* @model
*/
boolean hasUSState(
DiagnosticChain diagnostics,
Map context);

}


This leads to a single validator for the whole model being generated ( not
one per interface ). Also there is nothing generated for the constraints
that I can see.

Is this what is meant to occur now? i.e. If I want to do something special
I just override methods in the single package level validator?

Thanks
Re: Validation constraints on annotated Java [message #420871 is a reply to message #420870] Tue, 15 July 2008 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-6Q0hJF0iPQMxaNVTm/EU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, JF,

That is correct. All of the constraints in your package are generated
into a single validator class (like the single package, factory, switch,
adapter factory, etc.).

Just fill in the TODOs in the methods in your generated validator and
remember to mark them @generated NOT

HTH,

Christian

On Tue, 2008-07-15 at 12:43 +0000, JF wrote:

> Hi,
>
> I tried following the tutorial on the EMF Validation framework at
> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/references/overview/EMF.Validation.html
>
> I created a dymmy project based on the annotated Java Library example and
> annotated my Library as follows;
>
>
> /**
> * @model
> annotation="http://www.eclipse.org/emf/2002/Ecore
> constraints='NonNegativeQuantity ValidShipDate'"
>
> */
> public interface Library extends EObject
> {
> /**
> * @model
> */
> String getName();
>
> /**
> * Sets the value of the '{@link model.Library#getName <em>Name</em>}'
> attribute.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @param value the new value of the '<em>Name</em>' attribute.
> * @see #getName()
> * @generated
> */
> void setName(String value);
>
> /**
> * @model type="Writer" containment="true"
> */
> EList getWriters();
>
> /**
> * @model type="Book" containment="true"
> */
> EList getBooks();
>
> /**
> * @model
> */
> boolean hasUSState(
> DiagnosticChain diagnostics,
> Map context);
>
> }
>
>
> This leads to a single validator for the whole model being generated ( not
> one per interface ). Also there is nothing generated for the constraints
> that I can see.
>
> Is this what is meant to occur now? i.e. If I want to do something special
> I just override methods in the single package level validator?
>
> Thanks
>

--=-6Q0hJF0iPQMxaNVTm/EU
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, JF,<BR>
<BR>
That is correct.&nbsp; All of the constraints in your package are generated into a single validator class (like the single package, factory, switch, adapter factory, etc.).<BR>
<BR>
Just fill in the TODOs in the methods in your generated validator and remember to mark them @generated NOT<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
On Tue, 2008-07-15 at 12:43 +0000, JF wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hi, </FONT>

<FONT COLOR="#000000">I tried following the tutorial on the EMF Validation framework at </FONT>
<FONT COLOR="#000000"><A HREF=" http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/references/overview/EMF.Validation.html"> http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/references/overview/EMF.Validation.html</A></FONT>

<FONT COLOR="#000000">I created a dymmy project based on the annotated Java Library example and </FONT>
<FONT COLOR="#000000">annotated my Library as follows;</FONT>


<FONT COLOR="#000000">/**</FONT>
<FONT COLOR="#000000"> * @model </FONT>
<FONT COLOR="#000000"> annotation=&quot;<A HREF="http://www.eclipse.org/emf/2002/Ecore">http://www.eclipse.org/emf/2002/Ecore</A> </FONT>
<FONT COLOR="#000000"> constraints='NonNegativeQuantity ValidShipDate'&quot;</FONT>

<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000">public interface Library extends EObject</FONT>
<FONT COLOR="#000000">{</FONT>
<FONT COLOR="#000000"> /**</FONT>
<FONT COLOR="#000000"> * @model</FONT>
<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000"> String getName();</FONT>

<FONT COLOR="#000000"> /**</FONT>
<FONT COLOR="#000000"> * Sets the value of the '{@link model.Library#getName &lt;em&gt;Name&lt;/em&gt;}' </FONT>
<FONT COLOR="#000000">attribute.</FONT>
<FONT COLOR="#000000"> * &lt;!-- begin-user-doc --&gt;</FONT>
<FONT COLOR="#000000"> * &lt;!-- end-user-doc --&gt;</FONT>
<FONT COLOR="#000000"> * @param value the new value of the '&lt;em&gt;Name&lt;/em&gt;' attribute.</FONT>
<FONT COLOR="#000000"> * @see #getName()</FONT>
<FONT COLOR="#000000"> * @generated</FONT>
<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000"> void setName(String value);</FONT>

<FONT COLOR="#000000"> /**</FONT>
<FONT COLOR="#000000"> * @model type=&quot;Writer&quot; containment=&quot;true&quot;</FONT>
<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000"> EList getWriters();</FONT>

<FONT COLOR="#000000"> /**</FONT>
<FONT COLOR="#000000"> * @model type=&quot;Book&quot; containment=&quot;true&quot;</FONT>
<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000"> EList getBooks();</FONT>
<FONT COLOR="#000000"> </FONT>
<FONT COLOR="#000000"> /**</FONT>
<FONT COLOR="#000000"> * @model</FONT>
<FONT COLOR="#000000"> */</FONT>
<FONT COLOR="#000000"> boolean hasUSState(</FONT>
<FONT COLOR="#000000"> DiagnosticChain diagnostics, </FONT>
<FONT COLOR="#000000"> Map context);</FONT>

<FONT COLOR="#000000">}</FONT>


<FONT COLOR="#000000">This leads to a single validator for the whole model being generated ( not </FONT>
<FONT COLOR="#000000">one per interface ). Also there is nothing generated for the constraints </FONT>
<FONT COLOR="#000000">that I can see.</FONT>

<FONT COLOR="#000000">Is this what is meant to occur now? i.e. If I want to do something special </FONT>
<FONT COLOR="#000000">I just override methods in the single package level validator?</FONT>

<FONT COLOR="#000000">Thanks</FONT>

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-6Q0hJF0iPQMxaNVTm/EU--
Re: Validation constraints on annotated Java [message #420872 is a reply to message #420871] Tue, 15 July 2008 12:55 Go to previous messageGo to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Thanks...

So the

@model annotation="http://www.eclipse.org/emf/2002/Ecore
constraints='NonNegativeQuantity ValidShipDate'"


stuff is obsolete? - I don't get a Validator for the annotated class in
the generated util directory, with a method per constraint name?

What is the relationship of this with the validation framework?
Re: Validation constraints on annotated Java [message #420874 is a reply to message #420872] Tue, 15 July 2008 13:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

--=-o4/ozQ4W7jNapWpDdTXy
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, JF,

These annotations aren't obsolete. As far as I know, you should be
getting a validator in your model's *.util package. Perhaps Ed would be
able to advise on why this doesn't seem to be working.

This *is* the intrinsic (generative) validation framework provided by
the EMF Core component. The EMF Validation Framework component (the
separate one) provides an altogether different solution based on
contribution of constraints externally to the model definition.

Cheers,

Christian

On Tue, 2008-07-15 at 12:55 +0000, JF wrote:

> Thanks...
>
> So the
>
> @model annotation="http://www.eclipse.org/emf/2002/Ecore
> constraints='NonNegativeQuantity ValidShipDate'"
>
>
> stuff is obsolete? - I don't get a Validator for the annotated class in
> the generated util directory, with a method per constraint name?
>
> What is the relationship of this with the validation framework?
>

--=-o4/ozQ4W7jNapWpDdTXy
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.0">
</HEAD>
<BODY>
Hi, JF,<BR>
<BR>
These annotations aren't obsolete.&nbsp; As far as I know, you should be getting a validator in your model's *.util package.&nbsp; Perhaps Ed would be able to advise on why this doesn't seem to be working.<BR>
<BR>
This *is* the intrinsic (generative) validation framework provided by the EMF Core component.&nbsp; The EMF Validation Framework component (the separate one) provides an altogether different solution based on contribution of constraints externally to the model definition.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
On Tue, 2008-07-15 at 12:55 +0000, JF wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Thanks...</FONT>

<FONT COLOR="#000000">So the</FONT>

<FONT COLOR="#000000">@model annotation=&quot;<A HREF="http://www.eclipse.org/emf/2002/Ecore">http://www.eclipse.org/emf/2002/Ecore</A> </FONT>
<FONT COLOR="#000000"> constraints='NonNegativeQuantity ValidShipDate'&quot;</FONT>


<FONT COLOR="#000000">stuff is obsolete? - I don't get a Validator for the annotated class in </FONT>
<FONT COLOR="#000000">the generated util directory, with a method per constraint name?</FONT>

<FONT COLOR="#000000">What is the relationship of this with the validation framework?</FONT>

</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-o4/ozQ4W7jNapWpDdTXy--
Re: Validation constraints on annotated Java [message #420875 is a reply to message #420874] Tue, 15 July 2008 13:09 Go to previous messageGo to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Thanks Christian,

I don't seem to be getting the ***Validator class generated.

I started with the Empty EMF Project wizard, copied across the Java
interfaces from the library example, added the invariant method and
constraint annotation from the tutorial to the Library interface, as per
the code I posted, and nothing is being generated ...

BTW, I don't want to use the annotated Java, I would prefer to add
annotations directly to my EClass model which I extract from somewhere
else, I was trying to find out what "shape" the annotations would look
like in the ecore model, but ofcourse these don't seem to be generated
either. I'd be grateful of any hints, thanks...
Re: Validation constraints on annotated Java [message #420876 is a reply to message #420875] Tue, 15 July 2008 13:47 Go to previous messageGo to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Hi,

It seems to have been a problem with whitespace or new lines during the
annotation parsing, as I now get code for the constraints, though always
in the single ***Validator class in the generated util directory. My
source code level is antediluvian at 1.4 , so is that a possibel problem?
Re: Validation constraints on annotated Java [message #420878 is a reply to message #420876] Tue, 15 July 2008 13:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
JF,

It's supposed to generate a single validator. That validator traverses
the model hierarchy to enforce each constraint. There are also
invariants you can define that are generated as methods on the actual
instance classes...


JF wrote:
> Hi,
>
> It seems to have been a problem with whitespace or new lines during
> the annotation parsing, as I now get code for the constraints, though
> always in the single ***Validator class in the generated util
> directory. My source code level is antediluvian at 1.4 , so is that a
> possibel problem?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Validation constraints on annotated Java [message #420884 is a reply to message #420878] Tue, 15 July 2008 15:27 Go to previous message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Thanks Ed and Christian,

I was just expecting there to be another class generated from the
tutorial.
Previous Topic:EReference Overloading and genmodel
Next Topic:How to modify entries the PropertySheet?
Goto Forum:
  


Current Time: Thu Apr 25 19:23:34 GMT 2024

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

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

Back to the top