package org.enterprisedomain.sample;

import javax.inject.Inject;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.enterprisedomain.classsupplier.ClassSupplier;
import org.enterprisedomain.classsupplier.Contribution;
import org.enterprisedomain.classsupplier.impl.CompletionListenerImpl;
import org.osgi.framework.FrameworkUtil;

public class Invoker implements Runnable {

	@Inject
	private ClassSupplier m;

	private Contribution contribution;

	private EPackage ePackage;

	private void inject() {
		IEclipseContext context = EclipseContextFactory
				.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext());
		ContextInjectionFactory.inject(this, context);
	}

	public void run() {
		inject();
		EPackage p = EcoreFactory.eINSTANCE.createEPackage();
		p.setName("ho");
		p.setNsPrefix("ho");
		p.setNsURI("http://ho/0.1");
		final EClass c = EcoreFactory.eINSTANCE.createEClass();
		c.setName("Obj");
		final EAttribute a = EcoreFactory.eINSTANCE.createEAttribute();
		a.setName("p");
		a.setEType(EcorePackage.Literals.ESTRING);
		c.getEStructuralFeatures().add(a);
		p.getEClassifiers().add(c);
		IProgressMonitor monitor = new CodeGenUtil.EclipseUtil.StreamProgressMonitor(System.out);
		try {
			contribution = m.getWorkspace().createContribution(p, monitor);
		} catch (CoreException e) {
			e.printStackTrace();
		}
		try {
			contribution.save(monitor);
			contribution.addSaveCompletionListener(new CompletionListenerImpl() {

				@Override
				public void completed(Contribution result) throws Exception {
					ePackage = contribution.getDomainModel().getGenerated();
					EClass e = (EClass) ePackage.getEClassifier(c.getName());
					System.out.println(e.getName());
					EObject o = ePackage.getEFactoryInstance().create(e);
					EAttribute ea = (EAttribute) e.getEStructuralFeature(a.getName());
					o.eSet(ea, "Lorem ipsum");
					Object v = o.eGet(ea);
					System.out.println(v);
				}

			});

		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}

@@ -930,45 +930,8 @@
 m;%0A%0A
-%09private Contribution contribution;%0A%0A
 %09pri
@@ -1605,491 +1605,53 @@
 ;%0A%09%09
-IProgressMonitor monitor = new CodeGenUtil.EclipseUtil.StreamProgressMonitor(System.out);%0A%09%09try %7B%0A%09%09%09contribution = m.getWorkspace().createContribution(p, monitor);%0A%09%09%7D catch (CoreException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09contribution.save(monitor);%0A%09%09%09contribution.addSaveCompletionListener(new CompletionListenerImpl() %7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void completed(Contribution result) throws Exception %7B%0A%09%09%09%09%09ePackage = contribution.getDomainModel().getGener
+try %7B%0A%09%09%09EPackage ePackage = m.cre
 ate
-d
 (
+p
 );%0A%09%09%09
-%09%09
 ECla
@@ -1704,18 +1704,16 @@
 ame());%0A
-%09%09
 %09%09%09Syste
@@ -1743,18 +1743,16 @@
 ());%0A%09%09%09
-%09%09
 EObject 
@@ -1797,18 +1797,16 @@
 ate(e);%0A
-%09%09
 %09%09%09EAttr
@@ -1870,18 +1870,16 @@
 ());%0A%09%09%09
-%09%09
 o.eSet(e
@@ -1897,18 +1897,16 @@
 psum%22);%0A
-%09%09
 %09%09%09Objec
@@ -1926,18 +1926,16 @@
 ea);%0A%09%09%09
-%09%09
 System.o
@@ -1953,23 +1953,8 @@
 v);%0A
-%09%09%09%09%7D%0A%0A%09%09%09%7D);%0A%0A
 %09%09%7D 

Update sample