<%@ jet package="compiledtemplates" 
imports="java.util.* util.EcoreGenerationHelper org.eclipse.emf.ecore.* org.eclipse.emf.codegen.util.*"
class="Repository" %>
<%
%>
<%EClass eClass = (EClass) argument;
EPackage ePackage = eClass.getEPackage();

if (!eClass.getName().endsWith("Repository")) {
throw new IllegalArgumentException("Expect name of class argument to end with \"Repository\"");
}
String baseName = eClass.getName().substring(0, eClass.getName().length() - "Repository".length());
String productType = "Access";

EcoreGenerationHelper h = new EcoreGenerationHelper();
String apiPackageName = h.getQualifiedName(ePackage.getESuperPackage()) + ".accessapi";
String fwApiPackageName = h.getQualifiedName(ePackage.getESuperPackage().getESuperPackage()) + ".framework.accessapi";
h.makeImportManager(ePackage);
%>
<%@ include file="Header.jetinc"%>
package <%=h.getQualifiedName(eClass.getEPackage())%>;

<%
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
h.getImportManager().addCompilationUnitImports(stringBuffer.toString());
h.addImport(apiPackageName + "." + baseName + productType + "Factory");
// by some strange reason the import of in forId does not work
h.addImport("java.util.Map");
h.addImport(fwApiPackageName + ".*");
h.addImport(apiPackageName + ".*");
%>

/**
* <!-- begin-user-doc -->
* Repository for <%=baseName%>
* <!-- end-user-doc -->
*
* @generated
*/
public class <%=h.getName(eClass)%> {

/**
* Reference to the access object factory.
* @generated
*/
private <%=baseName%><%=productType%>Factory <%=h.uncapName(baseName)%><%=productType%>Factory = <%=baseName%><%=productType%>Factory.getInstance();

/** @generated */
public <%=h.getName(eClass)%>() {
}


<%for (EOperation op : h.getOperations(eClass)) {
// a few naming mapping conventions
String mappedOpName = h.getMappedOperationName(op);
boolean findById = (mappedOpName.equals("findById"));
%>
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
<%=h.getVisibility(op) %><%=h.getTypeName(op)%> <%=h.getName(op)%>(<%=h.getParameterList(op)%>) <% if (findById) {%>throws <%=baseName%>NotFoundException<%}%> {
<% if (h.getAnnotation(op, "noaccessobject") != null) {%>
// TODO Auto-generated method stub
throw new UnsupportedOperationException("<%=mappedOpName%> not implemented");
<%} else {%>
<%=h.capName(mappedOpName)%><%=productType%><%=h.getGenericType(op)%> ao = <%=h.uncapName(baseName)%><%=productType%>Factory.create<%=h.capName(mappedOpName)%><%=productType%>();
<%for (EParameter parameter : h.getParameters(op)) {%>
ao.set<%=h.capName(h.getName(parameter))%>(<%=h.getName(parameter)%>);
<%}%>
ao.execute();
<%if (!h.getTypeName(op).equals("void")) {%>
<%if (findById) {
EParameter idParam = h.getParameters(op).get(0);
%>
if (ao.getResult() == null) {
throw new <%=baseName%>NotFoundException("No <%=baseName%> found with <%=h.getName(idParam)%>: " + <%=h.getName(idParam)%>);
}
<%}%>
return ao.getResult();
<%}%>
<%}%>
}

<%}%>



}
<%importStringBuffer.insert(importInsertionPoint, h.getImportManager().computeSortedImports());%>