1 | /** |
2 | * |
3 | */ |
4 | package de.fzi.se.quality.util; |
5 | |
6 | import org.eclipse.emf.ecore.EAttribute; |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.util.EcoreUtil; |
9 | import org.eclipse.emf.ecore.util.EcoreUtil.Copier; |
10 | |
11 | /**Copies an EObject but replaced old Ids with new ones. |
12 | * @author groenda |
13 | * |
14 | */ |
15 | public class EcoreCopierCreatingNewIds extends Copier { |
16 | |
17 | /** |
18 | */ |
19 | private static final long serialVersionUID = 8417471343199324464L; |
20 | |
21 | @Override |
22 | protected void copyAttribute(EAttribute eAttribute, EObject eObject, |
23 | EObject copyEObject) { |
24 | if (eAttribute.isID() && !eAttribute.isMany() && eAttribute.isRequired()) { |
25 | // if the value is not automatically created upon object creation for identifier based classes |
26 | EcoreUtil.setID(copyEObject, EcoreUtil.generateUUID()); |
27 | } else { |
28 | super.copyAttribute(eAttribute, eObject, copyEObject); |
29 | } |
30 | } |
31 | } |