}
} else if (parent instanceof CategoryGroup) { if (!(child instanceof Category)) throw new IllegalArgumentException("Child not valid."); CategoryGroup p = (CategoryGroup) parent; Category d = (Category) child; CategoryGroupCategoryLink link; Iterator it = d.iterateCategoryGroupLinks(); while (it.hasNext()) { link = (CategoryGroupCategoryLink) it.next(); if (p.getId().equals(link.parent().getId())) p.addCategoryGroupCategoryLink(link, false); } } else if (parent instanceof Dataset) { if (!(child instanceof Image)) throw new IllegalArgumentException("Child not valid."); Dataset p = (Dataset) parent; Image d = (Image) child; DatasetImageLink link; Iterator it = d.iterateDatasetLinks(); while (it.hasNext()) { link = (DatasetImageLink) it.next(); if (p.getId().equals(link.parent().getId())) p.addDatasetImageLink(link, false); } } else if (parent instanceof Category) { if (!(child instanceof Image)) throw new IllegalArgumentException("Child not valid."); Category p = (Category) parent; Image d = (Image) child; CategoryImageLink link; Iterator it = d.iterateCategoryLinks(); while (it.hasNext()) { link = (CategoryImageLink) it.next(); if (p.getId().equals(link.parent().getId())) p.addCategoryImageLink(link, false); } }
    public static void linkParentToChild(IObject child, IObject parent)    {        if (parent == null) return;        if (child == null) throw new IllegalArgumentException("Child cannot" +                                "be null.");        if (parent instanceof Project) {            if (!(child instanceof Dataset))                throw new IllegalArgumentException("Child not valid.");            Project p = ((Project) parent);            Dataset d = ((Dataset) child);            Set links = d.findProjectDatasetLink(p);            if (links != null) {                Iterator i = links.iterator();                int j = 0;                                while (i.hasNext()) {                    System.out.println("creation: "+j);                    p.addProjectDatasetLink((ProjectDatasetLink)  i.next(), false);                }            }            //((ProjectData) parent).getDatasets().add(child);           // (parent.asProject()).linkDataset(child.asDataset());        }     }