if (parent instanceof ProjectData) { Project mParent = parent.asProject(); ProjectDatasetLink l; Iterator child = children.iterator(); while (child.hasNext()) { l = new ProjectDatasetLink(); l.link(mParent, ((DataObject) child.next()).asDataset()); objects.add(l); } } else if (parent instanceof DatasetData) { Dataset mParent = parent.asDataset(); DatasetImageLink l; Iterator child = children.iterator(); while (child.hasNext()) { l = new DatasetImageLink(); l.link(mParent, ((DataObject) child.next()).asImage()); objects.add(l); } } else if (parent instanceof CategoryGroupData) { CategoryGroup mParent = parent.asCategoryGroup(); CategoryGroupCategoryLink l; Iterator child = children.iterator(); while (child.hasNext()) { l = new CategoryGroupCategoryLink(); l.link(mParent, ((DataObject) child.next()).asCategory()); objects.add(l); }
IObject ioParent = parent.asIObject(); IObject ioChild; Iterator child = children.iterator(); while (child.hasNext()) { ioChild = ((DataObject) child.next()).asIObject(); objects.add(ModelMapper.linkParentToChild(ioChild, ioParent));
    public void addExistingObjects(DataObject parent, Set children)            throws DSOutOfServiceException, DSAccessException    {        if (parent instanceof ProjectData) {            try {                children.toArray(new DatasetData[] {});            } catch (ArrayStoreException ase) {                throw new IllegalArgumentException(                        "items can only be datasets.");            }        } else if (parent instanceof DatasetData) {            try {                children.toArray(new ImageData[] {});            } catch (ArrayStoreException ase) {                throw new IllegalArgumentException(                        "items can only be images.");            }        } else if (parent instanceof CategoryGroupData) {                try {                    children.toArray(new CategoryData[] {});                } catch (ArrayStoreException ase) {                    throw new IllegalArgumentException(                            "items can only be categories.");                }        } else if (parent instanceof CategoryData) {            try {                children.toArray(new ImageData[] {});            } catch (ArrayStoreException ase) {                throw new IllegalArgumentException(                        "items can only be images.");            }            Set cat = new HashSet(1);            cat.add(parent);            classify(children, cat);            return ;        } else            throw new IllegalArgumentException("parent object not supported");                List objects = new ArrayList();        if (parent instanceof ProjectData) {            Project mParent = parent.asProject();            ProjectDatasetLink l;            Iterator child = children.iterator();            while (child.hasNext()) {                l = new ProjectDatasetLink();                l.link(mParent, ((DataObject) child.next()).asDataset());                  objects.add(l);            }        } else if (parent instanceof DatasetData) {            Dataset mParent = parent.asDataset();            DatasetImageLink l;            Iterator child = children.iterator();            while (child.hasNext()) {                l = new DatasetImageLink();                l.link(mParent, ((DataObject) child.next()).asImage());                  objects.add(l);            }        } else if (parent instanceof CategoryGroupData) {            CategoryGroup mParent = parent.asCategoryGroup();            CategoryGroupCategoryLink l;            Iterator child = children.iterator();            while (child.hasNext()) {                l = new CategoryGroupCategoryLink();                l.link(mParent, ((DataObject) child.next()).asCategory());                  objects.add(l);            }        }        if (objects.size() != 0) {            Iterator i = objects.iterator();            IObject[] array = new IObject[objects.size()];            int index = 0;            while (i.hasNext()) {                array[index] = (IObject) i.next();                index++;            }            gateway.createObjects(array, (new PojoOptions()).map());        }     }