protected void addBaseViewFieldsAndMethodImpls(
      SourceGenerationContext context, JavaClassSource viewClass) {
    StringBuffer inputNames = new StringBuffer();
    StringBuffer readOnlyMethodSrc = new StringBuffer();

    for (FieldDefinition fieldDefinition : context.getFormDefinition().getFields()) {

      if ((fieldDefinition.isAnnotatedId() && !displaysId()) || isBanned(fieldDefinition)) continue;

      InputCreatorHelper helper = creatorHelpers.get(fieldDefinition.getCode());
      if (helper == null) continue;

      PropertySource<JavaClassSource> property =
          viewClass.addProperty(getWidgetFromHelper(helper), fieldDefinition.getName());

      FieldSource<JavaClassSource> field = property.getField();
      field.setPrivate();

      initializeProperty(helper, context, fieldDefinition, field);

      if (helper instanceof RequiresCustomCode)
        ((RequiresCustomCode) helper).addCustomCode(fieldDefinition, context, viewClass);

      if (!(fieldDefinition instanceof SubFormFieldDefinition)) {
        field
            .addAnnotation(ERRAI_BOUND)
            .setStringValue("property", fieldDefinition.getBindingExpression());
      }

      field.addAnnotation(ERRAI_DATAFIELD);

      property.removeAccessor();
      property.removeMutator();

      inputNames.append("inputNames.add(\"").append(fieldDefinition.getName()).append("\");");
      readOnlyMethodSrc.append(helper.getReadonlyMethod(fieldDefinition.getName(), READONLY_PARAM));
    }

    viewClass
        .addMethod()
        .setName("initInputNames")
        .setBody(inputNames.toString())
        .setPublic()
        .setReturnTypeVoid()
        .addAnnotation(JAVA_LANG_OVERRIDE);

    if (isEditable()) {
      MethodSource<JavaClassSource> readonlyMethod =
          viewClass
              .addMethod()
              .setName("setReadOnly")
              .setBody(readOnlyMethodSrc.toString())
              .setPublic()
              .setReturnTypeVoid();
      readonlyMethod.addParameter(boolean.class, SourceGenerationUtil.READONLY_PARAM);
      readonlyMethod.addAnnotation(JAVA_LANG_OVERRIDE);
    }
  }
Example #2
0
 @Test
 public void testJavaDocParsing() throws Exception {
   String text = "/** Text */ public class MyClass{}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   Assert.assertNotNull(javaDoc);
   Assert.assertEquals("Text", javaDoc.getText());
   Assert.assertTrue(javaDoc.getTagNames().isEmpty());
 }
