views:

18

answers:

1

Hello,

I found nothing how to validate an ecore model outside of eclipse. Does someone know how to do this?

A: 

Here is the skeleton of some code I've used to validate an EMF model outside of Eclipse:

EValidator.Registry.INSTANCE.put(YourPackage.eINSTANCE, new YourValidator());

BasicDiagnostic diagnostics = new BasicDiagnostic();
boolean valid = true;
for (EObject eo : yourResource.getContents())
{
    Map<Object, Object> context = new HashMap<Object, Object>();
    valid &= Diagnostician.INSTANCE.validate(eo, diagnostics, context);
}

There is more customization you can do, but I hope that helps get you started.

ChrisH
thanks for the answer. this validates the constraints defined. however, the constraint that an ID is unique throughout the document is not validated. do you have any leads on this?
simonh
I don't know all the ins and outs of EMF validation, so take this as a guess. Perhaps you can put that constraint check into YourValidator.
ChrisH