| some suggestion about validation [message #401224] |
Fri, 19 May 2006 03:50  |
Eclipse User |
|
|
|
hi all,
I found some extended validation support from ExtendedMetaData, EDataType
will profit from it. so each column in table have to define a EDataType to
add facet to column. it will drive me mad. Is it possible to add facet
info to EAttribute?
EObjectValidator.DynamicEDataTypeValidator seemed to be able to do
suchthing, how to make generated code call it?
In EMF validation overview, a constraint validation method could be
generated, it is another way to define validation info from ecore. but I
still found it cound not work on EAttribute. btw, it will be a pleasure if
condition code could be specified in annotion like this:
<xsd:complexType name="Item">
<xsd:annotation>
<xsd:appinfo
source="http://www.eclipse.org/emf/2002/Ecore/constraints"
ecore:key="ValidShipDate">
"US".equals(getCountry()) && getState() == null
</xsd:appinfo>
</xsd:annotation>
...
</xsd:complexType>
best regards,
steeven
|
|
|
| Re: some suggestion about validation [message #401226 is a reply to message #401224] |
Fri, 19 May 2006 08:52   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------090101060202030905030904
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Steeven,
ExtendedMetaData follows the XML Schema model where facet constraints
are defined on the types not on the elements/attributes. I'm not so
keen on extending such support beyond what XML Schema supports to create
something even more complex than XML Schema. The validator can be
invoked by using Diagnostician.INSTANCE's validate methods...
You can define constraints on an EClass including defining invariant
operations within a operation body and it's now possible to define
operations within the schema (where the notation <%x.y.z.QualifiedName%>
is used to specify qualified names to be imported in the generated code;
of course the < and > are escaped in the XML). This example below will
validate that the value of the x attribute is >= 0.0.:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:constraint="http://www.example.org/constraint"
ecore:nsPrefix="constraint" ecore:package="org.example.constraint"
targetNamespace="http://www.example.org/constraint">
<xsd:import namespace="http://www.eclipse.org/emf/2002/Ecore"
schemaLocation="platform:/plugin/org.eclipse.emf.ecore/model/Ecore.xsd "/>
<xsd:element ecore:ignore="true" name="ConstrainedClass"
type="constraint:ConstrainedClass"/>
<xsd:complexType name="ConstrainedClass">
<xsd:annotation>
<xsd:appinfo ecore:key="operations"
source="http://www.eclipse.org/emf/2002/Ecore">
<operation name="invariant" type="ecore:EBoolean">
<parameter name="diagnostics" type="ecore:EDiagnosticChain"/>
<parameter name="context" type="ecore:EMap"/>
<body> if (getX() < 0.0)
{
if (diagnostics != null)
{
diagnostics.add(
new <%org.eclipse.emf.common.util.BasicDiagnostic%> ;(
<%org.eclipse.emf.common.util.Diagnostic%>.ERR OR,
<%org.example.constraint.util.ConstraintValidator%&am p;gt;.DIAGNOSTIC_SOURCE,
<%org.example.constraint.util.ConstraintValidator%&am p;gt;.CONSTRAINED_CLASS__INVARIANT,
<%org.eclipse.emf.ecore.plugin.EcorePlugin%>.I NSTANCE.getString(
"_UI_GenericInvariant_diagnostic",
new Object[] {
"invariant",
<%org.eclipse.emf.ecore.util.EObjectValidator%> ;.getObjectLabel(this,
context)}),
new Object [] { this }));
}
return false;
}
return true;</body>
</operation>
</xsd:appinfo>
</xsd:annotation>
<xsd:attribute name="x" type="ecore:EFloat"/>
</xsd:complexType>
</xsd:schema>
Steeven wrote:
> hi all,
>
> I found some extended validation support from ExtendedMetaData,
> EDataType will profit from it. so each column in table have to define
> a EDataType to add facet to column. it will drive me mad. Is it
> possible to add facet info to EAttribute?
>
> EObjectValidator.DynamicEDataTypeValidator seemed to be able to do
> suchthing, how to make generated code call it?
>
> In EMF validation overview, a constraint validation method could be
> generated, it is another way to define validation info from ecore. but
> I still found it cound not work on EAttribute. btw, it will be a
> pleasure if condition code could be specified in annotion like this:
> <xsd:complexType name="Item">
> <xsd:annotation>
> <xsd:appinfo
> source="http://www.eclipse.org/emf/2002/Ecore/constraints"
> ecore:key="ValidShipDate">
> "US".equals(getCountry()) && getState() == null
> </xsd:appinfo>
> </xsd:annotation>
> ...
> </xsd:complexType>
>
>
> best regards,
> steeven
>
--------------090101060202030905030904
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Steeven,<br>
<br>
ExtendedMetaData follows the XML Schema model where facet constraints
are defined on the types not on the elements/attributes.
|
|
|
|
| Re: some suggestion about validation [message #401265 is a reply to message #401263] |
Sat, 20 May 2006 12:50  |
Eclipse User |
|
|
|
Steeven,
I could imagine something more stylized, perhaps even using OCL, but
there's nothing like that to help you today. Feel free to open a
feature request. We likely won't have time to consider it for a while...
steeven wrote:
> merks,
>
> thanks for your reply first.
>
> wrote such a validation method in annotation will be too complex, why
> not just make make the user input a boolean validate expression in
> value field? or input some lines of code to generate a method that
> return boolean.
>
> here is the example in ecore, same in schema:
> <genAnnotations
> source="Source=http://www.eclipse.org/emf/2002/Ecore/ValidationExpression">
>
> <details key="validateA" value="getQty1() != getQty2()"/>
> </genAnnotations>
> <genAnnotations
> source="Source=http://www.eclipse.org/emf/2002/Ecore/ValidationCodes">
> <details key="validateB"
> value="...
...
if(...) return false;
"/>
> </genAnnotations>
>
> generated method should like this:
> validateA(){
> ...
> if(getQty1() != getQty2()){
> ... }
> }
> validateB(){
> ...
> if(callValidateBCodes()){
> ...
> }
> }
>
>
> best regards,
> steeven
> }
>
> }
>
|
|
|
Powered by
FUDForum. Page generated in 0.03493 seconds