Example #3
0
 @Test
 public void testJavaDocParsingTags() throws Exception {
   String text = "/** Do Something\n*@author George Gastaldi*/ public class MyClass{}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   Assert.assertNotNull(javaDoc);
   Assert.assertEquals("Do Something", javaDoc.getText());
   Assert.assertEquals(1, javaDoc.getTagNames().size());
   JavaDocTag authorTag = javaDoc.getTags("@author").get(0);
   Assert.assertEquals("@author", authorTag.getName());
   Assert.assertEquals("George Gastaldi", authorTag.getValue());
 }
  @Override
  public String generateJavaTemplateSource(SourceGenerationContext context) {
    JavaClassSource viewClass = Roaster.create(JavaClassSource.class);
    String packageName = getPackageName(context);

    addTypeSignature(context, viewClass, packageName);
    addImports(context, viewClass);
    addAnnotations(context, viewClass);
    addAdditional(context, viewClass);

    addBaseViewFieldsAndMethodImpls(context, viewClass);
    return viewClass.toString();
  }
 /**
  * processMainClass (non-Javadoc).
  *
  * @param javaClass the java class
  * @see
  *     io.github.rampantlions.codetools.CommonProcessor#processMainClass(org.jboss.forge.roaster.model.source.JavaClassSource)
  */
 @Override
 public void processMainClass(final JavaClassSource javaClass) {
   for (AnnotationSource<JavaClassSource> annotation : javaClass.getAnnotations()) {
     switch (annotation.getQualifiedName()) {
       case "com.wordnik.swagger.annotations.ApiModel":
       case "com.wordnik.swagger.annotations.ApiModelProperty":
         javaClass.removeAnnotation(annotation);
         changeMade = true;
         break;
       default:
         break;
     }
   }
 }
 private void setDefaultTargetEntity(
     UISelection<FileResource<?>> selection, List<JavaResource> entities)
     throws FileNotFoundException {
   if (selection.isEmpty()) {
     return;
   }
   int idx = entities.indexOf(selection.get());
   if (idx != -1) {
     final JavaResource defaultEntity = entities.get(idx);
     forEntity.setDefaultValue(defaultEntity);
     JavaClassSource entityClass = ((JavaResource) defaultEntity).getJavaType();
     getNamed().setDefaultValue(entityClass.getName() + "Repository");
   }
 }
 @Test
 public void getClassGenericsName() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable("I");
   javaClass.addTypeVariable("O");
   List<TypeVariableSource<JavaClassSource>> typeVariables = javaClass.getTypeVariables();
   Assert.assertNotNull(typeVariables);
   Assert.assertEquals(2, typeVariables.size());
   Assert.assertEquals("I", typeVariables.get(0).getName());
   Assert.assertTrue(typeVariables.get(0).getBounds().isEmpty());
   Assert.assertEquals("O", typeVariables.get(1).getName());
   Assert.assertTrue(typeVariables.get(1).getBounds().isEmpty());
 }
 @Test
 public void classTypeVariableBounds() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds(CharSequence.class);
   Assert.assertTrue(javaClass.toString().contains("<T extends CharSequence>"));
   javaClass.getTypeVariable("T").setBounds(CharSequence.class, Serializable.class);
   Assert.assertTrue(javaClass.toString().contains("<T extends CharSequence & Serializable>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
 @Test
 public void stringTypeVariableBounds() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds("com.something.Foo");
   Assert.assertTrue(javaClass.toString().contains("<T extends com.something.Foo>"));
   javaClass.getTypeVariable("T").setBounds("com.something.Foo", "com.something.Bar<T>");
   Assert.assertTrue(
       javaClass.toString().contains("<T extends com.something.Foo & com.something.Bar<T>>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
Example #10
0
 @Test
 public void testJavaDocMultiLineShouldNotConcatenateWords() throws Exception {
   String text =
       "/**"
           + LINE_SEPARATOR
           + "* The country where this currency is used mostly. This field is just for"
           + LINE_SEPARATOR
           + "* informational purposes and have no effect on any processing."
           + LINE_SEPARATOR
           + "*/"
           + LINE_SEPARATOR
           + "public class MyClass{}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   String expected =
       "The country where this currency is used mostly. This field is just for informational purposes and have no effect on any processing.";
   Assert.assertEquals(expected, javaDoc.getFullText());
 }
 @Test
 public void removeGenericSuperType() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.addImport("it.coopservice.test.Bar");
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.setSuperType("Bar<T>");
   Assert.assertTrue(javaClass.toString().contains("Bar<T>"));
   javaClass.setSuperType("");
   Assert.assertTrue(!javaClass.toString().contains("Bar<T>"));
 }
 @Test
 public void addAndRemoveGenericType() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T");
   Assert.assertTrue(javaClass.getTypeVariables().get(0).getBounds().isEmpty());
   Assert.assertTrue(javaClass.toString().contains("<T>"));
   javaClass.removeTypeVariable("T");
   Assert.assertFalse(javaClass.toString().contains("<T>"));
 }
Example #13
0
  public static ClassTypeResolver createClassTypeResolver(
      JavaSource javaSource, ClassLoader classLoader) {
    String packageName;
    Set<String> classImports = new HashSet<String>();

    // Importer.getImports() returns both normal and static imports
    // You can see if an Import is static by calling hte
    // Import.isStatic() method
    List<Import> imports = javaSource.getImports();
    if (imports != null) {
      for (Import currentImport : imports) {
        String importName = currentImport.getQualifiedName();
        if (currentImport.isWildcard()) {
          importName = importName + ".*";
        }
        classImports.add(importName);
      }
    }

    packageName = javaSource.getPackage();
    // add current package too, if not added, the class type resolver don't resolve current package
    // classes.
    if (packageName != null && !"".equals(packageName)) {
      classImports.add(packageName + ".*");
    }

    if (javaSource instanceof JavaClassSource) {
      JavaClassSource javaClassSource = (JavaClassSource) javaSource;

      // add current file inner types as import clauses to help the ClassTypeResolver to find
      // variables of inner types
      // It was detected that current ClassTypeResolver don't resolve inner classes well.
      // workaround for BZ https://bugzilla.redhat.com/show_bug.cgi?id=1172711
      List<JavaSource<?>> innerTypes = javaClassSource.getNestedTypes();
      if (innerTypes != null) {
        for (JavaSource<?> type : innerTypes) {
          classImports.add(packageName + "." + javaClassSource.getName() + "." + type.getName());
        }
      }
    }

    return new ClassTypeResolver(classImports, classLoader);
  }
 @Test
 public void javaTypeTypeVariableBounds() throws ClassNotFoundException {
   JavaInterface<?> foo =
       Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Foo");
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("T").setBounds(foo);
   Assert.assertTrue(javaClass.toString().contains("<T extends Foo>"));
   JavaInterface<?> bar =
       Roaster.create(JavaInterfaceSource.class).setPackage("it.coopservice.test").setName("Bar");
   javaClass.getTypeVariable("T").setBounds(foo, bar);
   Assert.assertTrue(javaClass.toString().contains("<T extends Foo & Bar>"));
   javaClass.getTypeVariable("T").removeBounds();
   Assert.assertTrue(javaClass.toString().contains("<T>"));
 }
  public static void createJavaProperty(
      JavaClassSource javaClass, EntityMemberVariableVO memberVO) {
    PropertySource<JavaClassSource> propSource =
        javaClass.addProperty(memberVO.getType(), memberVO.getName());
    FieldSource<JavaClassSource> fieldSource = propSource.getField();

    List<AnnotationVO> annotationList = memberVO.getAnnotationList();
    if (Utils.notEmptyList(annotationList)) {
      AnnotationGenerator.createAnnotationForField(fieldSource, annotationList);
    }
  }
 @Test
 public void addMultipleConcreteGenericSuperTypeWithPackage() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.setSuperType(
       "it.coopservice.test.Bar<com.coopservice.test.MyConcreteSuperClass,com.coopservice.test.MyOtherClass>");
   Assert.assertTrue(
       javaClass.toString().contains("extends Bar<MyConcreteSuperClass, MyOtherClass>"));
   Assert.assertNotNull(javaClass.getImport("it.coopservice.test.Bar"));
   Assert.assertNotNull(javaClass.getImport("com.coopservice.test.MyConcreteSuperClass"));
   Assert.assertNotNull(javaClass.getImport("com.coopservice.test.MyOtherClass"));
 }
Example #17
0
 @Test
 public void testJavaDocGetFullText() throws Exception {
   String text =
       "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + "public class MyClass"
           + LINE_SEPARATOR
           + "{"
           + LINE_SEPARATOR
           + "}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   Assert.assertTrue(javaClass.hasJavaDoc());
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
   Assert.assertEquals(expected, javaDoc.getFullText());
 }
 @Test
 public void addMultipleGenerics() throws ClassNotFoundException {
   JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
   javaClass.setPackage("it.coopservice.test");
   javaClass.setName("SimpleClass");
   javaClass.addTypeVariable().setName("I");
   javaClass.addTypeVariable().setName("O");
   Assert.assertTrue(javaClass.toString().contains("<I, O>"));
   javaClass.removeTypeVariable("I");
   Assert.assertTrue(javaClass.toString().contains("<O>"));
 }
Example #19
0
 @Test
 public void testJavaDocMethod() throws Exception {
   String text =
       "public class MyClass {"
           + "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + ""
           + "private void foo(){};}";
   JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, text);
   Assert.assertFalse(javaClass.hasJavaDoc());
   Assert.assertEquals(1, javaClass.getMethods().size());
   MethodSource<JavaClassSource> method = javaClass.getMethods().get(0);
   Assert.assertTrue(method.hasJavaDoc());
   JavaDocSource<MethodSource<JavaClassSource>> javaDoc = method.getJavaDoc();
   String expected = "Do Something" + LINE_SEPARATOR + "@author George Gastaldi";
   Assert.assertEquals(expected, javaDoc.getFullText());
 }
