}
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);
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("contentType", contentType);
map.put("entityTable", getEntityTable(entity));
JavaClass endpoint = JavaParser.parse(JavaClass.class, template.render(map));
endpoint.addImport(entity.getQualifiedName());
endpoint.setPackage(java.getBasePackage() + ".rest");
endpoint.getAnnotation(Path.class).setStringValue("/" + getEntityTable(entity).toLowerCase());
/*
* Save the sources
*/
java.saveJavaSource(entity);
if (!java.getJavaResource(endpoint).exists()
|| prompt.promptBoolean("Endpoint [" + endpoint.getQualifiedName() + "] already, exists. Overwrite?"))
{
java.saveJavaSource(endpoint);
ShellMessages.success(out, "Generated REST endpoint for [" + entity.getQualifiedName() + "]");
}
else