in maven2-plugins/myfaces-faces-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/faces/GenerateComponentsMojo.java [122:268]
private void _generateComponent(
ComponentBean component) throws MojoExecutionException
{
ComponentGenerator generator;
String fullClassName = component.getComponentClass();
if (component.isTrinidadComponent())
{
generator = new TrinidadComponentGenerator(getLog(), _is12());
}
else
{
generator = new MyFacesComponentGenerator(getLog(),_is12() );
}
try
{
getLog().debug("Generating " + fullClassName+", with generator: "+generator.getClass().getName());
String sourcePath = Util.convertClassToSourcePath(fullClassName, ".java");
File targetFile = new File(generatedSourceDirectory, sourcePath);
StringWriter sw = new StringWriter();
PrettyWriter out = new PrettyWriter(sw);
String className = Util.getClassFromFullClass(fullClassName);
String componentFamily = component.findComponentFamily();
if (componentFamily == null)
{
getLog().warn("Missing <component-family> for \"" +
fullClassName + "\", generation of this Component is skipped");
}
else
{
String packageName = Util.getPackageFromFullClass(fullClassName);
String fullSuperclassName = component.findComponentSuperclass();
String superclassName = Util.getClassFromFullClass(fullSuperclassName);
// make class name fully qualified in case of collision
if (superclassName.equals(className))
superclassName = fullSuperclassName;
// TODO: remove this bogosity
if (superclassName.equals("UIXMenuHierarchy") ||
superclassName.equals("UIXTable") ||
superclassName.equals("UIXHierarchy") ||
superclassName.equals("UIXMenuTree") ||
className.equals("CoreTree"))
{
superclassName = fullSuperclassName;
}
String componentType = component.getComponentType();
// Use template file if it exists
String templatePath = Util.convertClassToSourcePath(fullClassName, "Template.java");
File templateFile = new File(templateSourceDirectory, templatePath);
SourceTemplate template = null;
if (templateFile.exists())
{
getLog().debug("Using template " + templatePath);
template = new SourceTemplate(templateFile);
template.substitute(className + "Template", className);
template.readPreface();
}
// header/copyright
writePreamble(out);
// package
out.println("package " + packageName + ";");
out.println();
// imports
generator.writeImports(out, template, packageName,
fullSuperclassName, superclassName,
component);
// class
generator.writeClassBegin(out, className, superclassName, component, template);
// static final constants
generator.writePropertyValueConstants(out, component);
generator.writePropertyConstants(out, superclassName, component);
generator.writeFacetConstants(out, component);
generator.writeGenericConstants(out, componentFamily, componentType);
// public constructors and methods
generator.writeConstructor(out, component, Modifier.PUBLIC);
// insert template code
if (template != null)
{
template.writeContent(out);
template.close();
}
generator.writeFacetMethods(out, component);
if (template == null)
{
generator.writePropertyMethods(out, component);
}
else
{
generator.writePropertyMethods(out, component, template.getIgnoreMethods());
}
if (!suppressListenerMethods)
{
generator.writeListenerMethods(out, component);
}
generator.writeStateManagementMethods(out, component);
generator.writeGetFamily(out);
// protected constructors and methods
// TODO: reverse this order, to make protected constructor go first
// for now we want consistency with previous code generation
generator.writeOther(out, component);
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.getParentFile().mkdirs();
targetFile.delete();
FileWriter fw = new FileWriter(targetFile);
StringBuffer buf = sw.getBuffer();
fw.write(buf.toString());
fw.close();
targetFile.setReadOnly();
}
}
catch (IOException e)
{
getLog().error("Error generating " + fullClassName, e);
}
}