|
Re: Constraint with EMF Framework validation [message #894474 is a reply to message #894466] |
Mon, 09 July 2012 11:05 |
Ed Merks Messages: 33217 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<Object, Object> context)</small><br>
<small> {</small><br>
<small> boolean result = true;</small><br>
<small> List<String> names = new
ArrayList<String>();</small><br>
<small> EList<EClassifier> 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.==> "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<String> 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/
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02791 seconds