in maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/GenerateJspTaglibsMojo.java [820:944]
public void generateTagHandler(ComponentBean component)
{
ComponentTagGenerator generator;
Set<ComponentBean> componentList;
String fullSuperclassName = component.findJspTagSuperclass();
if (fullSuperclassName == null)
{
getLog().warn("Missing JSP Tag superclass for component: " + component.getComponentClass()
+ ", generation of this Tag is skipped");
return;
}
componentList = initComponentList(component, fullSuperclassName);
String fullClassName = component.getTagClass();
try
{
String className = Util.getClassFromFullClass(fullClassName);
String packageName = Util.getPackageFromFullClass(fullClassName);
TemplateFile templateFile = new TemplateFile(fullClassName, packageName, className);
boolean hasTemplate = templateFile.exists();
SourceTemplate sourceTemplate = null;
String overrideClassName = null;
String sourcePath = templateFile.getSourcePath();
if (hasTemplate)
{
className = templateFile.getClassName();
fullClassName = templateFile.getFullClassName();
overrideClassName = className;
if (!templateFile.isSubclass())
{
// Merged template use case
sourceTemplate = new SourceTemplate(templateFile.getFile());
}
}
getLog().debug("Generating " + fullClassName);
File targetFile = new File(generatedSourceDirectory, sourcePath);
targetFile.getParentFile().mkdirs();
StringWriter sw = new StringWriter();
PrettyWriter out = new PrettyWriter(sw);
if (component.isTrinidadComponent())
{
generator = new TrinidadComponentTagGenerator(!JsfVersion.isJSF11(jsfVersion));
}
else
{
generator = new MyFacesComponentTagGenerator(!JsfVersion.isJSF11(jsfVersion));
}
getLog().debug("Generating " + fullClassName + ", with generator: " +
generator.getClass().getName());
// header/copyright
writePreamble(out);
// package
out.println("package " + packageName + ";");
out.println();
String superclassName = Util.getClassFromFullClass(fullSuperclassName);
if (superclassName.equals(className))
{
superclassName = fullSuperclassName;
}
String componentFullClass = component.getComponentClass();
String componentClass = Util.getClassFromFullClass(componentFullClass);
generator.writeImports(out, null, packageName, fullSuperclassName, superclassName,
componentList);
generator.writeClassBegin(out, className, superclassName, component,
sourceTemplate, hasTemplate);
int modifiers = component.getTagClassModifiers();
generator.writeConstructor(out, component, overrideClassName, modifiers);
if (!Modifier.isAbstract(modifiers))
{
generator.writeGetComponentType(out, component);
generator.writeGetRendererType(out, component);
}
GenerateJspTaglibsMojo.this.writeCustomComponentTagHandlerContent(out, component);
generator.writePropertyMembers(out, componentList);
generator.writeSetPropertiesMethod(out, componentClass, componentList);
generator.writeReleaseMethod(out, componentList);
generator.writeClassEnd(out);
out.close();
// delay write in case of error
// timestamp should not be updated when an error occurs
// delete target file first, because it is readonly
targetFile.delete();
FileWriter fw = new FileWriter(targetFile);
StringBuffer buf = sw.getBuffer();
fw.write(buf.toString());
fw.close();
targetFile.setReadOnly();
if (templateFile.isSubclass())
{
// If there is a sub-class, copy the file to the directory in the compiler path
File destFile = new File(generatedSourceDirectory, templateFile.getOriginalSourcePath());
Util.copyFile(templateFile.getFile(), destFile);
destFile.setReadOnly();
}
}
catch (Throwable e)
{
getLog().error("Error generating " + fullClassName, e);
}
}