Hi Tom,

> -----Original Message-----
> From: Tom Morris [mailto:[EMAIL PROTECTED]
> 
> On Nov 19, 2007 2:07 PM, Sérgio Lopes <[EMAIL PROTECTED]> wrote:
> >
> > the method [...] getElement(List<String> path, Object namespace)
> > does not work if the root of path starts at the same level as the
> > namespace.
> > (...)
> > I think it would be useful to support the example above. It would enable
> > searching elements in models (top-level namespaces) providing a full
> > path obtained with getPathList(). Can we support that?
> 
> I think a better way to allow this would be to allow a null namespace
> argument to signify the root of the repository.
> 

Can we add the code for this, or (I think it is better) add a new method
that searches in all roots of the current project?

I have implemented this method in ModelManagementHelper (see attach), but I
found one difficulty. Currently it is based on
modelImpl.getFacade().getRootElements() to get all root elements in the UML
repository, but this includes all available profiles that are not part of
the current project (e.g. the UML Profile for Java). So it slows down the
search unnecessarily.
I've tried with ProjectManager.getManager().getCurrentProject().getRoots()
but it only returns user roots, i.e. no profile roots.
Which is the best way to get all roots in the current project?

Sergio.



/**
     * This method searches all roots for the element that matches the received
     * full-path. 
     * 
     * @param fullPath the full-path necessary to find the element
     * @return the element found
     */
    public Object findElement (List<String> fullPath) {
        if (fullPath == null || fullPath.isEmpty()) {
            return null;
        }
        Object element = null;
        for (Object root : modelImpl.getFacade().getRootElements()) {
            if (((ModelElement) root).getName().equals(fullPath.get(0))) {
                    element = root;
                    if (root instanceof Namespace && fullPath.size() > 1) {
                    element = getElement(fullPath.subList(1, fullPath.size()),
                            root);
                    }
                    if (element != null) {
                    break;
                }
            }
        }
        return element;
    }


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to