/** * Converts a set of model managed objects and all the objects they reference to a collection of * EObjects. * * @param objects the model objects to convert, also the references/children are converted * @return the created EObjects */ public List<EObject> convert(final List<Object> objects) { doBaseActions(objects); // the process creates the new target objects and then converts the content // this multi-step process prevents stack overflow with large object graphs final List<EObject> result = new ArrayList<EObject>(); Check.isNotNullArgument(objects, "objects"); // $NON-NLS-1$ for (final Object object : objects) { result.add(createTarget(object)); } while (!toConvert.isEmpty()) { final ArrayList<Object> beingConverted = new ArrayList<Object>(toConvert); toConvert.clear(); for (Object object : beingConverted) { convertContent(object); converted.add(object); } } // for (ManyToMany mtm : toRepairManyToMany) { // final ModelObject<?> modelObject = mtm.getOwner(); // final EObject eObject = objectMapping.get(modelObject.getTarget()); // for (EReference eReference : eObject.eClass().getEAllReferences()) { // if (eReference.isMany()) { // final Collection<?> coll1 = (Collection<?>) modelObject.eGet(eReference); // final Collection<?> coll2 = (Collection<?>) eObject.eGet(eReference); // if (coll1.size() != coll2.size()) { // throw new IllegalStateException("Unequal sizes of collection for EReference " // //$NON-NLS-1$ // + eReference); // } // } // } // } // now repair the ManyToMany for (ManyToMany mtm : toRepairManyToMany) { mtm.repair(); } return result; }
/** * Converts a set of EObjects and all the objects they reference to a a collection of model * managed objects. * * @param eObjects the eObjects to convert, also the references/children are converted * @return the created model objects */ public List<Object> convert(final List<EObject> eObjects) { // the process creates the new target objects and then converts the content // this multi-step process prevents stack overflow with large object graphs final List<Object> result = new ArrayList<Object>(); for (final EObject eObject : eObjects) { result.add(createTarget(eObject)); } while (!toConvert.isEmpty()) { final ArrayList<EObject> beingConverted = new ArrayList<EObject>(toConvert); allConvertedEObjects.addAll(beingConverted); toConvert.clear(); for (EObject eObject : beingConverted) { convertContent(eObject); } } // now repair the ManyToMany for (ManyToMany mtm : toRepairManyToMany) { mtm.repair(); } toRepairManyToMany.clear(); return result; }