// Since they want all locales, this is guaranteed to be one of them.
found = true;
}
if (found) {
for (String genClassName : generate.format()) {
MessageCatalogFormat msgWriter = null;
try {
Class<? extends MessageCatalogFormat> msgFormatClass = Class.forName(
genClassName, false,
MessageCatalogFormat.class.getClassLoader()).asSubclass(
MessageCatalogFormat.class);
msgWriter = msgFormatClass.newInstance();
} catch (InstantiationException e) {
logger.log(TreeLogger.ERROR, "Error instantiating @Generate class "
+ genClassName, e);
seenError = true;
continue;
} catch (IllegalAccessException e) {
logger.log(TreeLogger.ERROR, "@Generate class " + genClassName
+ " illegal access", e);
seenError = true;
continue;
} catch (ClassNotFoundException e) {
logger.log(TreeLogger.ERROR, "@Generate class " + genClassName
+ " not found");
seenError = true;
continue;
}
// Make generator-specific changes to a temporary copy of the path.
String genPath = path;
if (genLocales.length != 1) {
// If the user explicitly specified only one locale, do not add the
// locale.
genPath += '_' + locale.toString();
}
genPath += msgWriter.getExtension();
OutputStream outStr = context.tryCreateResource(logger, genPath);
if (outStr != null) {
TreeLogger branch = logger.branch(TreeLogger.INFO, "Generating "
+ genPath + " from " + className + " for locale " + locale,
null);
PrintWriter out = null;
try {
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
outStr, "UTF-8")), false);
} catch (UnsupportedEncodingException e) {
throw error(logger, e.getMessage());
}
try {
// TODO(jat): change writer interface to use GwtLocale
msgWriter.write(branch, locale.toString(), resourceList, out,
targetClass);
out.flush();
context.commitResource(logger, outStr).setPrivate(true);
} catch (UnableToCompleteException e) {
// msgWriter should have already logged an error message.