package org.nasdanika.codegen.ecore.web.ui;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.nasdanika.codegen.GeneratorController;
import org.nasdanika.codegen.Interpolator;
import org.nasdanika.codegen.ecore.EcoreCodeGenerator;
import org.nasdanika.config.Context;
import org.nasdanika.config.MutableContext;

/**
 * Iterates over selected non-abstract EClasses
 * @author Pavel
 *
 */
public class PluginXmlRouteEntriesInterpolatorController implements GeneratorController<String, Interpolator> {

	@Override
	public Collection<Context> iterate(Context context, Interpolator generator) throws Exception {
		Collection<Context> ret = new ArrayList<>();
		EcoreCodeGenerator eCoreCodeGenerator = context.get(EcoreCodeGenerator.class);
		for (EPackage ep: eCoreCodeGenerator.getEPackages()) {
			if (eCoreCodeGenerator.isSelected(ep)) {
				for (EClassifier ec: ep.getEClassifiers()) {
					if (ec instanceof EClass && !((EClass) ec).isAbstract() && eCoreCodeGenerator.isSelected(ec)) {
						MutableContext mc = context.createSubContext();
						mc.set("epackage-namespace-uri", ep.getNsURI());
						mc.set("epackage-name", ep.getName());
						mc.set("eclass-name", ec.getName());
						ret.add(mc);
					}
				}
			}
		}
		
		return ret;
	}

}

@@ -97,24 +97,67 @@
 lection;%0D%0A%0D%0A
+import org.eclipse.emf.common.util.EList;%0D%0A
 import org.e
@@ -182,16 +182,16 @@
 Class;%0D%0A
-
 import o
@@ -221,24 +221,63 @@
 lassifier;%0D%0A
+import org.eclipse.emf.ecore.EObject;%0D%0A
 import org.e
@@ -981,21 +981,22 @@
 %0D%0A%09%09
-for (
+EList%3C
 EPackage
  ep:
@@ -995,12 +995,21 @@
 kage
+%3E
  e
-p:
+Packages =
  eCo
@@ -1038,16 +1038,48 @@
 ckages()
+;%0D%0A%09%09for (EPackage ep: ePackages
 ) %7B%0D%0A%09%09%09
@@ -1379,24 +1379,272 @@
 tNsURI());%0D%0A
+%09%09%09%09%09%09String ePackageName = ep.getName();%0D%0A%09%09%09%09%09%09for (EObject container = ep.eContainer(); ePackages.contains(container); container = container.eContainer()) %7B%0D%0A%09%09%09%09%09%09%09ePackageName = ((EPackage) container).getName() + %22.%22 + ePackageName;%0D%0A%09%09%09%09%09%09%7D%0D%0A
 %09%09%09%09%09%09mc.set
@@ -1662,27 +1662,27 @@
 name%22, e
-p.
+Packa
 ge
-t
 Name
-()
 );%0D%0A%09%09%09%09

Fix in nested package name generation.