Example #20
0
 @Test
 public void testJavaDocSetFullText() throws Exception {
   String expected =
       "/**"
           + LINE_SEPARATOR
           + " * Do Something"
           + LINE_SEPARATOR
           + " * "
           + LINE_SEPARATOR
           + " * @author George Gastaldi"
           + LINE_SEPARATOR
           + " */"
           + LINE_SEPARATOR
           + "public class MyClass {"
           + LINE_SEPARATOR
           + "}";
   JavaClassSource javaClass =
       Roaster.create(JavaClassSource.class).setPublic().setName("MyClass");
   Assert.assertFalse(javaClass.hasJavaDoc());
   JavaDocSource<JavaClassSource> javaDoc = javaClass.getJavaDoc();
   javaDoc.setFullText("Do Something" + LINE_SEPARATOR + "* @author George Gastaldi");
   Assert.assertEquals(expected, javaClass.toString());
 }
Example #21
0
  private void setPrimaryKeyMetaData(Map<Object, Object> context, final JavaClassSource entity) {
    String pkName = "id";
    String pkType = "Long";
    String nullablePkType = "Long";
    for (MemberSource<JavaClassSource, ?> m : entity.getMembers()) {
      if (m.hasAnnotation(Id.class)) {
        if (m instanceof Field) {
          Field<?> field = (Field<?>) m;
          pkName = field.getName();
          pkType = field.getType().getQualifiedName();
          nullablePkType = pkType;
          break;
        }

        MethodSource<?> method = (MethodSource<?>) m;
        pkName = method.getName().substring(3);
        if (method.getName().startsWith("get")) {
          pkType = method.getReturnType().getQualifiedName();
        } else {
          pkType = method.getParameters().get(0).getType().getQualifiedName();
        }
        nullablePkType = pkType;
        break;
      }
    }

    if (Types.isJavaLang(pkType)) {
      nullablePkType = Types.toSimpleName(pkType);
    } else if ("int".equals(pkType)) {
      nullablePkType = Integer.class.getSimpleName();
    } else if ("short".equals(pkType)) {
      nullablePkType = Short.class.getSimpleName();
    } else if ("byte".equals(pkType)) {
      nullablePkType = Byte.class.getSimpleName();
    } else if ("long".equals(pkType)) {
      nullablePkType = Long.class.getSimpleName();
    }

    context.put("primaryKey", pkName);
    context.put("primaryKeyCC", StringUtils.capitalize(pkName));
    context.put("primaryKeyType", pkType);
    context.put("nullablePrimaryKeyType", nullablePkType);
  }
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    JavaResource javaResource = targetClass.getValue();
    JavaClassSource targetClass = javaResource.getJavaType();
    GetSetMethodGenerator generator;
    if (builderPattern.getValue()) {
      generator = new BuilderGetSetMethodGenerator();
    } else {
      generator = new DefaultGetSetMethodGenerator();
    }
    List<PropertySource<JavaClassSource>> selectedProperties = new ArrayList<>();
    if (properties == null || properties.getValue() == null) {
      return Results.fail("No properties were selected");
    }
    for (String selectedProperty : properties.getValue()) {
      selectedProperties.add(targetClass.getProperty(selectedProperty));
    }

    for (PropertySource<JavaClassSource> property : selectedProperties) {
      MethodSource<JavaClassSource> accessor =
          targetClass.getMethod("get" + Strings.capitalize(property.getName()));
      if (accessor == null) {
        generator.createAccessor(property);
      } else {
        if (!generator.isCorrectAccessor(accessor, property)) {
          if (promptToFixMethod(context, accessor.getName(), property.getName())) {
            targetClass.removeMethod(accessor);
            generator.createMutator(property);
          }
        }
      }
      String mutatorMethodName = "set" + Strings.capitalize(property.getName());
      String mutatorMethodParameter = property.getType().getName();
      MethodSource<JavaClassSource> mutator =
          targetClass.getMethod(mutatorMethodName, mutatorMethodParameter);
      if (mutator == null) {
        generator.createMutator(property);
      } else {
        if (!generator.isCorrectMutator(mutator, property)) {
          if (promptToFixMethod(context, mutator.getName(), property.getName())) {
            targetClass.removeMethod(mutator);
            generator.createMutator(property);
          }
        }
      }
    }
    setCurrentWorkingResource(context, targetClass);
    return Results.success("Mutators and accessors were generated successfully");
  }
