logger.debug( "rolesList: " + rolesList );
//Validate onStartup0ParameterMethodName and onStartup1ParameterMethodName
if ( onStartup0ParameterMethodName != null && onStartup1ParameterMethodName != null ) {
final String msg = "Found multiple @OnStartup methods. Each class can declare at most one.";
throw new GenerationException( msg );
}
//Validate getPerspectiveMethodName
if ( getPerspectiveMethodName == null && !isTemplate ) {
throw new GenerationException( "The WorkbenchPerspective must provide a @Perspective annotated method to return a org.uberfire.client.workbench.model.PerspectiveDefinition.", packageName + "." + className );
}
if ( isDefault ) {
warningIfMoreThanOneDefaultPerspective( processingEnvironment, identifier );
}
//Setup data for template sub-system
Map<String, Object> root = new HashMap<String, Object>();
root.put( "packageName",
packageName );
root.put( "className",
className );
root.put( "identifier",
identifier );
root.put( "isTemplate", isTemplate );
root.put( "isDefault",
isDefault );
root.put( "realClassName",
classElement.getSimpleName().toString() );
root.put( "onStartup0ParameterMethodName",
onStartup0ParameterMethodName );
root.put( "onStartup1ParameterMethodName",
onStartup1ParameterMethodName );
root.put( "onCloseMethodName",
onCloseMethodName );
root.put( "onShutdownMethodName",
onShutdownMethodName );
root.put( "onOpenMethodName",
onOpenMethodName );
root.put( "getPerspectiveMethodName",
getPerspectiveMethodName );
root.put( "getMenuBarMethodName",
getMenuBarMethodName );
root.put( "getToolBarMethodName",
getToolBarMethodName );
root.put( "securityTraitList",
securityTraitList );
root.put( "rolesList",
rolesList );
if ( isTemplate ) {
setupTemplateElements( root, classElement );
}
//Generate code
final StringWriter sw = new StringWriter();
final BufferedWriter bw = new BufferedWriter( sw );
try {
final Template template = config.getTemplate( "perspective.ftl" );
template.process( root,
bw );
} catch ( IOException ioe ) {
throw new GenerationException( ioe );
} catch ( TemplateException te ) {
throw new GenerationException( te );
} finally {
try {
bw.close();
sw.close();
} catch ( IOException ioe ) {
throw new GenerationException( ioe );
}
}
logger.debug( "Successfully generated code for [" + className + "]" );
return sw.getBuffer();