Check for and show invalid references before saving

Issue #463 resolved
Matthias Schoettle created an issue

Currently, if a model contains references to objects that are not contained in a resource, an exception (DanglingHREFException inside a WrappedIOException), which only says which object is referenced and not contained in a resource.

For example:

The object 'ca.mcgill.sel.ram.impl.ClassImpl@795374b8 (name: E) (partiality: none, visibility: concern) (abstract: false)' is not contained in a resource.

However, the user might have no idea where it is referenced from.

In general, the best solution would be that the validator checks for this using an OCL rule, if possible. At least, it would be great to be able to show to the user all the locations that reference objects that are not contained in a resource before allowing to save.

Comments (4)

  1. Matthias Schoettle reporter

    I was able to use the following constraint, however, I am unable to provide it in a general way for a super-class like COREModelElement:

    def: getRootContainer(m : ocl::OclElement) : Aspect = 
            let container : ocl::OclElement = m.oclContainer()
            in if (container.oclIsTypeOf(Aspect)) then container.oclAsType(Aspect) else getRootContainer(container) endif
    

    For example, I could add it to context Parameter and then inside this context write a constraint which checks whether getRootContainer(type).oclIsUndefined(). As soon as I move getRootContainer out I am unable to call it from there.

  2. Matthias Schoettle reporter

    References #463: Adds a check to find uncontained references before saving.

    In case of existing uncontained references, they are shown to the user instead of saving. The list contains a guidance to the user on where the reference is located, i.e., the object containing the reference and a (in)direct container is presented.

    → <<cset ac24d0af3904>>

  3. Matthias Schoettle reporter

    OCL rules in #456 references branch contain a getRootContainer() method that uses closure to find the top-most root container.

  4. Log in to comment