Diagnostic dia = Diagnostician.INSTANCE.validate(eObject);
to get the validation result of an object. However, using the getMessage method of Diagnostic class only gives me a fixed error message (like "constraint violcation occured at the element //@elem.0). Now that my question is how to get the full information of the element at which the violation occured, for example, the name or properties of that element?
Sorry if I repost a raised question but I tried to find the answer without any result.
Best regards.
On 28/02/2012 09:26, Capi Tali wrote:
> Hi all,
> I use Diagnostic dia = Diagnostician.INSTANCE.validate(eObject); to
> get the validation result of an object. However, using the getMessage
> method of Diagnostic class only gives me a fixed error message (like
> "constraint violcation occured at the element //@elem.0). Now that my
> question is how to get the full information of the element at which
> the violation occured, for example, the name or properties of that
> element? Sorry if I repost a raised question but I tried to find the
> answer without any result. Best regards.
Hi Ed,
Firstly, thank you for your answer. In the tutorial I see "This must be activated explicitly using an EValidator that is aware of the ValidationDelegateExtension extended API". I understand this as we have to activate the customization support within the EMF generated code. My problem is that in my application, the metamodel and its models are generated which means that I only have an ECORE meta-model without the EMF generated code for it. I wonder how we can deal with this situation? I try to register the Validator in a triggered event before the metamodel is generated but nothing happened.
Best regards.
EMF model generation uses JMerge to preserve user customisations so you
can just do:
/**
* <!-- begin-user-doc -->
* The <b>Validator</b> for the model.
* @extends
org.eclipse.ocl.examples.xtext.oclinecore.validation.OCLinEcoreEObjectValidator
* <!-- end-user-doc -->
* @see company.CompanyPackage
*/
public class CompanyValidator extends OCLinEcoreEObjectValidator {
The Help Documentation is wrong; update in progress. There is no need
for @generate NOT; just an @extends within the user-doc section.
Regards
Ed Willink
On 28/02/2012 12:54, Capi Tali wrote:
> Hi Ed,
> Firstly, thank you for your answer. In the tutorial I see "This must
> be activated explicitly using an EValidator that is aware of the
> ValidationDelegateExtension extended API". I understand this as we
> have to activate the customization support within the EMF generated
> code. My problem is that in my application, the metamodel and its
> models are generated which means that I only have an ECORE meta-model
> without the EMF generated code for it. I wonder how we can deal with
> this situation? I try to register the Validator in a triggered event
> before the metamodel is generated but nothing happened. Best regards.
Hi Ed,
Maybe you didn't understand my poor explanation. I have an ECORE metamodel embedded with OCL rule without EMF generated code. Is there anyway to register the OCLinEcoreEObjectValidator in order to modify the validation message?
Unfortunately, in the Indigo release, EMF does not support this
customization and so must be activated by explicitly using an EValidator
that is aware of the ValidationDelegateExtension extended API. This is
available by using the OCLinEcoreEObjectValidator, which you may install
globally by:
|EValidator.Registry.INSTANCE.put(null, new OCLinEcoreEObjectValidator());
|
Doesn't this work? Once you start validating debug where your EValidator
came from.
Regards
Ed Willink
On 28/02/2012 14:16, Capi Tali wrote:
> Hi Ed,
> Maybe you didn't understand my poor explanation. I have an ECORE
> metamodel embedded with OCL rule without EMF generated code. Is there
> anyway to register the OCLinEcoreEObjectValidator in order to modify
> the validation message?