several bug fixes

This commit is contained in:
Keith Donald
2008-04-01 22:49:10 +00:00
parent 4df670ae70
commit c579f1852b
9 changed files with 251 additions and 9 deletions

View File

@@ -52,9 +52,8 @@ class DefaultMessageContext implements StateManageableMessageContext {
public Message[] getAllMessages() {
List messages = new ArrayList();
Iterator it = objectMessages.keySet().iterator();
while (it.hasNext()) {
messages.addAll((List) objectMessages.get(it.next()));
for (Iterator it = objectMessages.values().iterator(); it.hasNext();) {
messages.addAll((List) it.next());
}
return (Message[]) messages.toArray(new Message[messages.size()]);
}
@@ -80,6 +79,20 @@ class DefaultMessageContext implements StateManageableMessageContext {
return (Message[]) messages.toArray(new Message[messages.size()]);
}
public boolean hasErrorMessages() {
Iterator it = objectMessages.values().iterator();
while (it.hasNext()) {
List sourceMessages = (List) it.next();
for (Iterator it2 = sourceMessages.iterator(); it2.hasNext();) {
Message message = (Message) it2.next();
if (message.getSeverity() == Severity.ERROR) {
return true;
}
}
}
return false;
}
public void addMessage(MessageResolver messageResolver) {
Locale currentLocale = LocaleContextHolder.getLocale();
Message message = messageResolver.resolveMessage(messageSource, currentLocale);

View File

@@ -1,6 +1,7 @@
package org.springframework.binding.message;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
@@ -84,6 +85,18 @@ public class MessageBuilder {
return this;
}
/**
* Records that the message being built should try and resolve its text using the codes provided. Adds the codes to
* the codes list. Successive calls to this method add additional codes. Codes are applied in the order they are
* added.
* @param codes the message codes
* @return this, for fluent API usage
*/
public MessageBuilder codes(String[] codes) {
this.codes.add(Arrays.asList(codes));
return this;
}
/**
* Records that the message being built has a variable argument. Adds the arg to the args list. Successive calls to
* this method add additional args. Args are applied in the order they are added.
@@ -95,6 +108,17 @@ public class MessageBuilder {
return this;
}
/**
* Records that the message being built has variable arguments. Adds the args to the args list. Successive calls to
* this method add additional args. Args are applied in the order they are added.
* @param arg the message argument value
* @return this, for fluent API usage
*/
public MessageBuilder args(Object[] args) {
this.args.add(Arrays.asList(args));
return this;
}
/**
* Records that the message being built has a variable argument, whose display value is also
* {@link MessageSourceResolvable}. Adds the arg to the args list. Successive calls to this method add additional
@@ -107,6 +131,20 @@ public class MessageBuilder {
return this;
}
/**
* Records that the message being built has variable arguments, whose display values are also
* {@link MessageSourceResolvable} instances. Adds the args to the args list. Successive calls to this method add
* additional resolvable args. Args are applied in the order they are added.
* @param args the resolvable message arguments
* @return this, for fluent API usage
*/
public MessageBuilder resolvableArgs(Object[] args) {
for (int i = 0; i < args.length; i++) {
this.args.add(new ResolvableArgument(args[i]));
}
return this;
}
/**
* Records the fallback text of the message being built. If the message has no codes, this will always be used as
* the text. If the message has codes but none can be resolved, this will alway be used as the text.

View File

@@ -24,6 +24,12 @@ public interface MessageContext {
*/
public Message[] getMessagesByCriteria(MessageCriteria criteria);
/**
* Returns true if there are error messages in this context.
* @return error messages
*/
public boolean hasErrorMessages();
/**
* Add a new message to this context.
* @param messageResolver the resolver that will resolve the message to be added