List<Resource<?>> result = new ArrayList<Resource<?>>();
try
{
JavaSourceFacet java = this.project.getFacet(JavaSourceFacet.class);
WebResourceFacet web = this.project.getFacet(WebResourceFacet.class);
loadTemplates();
Map<Object, Object> context = CollectionUtils.newHashMap();
context.put("entity", entity);
String ccEntity = StringUtils.decapitalize(entity.getName());
context.put("ccEntity", ccEntity);
context.put("rmEntity", ccEntity + "ToDelete");
setPrimaryKeyMetaData(context, entity);
// Prepare qbeMetawidget
this.qbeMetawidget.setPath(entity.getQualifiedName());
StringWriter stringWriter = new StringWriter();
this.qbeMetawidget.write(stringWriter, this.backingBeanTemplateQbeMetawidgetIndent);
context.put("qbeMetawidget", stringWriter.toString().trim());
// Prepare removeEntityMetawidget
this.rmEntityMetawidget.setPath(entity.getQualifiedName());
stringWriter = new StringWriter();
this.rmEntityMetawidget.write(stringWriter, this.backingBeanTemplateRmEntityMetawidgetIndent);
context.put("rmEntityMetawidget", stringWriter.toString().trim());
// Prepare Java imports
Set<String> qbeMetawidgetImports = this.qbeMetawidget.getImports();
Set<String> rmEntityMetawidgetImports = this.rmEntityMetawidget.getImports();
Set<String> metawidgetImports = CollectionUtils.newHashSet();
metawidgetImports.addAll(qbeMetawidgetImports);
metawidgetImports.addAll(rmEntityMetawidgetImports);
metawidgetImports.remove(entity.getQualifiedName());
context.put("metawidgetImports",
CollectionUtils.toString(metawidgetImports, ";\r\nimport ", true, false));
// Create the Backing Bean for this entity
JavaClass viewBean = JavaParser.parse(JavaClass.class, this.backingBeanTemplate.render(context));
viewBean.setPackage(java.getBasePackage() + ".view");
result.add(ScaffoldUtil.createOrOverwrite(this.prompt, java.getJavaResource(viewBean), viewBean.toString(),
overwrite));
// Set new context for view generation
context = getTemplateContext(targetDir, template);
String beanName = StringUtils.decapitalize(viewBean.getName());
context.put("beanName", beanName);
context.put("ccEntity", ccEntity);
context.put("entityName", StringUtils.uncamelCase(entity.getName()));
setPrimaryKeyMetaData(context, entity);
// Prepare entityMetawidget
this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity));
this.entityMetawidget.setPath(entity.getQualifiedName());
this.entityMetawidget.setReadOnly(false);
this.entityMetawidget.setStyle(null);
// Generate create
writeEntityMetawidget(context, this.createTemplateEntityMetawidgetIndent, this.createTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(this.prompt,
web.getWebResource(targetDir + "/" + ccEntity + "/create.xhtml"),
this.createTemplate.render(context),
overwrite));
// Generate view
this.entityMetawidget.setReadOnly(true);
writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(this.prompt,
web.getWebResource(targetDir + "/" + ccEntity + "/view.xhtml"),
this.viewTemplate.render(context), overwrite));
// Generate search
this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example"));
this.searchMetawidget.setPath(entity.getQualifiedName());
this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems"));
this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems");
writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent,
this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);
result.add(ScaffoldUtil.createOrOverwrite(this.prompt,
web.getWebResource(targetDir + "/" + ccEntity + "/search.xhtml"),
this.searchTemplate.render(context), overwrite));
// Generate navigation
result.add(generateNavigation(targetDir, overwrite));
// Need ViewUtils and forge.taglib.xml for forgeview:asList
JavaClass viewUtils = JavaParser.parse(JavaClass.class, this.viewUtilsTemplate.render(context));
viewUtils.setPackage(viewBean.getPackage());
result.add(ScaffoldUtil.createOrOverwrite(this.prompt, java.getJavaResource(viewUtils), viewUtils.toString(),
true));
context.put("viewPackage", viewBean.getPackage());
result.add(ScaffoldUtil.createOrOverwrite(this.prompt,
web.getWebResource("WEB-INF/classes/META-INF/forge.taglib.xml"),
this.taglibTemplate.render(context), true));
createInitializers(entity);
}
catch (Exception e)