[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.ocl] Re: OCLConsole Saving Error: The 'no duplicates' constraint is violated

Ed,

Thanks for the response.  I should have elaborated.

I have simply created an ecore model, generated the code, and run the generated editor. I have also included the OCL Interpreter that Christian wrote.

Within the OCLConsolePage, there is an input window (SourceViewer) and an output window (Read-only TextViewer).

When I enter a valid OCL expression and hit Enter, the OCL expression is parsed and evaluated, and the results are outputted in the TextViewer. There is a button to save the OCL Expression (lastExpression variable) to the default persistence mechanism, an XMI file. After I select the file location, the Error dialog pops up. I have tried many expressions such as:

self.title
self.question->size() > 1

which are valid OCL expressions.

My understanding is that the OCL expression that I enter is parsed into the AST (OCL is an ecore model), and that this AST structure is persisted, just like any ecore model.

Thanks for the heads up about an EList's uniqueness constraint.

It is interesting that Christian put this comment in his code:
// add my expression as the first root, because I already contain
// variables and EPackages defining dynamically-generated types
     getContents().add(0, expr);

When I debug, it seems that getContents() already has 3 strucutres in it. Do you know why? Typically when I save an instance of an ecore model that I have created it is the only strucutre in the file. The EMF book also says to use this code to do

getContents().add(expr)

I presume that OCL has some special requirements and that is why there are already 3 structures. Any ideas here?

When I modify the code to
getContents().add(expr)
I don't get the error, but the OCL expression can not be loaded from the file.


Any help is appreciated.

Regards,
Richard Catlin





On 9/15/2009 10:49 PM, Ed Willink wrote:
Hi Richard

You provide no clues as to what you are saving, so I can do little more than elaborate the message, which occurs when the same EObject is added
more than once to an EList that enforces unique content.


So for some reason you are adding a duplicate expression; most likely
a singleton value such as (Ocl)Invalid that may have arisen more than once.

You need to investigate waht is duplicated and where each one came from.

When you tell us how to reproduce the problem we may be able to improve the error message.

    Regards

        Ed Willink


Richard Catlin wrote:
I am getting this error when I try to save an OCL expression to an xmi file.

public void setOCLExpression(OCLExpression<Object> expr) {
// add my expression as the first root, because I already contain
// variables and EPackages defining dynamically-generated types
    getContents().add(0, expr);
}

Exception:
"Error Saving OCL Expression, The 'no duplicates' constraint is violated"

Any help is appreciated.

Regards,
Richard Catlin