Java Code Examples for org.eclipse.emf.ecore.EPackage.eAllContents()

The following are Jave code examples for showing how to use eAllContents() of the org.eclipse.emf.ecore.EPackage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OCCI-Studio   File: ConverterUtils.java   View Source Code Vote up 6 votes
public static void persistMetamodel(ResourceSet resourceSet, EPackage generated, String path) throws IOException {
	if (new File(path).exists()) {
		EPackage existing = (EPackage) OcciHelper.getRootElement(resourceSet, "file:/" + path);
		for (Iterator<EObject> iterator = existing.eAllContents(); iterator.hasNext();) {
			EObject eo = iterator.next();
			if (eo instanceof EAnnotation && isOCLRelated((EAnnotation) eo)) {
				EModelElement existingContainer = (EModelElement) eo.eContainer();
				EModelElement generatedContainer = (EModelElement) getGeneratedElement(generated,
						existingContainer);
				if (generatedContainer == null) {
					throw new RuntimeException("Unable to find " + existingContainer + " to reattach " + eo + " "
							+ ((EAnnotation) eo).getEAnnotations());
				} else {
					generatedContainer.getEAnnotations().add((EAnnotation) EcoreUtil.copy(eo));
				}
			}
		}
	}
	ConverterUtils.save(resourceSet, generated, "file:/" + path);
}