use of com.sun.enterprise.util.LocalStringManagerImpl in project Payara by payara.
the class ActionReporter method getCombinedMessages.
/**
* Returns combined messages. Meant mainly for long running
* operations where some of the intermediate steps can go wrong, although
* overall operation succeeds. Does nothing if either of the arguments are null.
* The traversal visits the message of current reporter first. The various
* parts of the message are separated by EOL_MARKERs.
* <p>
* Note: This method is a recursive implementation.
* @param aReport a given (usually top-level) ActionReporter instance
* @param sb StringBuilder instance that contains all the messages
*/
public void getCombinedMessages(ActionReporter aReport, StringBuilder sb) {
if (aReport == null || sb == null)
return;
// this is the message related to the topMessage
String mainMsg = "";
// this is the message related to failure cause
String failMsg;
// and also set report.setFailureCause(exception). We need to avoid the duplicate message.
if (aReport.getMessage() != null && aReport.getMessage().length() != 0) {
mainMsg = aReport.getMessage();
String format = "{0}";
if (ActionReport.ExitCode.WARNING.equals(aReport.getActionExitCode())) {
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ActionReporter.class);
format = localStrings.getLocalString("flag.message.as.warning", "Warning: {0}");
}
if (ActionReport.ExitCode.FAILURE.equals(aReport.getActionExitCode())) {
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ActionReporter.class);
format = localStrings.getLocalString("flag.message.as.failure", "Failure: {0}");
}
if (sb.length() > 0)
sb.append(EOL_MARKER);
sb.append(MessageFormat.format(format, mainMsg));
}
if (aReport.getFailureCause() != null && aReport.getFailureCause().getMessage() != null && aReport.getFailureCause().getMessage().length() != 0) {
failMsg = aReport.getFailureCause().getMessage();
if (!failMsg.equals(mainMsg)) {
if (sb.length() > 0)
sb.append(EOL_MARKER);
sb.append(failMsg);
}
}
for (ActionReporter sub : aReport.subActions) {
getCombinedMessages(sub, sb);
}
}
use of com.sun.enterprise.util.LocalStringManagerImpl in project Payara by payara.
the class CommandModelImpl method init.
public static Map<String, ParamModel> init(Class commandType, I18n i18n, LocalStringManager localStrings) {
Class currentClazz = commandType;
Map<String, ParamModel> results = new LinkedHashMap<String, ParamModel>();
while (currentClazz != null) {
for (Field f : currentClazz.getDeclaredFields()) {
I18n fieldI18n = f.getAnnotation(I18n.class);
if (fieldI18n != null) {
localStrings = new LocalStringManagerImpl(commandType);
}
add(results, f, i18n, localStrings);
}
for (Method m : currentClazz.getDeclaredMethods()) {
I18n fieldI18n = m.getAnnotation(I18n.class);
if (fieldI18n != null) {
localStrings = new LocalStringManagerImpl(commandType);
}
add(results, m, i18n, localStrings);
}
currentClazz = currentClazz.getSuperclass();
}
return results;
}
use of com.sun.enterprise.util.LocalStringManagerImpl in project Payara by payara.
the class GenericCreateCommand method postConstruct.
@Override
public void postConstruct() {
super.postConstruct();
create = getAnnotation(targetMethod, Create.class);
resolverType = create.resolver();
try {
model = new GenericCommandModel(targetType, true, create.cluster(), create.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, AnnotationUtil.presentTransitive(ManagedJob.class, create.decorator()), create.resolver(), create.decorator());
if (LOGGER.isLoggable(level)) {
for (String paramName : model.getParametersNames()) {
CommandModel.ParamModel param = model.getModelFor(paramName);
LOGGER.log(Level.FINE, "I take {0} parameters", param.getName());
}
}
} catch (Exception e) {
String msg = LOCAL_STRINGS.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage());
LOGGER.log(Level.SEVERE, ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, commandName);
throw new RuntimeException(msg, e);
}
}
use of com.sun.enterprise.util.LocalStringManagerImpl in project Payara by payara.
the class ArchiveClassesLoadableHelper method getFailedResult.
/**
* This method is used to print the result in various
* *ArchiveClassesLoadable tests.
* @param cc a closure compiler which provides the necesasry information
* @return a localized string which contains the details.
*/
public static String getFailedResult(ClosureCompiler cc) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
for (Object o : cc.getFailed().entrySet()) {
Map.Entry<String, List<String>> referencingPathToFailedList = (Map.Entry<String, List<String>>) o;
LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
String classes = "Failed to find following classes:";
if (smh != null) {
classes = smh.getLocalString(ArchiveClassesLoadableHelper.class.getName() + ".classes", classes);
}
sb.append(classes).append("\n[");
for (Iterator<String> iii = referencingPathToFailedList.getValue().iterator(); iii.hasNext(); ) {
sb.append("\n\t").append(iii.next());
if (iii.hasNext())
sb.append(",");
}
sb.append("\n]");
String referencingPath = referencingPathToFailedList.getKey();
// skip if a top level class is not found
if (referencingPath.length() == 0)
continue;
String ref = "referenced in the following call stack :\n";
String reference = "at";
if (smh != null) {
ref = smh.getLocalString(ArchiveClassesLoadableHelper.class.getName() + ".ref", ref);
reference = smh.getLocalString(ArchiveClassesLoadableHelper.class.getName() + ".reference", reference);
}
StringTokenizer st = new StringTokenizer(referencingPath, File.separator);
Stack<String> referencingClassStack = new Stack<String>();
while (st.hasMoreTokens()) {
referencingClassStack.push(st.nextToken());
}
if (!referencingClassStack.isEmpty())
sb.append("\n\n" + ref);
while (!referencingClassStack.isEmpty()) {
sb.append("\n\t").append(reference).append(" ");
sb.append(referencingClassStack.pop());
}
sb.append("\n\n");
}
return sb.toString();
}
use of com.sun.enterprise.util.LocalStringManagerImpl in project Payara by payara.
the class WebArchiveLoadableHelper method getFailedResults.
public static String getFailedResults(ClosureCompiler cc, File jspDir) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
for (Object o : cc.getFailed().entrySet()) {
Map.Entry<String, List<String>> referencingPathToFailedList = (Map.Entry<String, List<String>>) o;
LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
String classes = "Failed to find following classes:";
if (smh != null) {
classes = smh.getLocalString(WebArchiveLoadableHelper.class.getName() + ".classes", classes);
}
sb.append(classes).append("\n[");
for (Iterator<String> iii = referencingPathToFailedList.getValue().iterator(); iii.hasNext(); ) {
sb.append("\n\t").append(iii.next());
if (iii.hasNext())
sb.append(",");
}
sb.append("\n]");
String referencingPath = referencingPathToFailedList.getKey();
// skip if a top level class is not found
if (referencingPath.length() == 0)
continue;
String ref = "referenced in the following call stack :";
String reference = "at";
if (smh != null) {
ref = smh.getLocalString(WebArchiveLoadableHelper.class.getName() + ".ref", ref);
reference = smh.getLocalString(WebArchiveLoadableHelper.class.getName() + ".reference", reference);
}
StringTokenizer st = new StringTokenizer(referencingPath, File.separator);
Stack<String> referencingClassStack = new Stack<String>();
boolean jspDirExists = (jspDir != null && jspDir.exists());
final String jspPkgName = "org.apache.jsp.";
while (st.hasMoreTokens()) {
String className = st.nextToken();
// This logic is to map the compiled jsp class to original jsp name.
// The logic is to find whether the ref class is in jsp out dir. If true
// then maniputale the ref class to get the jsp name
String fileName = className.replace(".", File.separator) + ".class";
if (jspDirExists && className.startsWith(jspPkgName) && new File(jspDir, fileName).exists()) {
StringBuilder jspName = new StringBuilder(className.substring(jspPkgName.length()));
int innerClassIndex = jspName.indexOf("$");
if (innerClassIndex != -1) {
jspName = jspName.replace(innerClassIndex, jspName.length(), "");
}
if (jspName.toString().endsWith("_jsp")) {
jspName = jspName.replace(jspName.lastIndexOf("_jsp"), jspName.length(), ".jsp");
} else if (jspName.toString().endsWith("_jspx")) {
jspName = jspName.replace(jspName.lastIndexOf("_jspx"), jspName.length(), ".jspx");
}
className = jspName.toString();
}
referencingClassStack.push(className);
}
if ((!referencingClassStack.isEmpty()))
sb.append("\n\n" + ref);
while (!referencingClassStack.isEmpty()) {
sb.append("\n\t").append(reference).append(" ");
sb.append(referencingClassStack.pop());
}
sb.append("\n\n");
}
return sb.toString();
}
Aggregations