if ( associatedResources != null && associatedResources.size() > 0 ) {
for ( final String resourceTypeName : associatedResources ) {
final TypeElement type = processingEnvironment.getElementUtils().getTypeElement( resourceTypeName );
if ( type.getAnnotation( ApplicationScoped.class ) == null ) {
throw new GenerationException( "The '" + resourceTypeName + "' must be ApplicationScope`d ." );
}
}
}
final String onStartup1ParameterMethodName = GeneratorUtils.getOnStartupPathParameterMethodName( classElement,
processingEnvironment );
final String onStartup2ParametersMethodName = GeneratorUtils.getOnStartupPathPlaceRequestParametersMethodName( classElement,
processingEnvironment );
final String onMayCloseMethodName = GeneratorUtils.getOnMayCloseMethodName( classElement,
processingEnvironment );
final String onCloseMethodName = GeneratorUtils.getOnCloseMethodName( classElement,
processingEnvironment );
final String onShutdownMethodName = GeneratorUtils.getOnShutdownMethodName( classElement,
processingEnvironment );
final String onOpenMethodName = GeneratorUtils.getOnOpenMethodName( classElement,
processingEnvironment );
final String onLostFocusMethodName = GeneratorUtils.getOnLostFocusMethodName( classElement,
processingEnvironment );
final String onFocusMethodName = GeneratorUtils.getOnFocusMethodName( classElement,
processingEnvironment );
final String getDefaultPositionMethodName = GeneratorUtils.getDefaultPositionMethodName( classElement,
processingEnvironment );
final String getTitleMethodName = GeneratorUtils.getTitleMethodName( classElement,
processingEnvironment );
final String getContextIdMethodName = GeneratorUtils.getContextIdMethodName( classElement,
processingEnvironment );
final ExecutableElement getTitleWidgetMethod = GeneratorUtils.getTitleWidgetMethodName( classElement,
processingEnvironment );
final String getTitleWidgetMethodName = getTitleWidgetMethod == null ? null : getTitleWidgetMethod.getSimpleName().toString();
final ExecutableElement getWidgetMethod = GeneratorUtils.getWidgetMethodName( classElement,
processingEnvironment );
final String getWidgetMethodName = getWidgetMethod == null ? null : getWidgetMethod.getSimpleName().toString();
final boolean hasUberView = GeneratorUtils.hasUberViewReference( classElement,
processingEnvironment,
getWidgetMethod );
final boolean isWidget = GeneratorUtils.getIsWidget( classElement,
processingEnvironment );
final String isDirtyMethodName = GeneratorUtils.getIsDirtyMethodName( classElement,
processingEnvironment );
final String onSaveMethodName = GeneratorUtils.getOnSaveMethodName( classElement,
processingEnvironment );
final String getMenuBarMethodName = GeneratorUtils.getMenuBarMethodName( classElement,
processingEnvironment );
final String getToolBarMethodName = GeneratorUtils.getToolBarMethodName( classElement,
processingEnvironment );
final String securityTraitList = GeneratorUtils.getSecurityTraitList( classElement );
final String rolesList = GeneratorUtils.getRoleList( classElement );
logger.debug( "Package name: " + packageName );
logger.debug( "Class name: " + className );
logger.debug( "Identifier: " + identifier );
logger.debug( "getContextIdMethodName: " + getContextIdMethodName );
logger.debug( "Priority: " + priority );
logger.debug( "Resource types: " + associatedResources );
logger.debug( "Preferred Height: " + preferredHeight );
logger.debug( "Preferred Width: " + preferredWidth );
logger.debug( "onStartup1ParameterMethodName: " + onStartup1ParameterMethodName );
logger.debug( "onStartup2ParametersMethodName: " + onStartup2ParametersMethodName );
logger.debug( "onMayCloseMethodName: " + onMayCloseMethodName );
logger.debug( "onCloseMethodName: " + onCloseMethodName );
logger.debug( "onShutdownMethodName: " + onShutdownMethodName );
logger.debug( "onOpenMethodName: " + onOpenMethodName );
logger.debug( "onLostFocusMethodName: " + onLostFocusMethodName );
logger.debug( "onFocusMethodName: " + onFocusMethodName );
logger.debug( "getDefaultPositionMethodName: " + getDefaultPositionMethodName );
logger.debug( "getTitleMethodName: " + getTitleMethodName );
logger.debug( "getTitleWidgetMethodName: " + getTitleWidgetMethodName );
logger.debug( "getWidgetMethodName: " + getWidgetMethodName );
logger.debug( "isWidget: " + Boolean.toString( isWidget ) );
logger.debug( "hasUberView: " + Boolean.toString( hasUberView ) );
logger.debug( "isDirtyMethodName: " + isDirtyMethodName );
logger.debug( "onSaveMethodName: " + onSaveMethodName );
logger.debug( "getMenuBarMethodName: " + getMenuBarMethodName );
logger.debug( "getToolBarMethodName: " + getToolBarMethodName );
logger.debug( "securityTraitList: " + securityTraitList );
logger.debug( "rolesList: " + rolesList );
//Validate getWidgetMethodName and isWidget
if ( !isWidget && getWidgetMethodName == null ) {
throw new GenerationException( "The WorkbenchEditor must either extend IsWidget or provide a @WorkbenchPartView annotated method to return a com.google.gwt.user.client.ui.IsWidget.", packageName + "." + className );
}
if ( isWidget && getWidgetMethodName != null ) {
final String msg = "The WorkbenchEditor both extends com.google.gwt.user.client.ui.IsWidget and provides a @WorkbenchPartView annotated method. The annotated method will take precedence.";
processingEnvironment.getMessager().printMessage( Kind.WARNING,
msg );
logger.warn( msg );
}
//Validate onStartup1ParameterMethodName and onStartup2ParametersMethodName
if ( onStartup1ParameterMethodName != null && onStartup2ParametersMethodName != null ) {
final String msg = "The WorkbenchEditor has methods for both @OnStartup(Path) and @OnStartup(Path, Place). Method @OnStartup(Path, Place) will take precedence.";
processingEnvironment.getMessager().printMessage( Kind.WARNING,
msg );
logger.warn( msg );
}
//Validate getTitleMethodName
if ( getTitleMethodName == null ) {
throw new GenerationException( "The WorkbenchEditor must provide a @WorkbenchPartTitle annotated method to return a java.lang.String.", packageName + "." + className );
}
//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( "getContextIdMethodName",
getContextIdMethodName );
root.put( "priority",
priority.toString().replace( ",", "" ) );
root.put( "associatedResources",
GeneratorUtils.formatAssociatedResources( associatedResources ) );
root.put( "preferredHeight",
preferredHeight );
root.put( "preferredWidth",
preferredWidth );
root.put( "realClassName",
classElement.getSimpleName().toString() );
root.put( "onStartup1ParameterMethodName",
onStartup1ParameterMethodName );
root.put( "onStartup2ParametersMethodName",
onStartup2ParametersMethodName );
root.put( "onMayCloseMethodName",
onMayCloseMethodName );
root.put( "onCloseMethodName",
onCloseMethodName );
root.put( "onShutdownMethodName",
onShutdownMethodName );
root.put( "onOpenMethodName",
onOpenMethodName );
root.put( "onLostFocusMethodName",
onLostFocusMethodName );
root.put( "onFocusMethodName",
onFocusMethodName );
root.put( "getDefaultPositionMethodName",
getDefaultPositionMethodName );
root.put( "getTitleMethodName",
getTitleMethodName );
root.put( "getTitleWidgetMethodName",
getTitleWidgetMethodName );
root.put( "getWidgetMethodName",
getWidgetMethodName );
root.put( "isWidget",
isWidget );
root.put( "hasUberView",
hasUberView );
root.put( "isDirtyMethodName",
isDirtyMethodName );
root.put( "onSaveMethodName",
onSaveMethodName );
root.put( "getMenuBarMethodName",
getMenuBarMethodName );
root.put( "getToolBarMethodName",
getToolBarMethodName );
root.put( "securityTraitList",
securityTraitList );
root.put( "rolesList",
rolesList );
//Generate code
final StringWriter sw = new StringWriter();
final BufferedWriter bw = new BufferedWriter( sw );
try {
final Template template = config.getTemplate( "activityEditor.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();