@SuppressWarnings({ "unchecked", "rawtypes" }) private void updateReferences() { for (IdEObject idEObject : newModel.getValues()) { if (idEObject instanceof IfcRoot) { String guid = ((IfcRoot) idEObject).getGlobalId(); IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid); for (EReference eReference : idEObject.eClass().getEAllReferences()) { Object referencedObject = idEObject.eGet(eReference); if (referencedObject instanceof IfcRoot) { String referencedGuid = ((IfcRoot) referencedObject).getGlobalId(); IfcRoot newObject = (IfcRoot) resultModel.getByGuid(referencedGuid); oldObject.eSet(eReference, newObject); // LOGGER.info("Fixing reference from " + guid + " to " + referencedGuid); } else if (referencedObject instanceof List) { List referencedList = (List) referencedObject; List oldReferencedList = (List) oldObject.eGet(eReference); for (Object object : referencedList) { if (object instanceof IfcRoot) { IfcRoot referencedItem = (IfcRoot) object; String itemGuid = referencedItem.getGlobalId(); oldReferencedList.add(resultModel.getByGuid(itemGuid)); // LOGGER.info("Fixing list reference from " + guid + " to " + itemGuid); } } } } } } }
private void copyAttributesGuidObjectsAndAddNewObjects() throws IfcModelInterfaceException, ObjectAlreadyExistsException { for (IdEObject idEObject : newModel.getValues()) { if (idEObject instanceof IfcRoot) { IfcRoot ifcRoot = (IfcRoot) idEObject; String guid = ifcRoot.getGlobalId(); if (resultModel.containsGuid(guid)) { // LOGGER.info("Updating attributes for object " + idEObject.eClass().getName() + " " + guid); IfcRoot oldObject = (IfcRoot) resultModel.getByGuid(guid); for (EAttribute eAttribute : idEObject.eClass().getEAllAttributes()) { Object newValue = idEObject.eGet(eAttribute); oldObject.eSet(eAttribute, newValue); } } else { // LOGGER.info("Adding new GUID object " + idEObject.eClass().getName() + " " + guid); IdEObject newObject = (IdEObject) idEObject.eClass().getEPackage().getEFactoryInstance().create(idEObject.eClass()); ((IdEObjectImpl)newObject).setOid(idEObject.getOid()); ((IfcRoot) newObject).setGlobalId(newGuid(guid)); for (EAttribute eAttribute : newObject.eClass().getEAllAttributes()) { newObject.eSet(eAttribute, idEObject.eGet(eAttribute)); } resultModel.add(newObject.getOid(), newObject); } } } }