Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Constraint with EMF Framework validation([EMF Validation])
icon5.gif  Constraint with EMF Framework validation [message #894466] Mon, 09 July 2012 10:52 Go to next message
wiwa wiwa is currently offline wiwa wiwaFriend
Messages: 12
Registered: May 2012
Junior Member
hi,
I create a constrainte using the EMF Validation framework to check the duplicated name in the instance model.I want to control that every class in the model instance must have a different name.==> "name": is an attribute in each class..
So, I create a list to collect these instances.
***********************************
Quote:
public class ChekDuplicatedNames extends AbstractModelConstraint {
static List<String> groupWrt ;
.......
private void addWriter(String att){
groupWrt.add(att);
}
@Override
public IStatus validate(IValidationContext ctx) {
EObject eObj = ctx.getTarget();
EMFEventType eType = ctx.getEventType();
if (eType == EMFEventType.NULL) {
String name = null;
if (eObj instanceof Writer) {
name = ((Writer)eObj).getName();
addWriter(name);
}
....

}
...
}
}

**************************************
I'm a new user in this area and I try to do that by following the example (Example Validation General)in the Eclipse Example, but I can't achieve any result. I need other way to do it.

Please help me.
Thank you,
Re: Constraint with EMF Framework validation [message #894474 is a reply to message #894466] Mon, 09 July 2012 11:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Maybe you can just use EMF's core validation support:<br>
<blockquote><a
href="http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.Validation.html">http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.Validation.html</a><br>
</blockquote>
What you're describing is analogous to an EPackage's
UniqueClassifierNames constraint, which is implemented in
EcoreValidator like as follows:<br>
<blockquote><small>  public boolean
validateEPackage_UniqueClassifierNames(EPackage ePackage,
DiagnosticChain diagnostics, Map&lt;Object, Object&gt; context)</small><br>
<small>  {</small><br>
<small>    boolean result = true;</small><br>
<small>    List&lt;String&gt; names = new
ArrayList&lt;String&gt;();</small><br>
<small>    EList&lt;EClassifier&gt; eClassifiers =
ePackage.getEClassifiers();</small><br>
<small>    for (EClassifier eClassifier : eClassifiers)</small><br>
<small>    {</small><br>
<small>      String name = eClassifier.getName();</small><br>
<small>      if (name != null)</small><br>
<small>      {</small><br>
<small>        String key = name.replace("_", "").toUpperCase();</small><br>
<small>        int index = names.indexOf(key);</small><br>
<small>        if (index != -1)</small><br>
<small>        {</small><br>
<small>          if (diagnostics == null)</small><br>
<small>          {</small><br>
<small>            return false;</small><br>
<small>          }</small><br>
<small>          else</small><br>
<small>          {</small><br>
<small>            result = false;</small><br>
<small>            EClassifier otherEClassifier =
eClassifiers.get(index);</small><br>
<small>            String otherName = otherEClassifier.getName();</small><br>
<small>            diagnostics.add</small><br>
<small>              (createDiagnostic</small><br>
<small>                (name.equals(otherName) ? Diagnostic.ERROR
: Diagnostic.WARNING,</small><br>
<small>                 DIAGNOSTIC_SOURCE,</small><br>
<small>                 UNIQUE_CLASSIFIER_NAMES,</small><br>
<small>                 name.equals(otherName) ?
"_UI_EPackageUniqueClassifierNames_diagnostic" :
"_UI_EPackageDissimilarClassifierNames_diagnostic",</small><br>
<small>                 name.equals(otherName) ? new Object[] {
name } : new Object[] { name, otherName },</small><br>
<small>                 new Object[] { ePackage, eClassifier,
otherEClassifier },</small><br>
<small>                 context));</small><br>
<small>          }</small><br>
<small>        }</small><br>
<small>        names.add(key);</small><br>
<small>      }</small><br>
<small>      else</small><br>
<small>      {</small><br>
<small>        names.add(null);</small><br>
<small>      }</small><br>
<small>    }</small><br>
<small>    return result;</small><br>
<small>  }</small><br>
</blockquote>
<br>
<br>
<div class="moz-cite-prefix">On 09/07/2012 12:52 PM, wiwa wiwa
wrote:<br>
</div>
<blockquote cite="mid:jted53$lp2$1@xxxxxxxxe.org" type="cite">hi,
<br>
I create a constrainte using the EMF Validation framework to check
the duplicated name in the instance model.I want to control that
every class in the model instance must have a different
name.==&gt; "name": is an attribute in each class..
<br>
So, I create a list to collect these instances.
<br>
***********************************
<br>
Quote:
<br>
<blockquote type="cite">public class ChekDuplicatedNames extends
AbstractModelConstraint {
<br>
    static List&lt;String&gt; groupWrt ;
<br>
    .......
<br>
    private void addWriter(String att){
<br>
        groupWrt.add(att);
<br>
    }
<br>
    @Override
<br>
    public IStatus validate(IValidationContext ctx) {
<br>
        EObject eObj = ctx.getTarget();
<br>
        EMFEventType eType = ctx.getEventType();
<br>
        if (eType == EMFEventType.NULL) {
<br>
            String name = null;
<br>
            if (eObj instanceof Writer) {
<br>
                name = ((Writer)eObj).getName();
                                addWriter(name);             }
                 ....
<br>
<br>
        }
<br>
        ...
<br>
    }
<br>
}
<br>
</blockquote>
<br>
**************************************
<br>
I'm a new user in this area and I try to do that by following the
example (Example Validation General)in the Eclipse Example, but I
can't achieve any result. I need other way to do it.
<br>
<br>
Please help me.
<br>
Thank you,
<br>
</blockquote>
<br>
<br>
</body>
</html>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Constraint with EMF Framework validation [message #894573 is a reply to message #894474] Mon, 09 July 2012 16:14 Go to previous messageGo to next message
wiwa wiwa is currently offline wiwa wiwaFriend
Messages: 12
Registered: May 2012
Junior Member
thank you for your help.
But, how can i find the full example.
Re: Constraint with EMF Framework validation [message #894612 is a reply to message #894573] Mon, 09 July 2012 19:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
You can add a constraint to you own model and make your own example.

On 09/07/2012 6:14 PM, wiwa wiwa wrote:
> thank you for your help.
> But, how can i find the full example.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Copy and Paste from clipboard in EMF
Next Topic:How to configure the format of the XML files?
Goto Forum:
  


Current Time: Fri Mar 29 02:19:18 GMT 2024

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

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

Back to the top