Example #23
0
 protected void createInitializers(final JavaClassSource entity)
     throws FacetNotFoundException, FileNotFoundException {
   boolean dirtyBit = false;
   for (FieldSource<JavaClassSource> field : entity.getFields()) {
     if (field.hasAnnotation(OneToOne.class)) {
       AnnotationSource<JavaClassSource> oneToOne = field.getAnnotation(OneToOne.class);
       if (oneToOne.getStringValue("mappedBy") == null
           && oneToOne.getStringValue("cascade") == null) {
         oneToOne.setEnumValue("cascade", CascadeType.ALL);
         dirtyBit = true;
       }
       String methodName = "new" + StringUtils.capitalize(field.getName());
       if (!entity.hasMethodSignature(methodName)) {
         entity
             .addMethod()
             .setName(methodName)
             .setReturnTypeVoid()
             .setPublic()
             .setBody("this." + field.getName() + " = new " + field.getType().getName() + "();");
         dirtyBit = true;
       }
     }
   }
   for (MethodSource<JavaClassSource> method : entity.getMethods()) {
     if (method.hasAnnotation(OneToOne.class)) {
       AnnotationSource<JavaClassSource> oneToOne = method.getAnnotation(OneToOne.class);
       if (oneToOne.getStringValue("mappedBy") == null
           && oneToOne.getStringValue("cascade") == null) {
         oneToOne.setEnumValue("cascade", CascadeType.ALL);
         dirtyBit = true;
       }
       String fieldName = StringUtils.camelCase(method.getName().substring(3));
       String methodName = "new" + StringUtils.capitalize(fieldName);
       if (!entity.hasMethodSignature(methodName)) {
         entity
             .addMethod()
             .setName(methodName)
             .setReturnTypeVoid()
             .setPublic()
             .setBody("this." + fieldName + " = new " + method.getReturnType().getName() + "();");
         dirtyBit = true;
       }
     }
   }
   if (dirtyBit) {
     this.project.getFacet(JavaSourceFacet.class).saveJavaSource(entity);
   }
 }
