}
final JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
for (JavaResource jr : javaTargets)
{
JavaClass entity = (JavaClass) (jr).getJavaSource();
if (!entity.hasAnnotation(XmlRootElement.class))
entity.addAnnotation(XmlRootElement.class);
String idType = resolveIdType(entity);
if (!Types.isBasicType(idType))
{
ShellMessages.error(out, "Skipped class [" + entity.getQualifiedName() + "] because @Id type [" + idType
+ "] is not supported by endpoint generation.");
continue;
}
String idSetterName = resolveIdSetterName(entity);
String idGetterName = resolveIdGetterName(entity);
CompiledTemplateResource template = compiler.compileResource(getClass().getResourceAsStream(
"/org/jboss/forge/rest/Endpoint.jv"));
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("entity", entity);
map.put("idType", idType);
map.put("setIdStatement", idSetterName);
map.put("getIdStatement", idGetterName);
map.put("contentType", contentType);
String entityTable = getEntityTable(entity);
map.put("entityTable", entityTable);
map.put("resourcePath", entityTable.toLowerCase() + "s");
JavaClass resource = JavaParser.parse(JavaClass.class, template.render(map));
resource.addImport(entity.getQualifiedName());
resource.setPackage(java.getBasePackage() + ".rest");
/*
* Save the sources
*/
java.saveJavaSource(entity);
if (!java.getJavaResource(resource).exists()
|| prompt.promptBoolean("Endpoint [" + resource.getQualifiedName() + "] already, exists. Overwrite?"))
{
java.saveJavaSource(resource);
ShellMessages.success(out, "Generated REST endpoint for [" + entity.getQualifiedName() + "]");
}
else