Example #24
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  private List<Resource<?>> generateFromEntity(
      String targetDir, final Resource<?> template, final JavaClassSource entity) {
    resetMetaWidgets();

    // Track the list of resources generated

    List<Resource<?>> result = new ArrayList<>();
    try {
      JavaSourceFacet java = this.project.getFacet(JavaSourceFacet.class);
      WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
      JPAFacet<PersistenceCommonDescriptor> jpa = this.project.getFacet(JPAFacet.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));

      // Prepare JPA Persistence Unit
      context.put("persistenceUnitName", jpa.getConfig().getOrCreatePersistenceUnit().getName());

      // Create the Backing Bean for this entity
      JavaClassSource viewBean =
          Roaster.parse(
              JavaClassSource.class,
              FreemarkerTemplateProcessor.processTemplate(context, this.backingBeanTemplate));
      viewBean.setPackage(java.getBasePackage() + "." + DEFAULT_FACES_PACKAGE);
      result.add(
          ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewBean), viewBean.toString()));

      // 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(
              web.getWebResource(targetDir + "/" + ccEntity + "/create.xhtml"),
              FreemarkerTemplateProcessor.processTemplate(context, this.createTemplate)));

      // Generate view
      this.entityMetawidget.setReadOnly(true);
      writeEntityMetawidget(
          context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces);

      result.add(
          ScaffoldUtil.createOrOverwrite(
              web.getWebResource(targetDir + "/" + ccEntity + "/view.xhtml"),
              FreemarkerTemplateProcessor.processTemplate(context, this.viewTemplate)));

      // 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(
              web.getWebResource(targetDir + "/" + ccEntity + "/search.xhtml"),
              FreemarkerTemplateProcessor.processTemplate(context, this.searchTemplate)));

      // Generate navigation
      result.add(generateNavigation(targetDir));

      // Need ViewUtils and forge.taglib.xml for forgeview:asList
      JavaClassSource viewUtils =
          Roaster.parse(
              JavaClassSource.class,
              FreemarkerTemplateProcessor.processTemplate(context, this.viewUtilsTemplate));
      viewUtils.setPackage(viewBean.getPackage());
      result.add(
          ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewUtils), viewUtils.toString()));

      context.put("viewPackage", viewBean.getPackage());
      result.add(
          ScaffoldUtil.createOrOverwrite(
              web.getWebResource("WEB-INF/classes/META-INF/forge.taglib.xml"),
              FreemarkerTemplateProcessor.processTemplate(context, this.taglibTemplate)));

      createInitializers(entity);
    } catch (Exception e) {
      throw new RuntimeException("Error generating default scaffolding: " + e.getMessage(), e);
    }
    return result;
  }