polishing

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3492 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-07-20 20:02:43 +00:00
parent 424e10e173
commit 038ee9ff86
2 changed files with 11 additions and 29 deletions

View File

@ -1,12 +1,12 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -34,7 +34,7 @@ public interface MessageSourceResolvable {
* they should get tried. The last code will therefore be the default one. * they should get tried. The last code will therefore be the default one.
* @return a String array of codes which are associated with this message * @return a String array of codes which are associated with this message
*/ */
public String[] getCodes(); String[] getCodes();
/** /**
* Return the array of arguments to be used to resolve this message. * Return the array of arguments to be used to resolve this message.
@ -42,12 +42,12 @@ public interface MessageSourceResolvable {
* placeholders within the message text * placeholders within the message text
* @see java.text.MessageFormat * @see java.text.MessageFormat
*/ */
public Object[] getArguments(); Object[] getArguments();
/** /**
* Return the default message to be used to resolve this message. * Return the default message to be used to resolve this message.
* @return the default message, or <code>null</code> if no default * @return the default message, or <code>null</code> if no default
*/ */
public String getDefaultMessage(); String getDefaultMessage();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -148,8 +148,9 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
return msg; return msg;
} }
} }
if (resolvable.getDefaultMessage() != null) { String defaultMessage = resolvable.getDefaultMessage();
return renderDefaultMessage(resolvable.getDefaultMessage(), resolvable.getArguments(), locale); if (defaultMessage != null) {
return renderDefaultMessage(defaultMessage, resolvable.getArguments(), locale);
} }
if (codes.length > 0) { if (codes.length > 0) {
String fallback = getDefaultMessage(codes[0]); String fallback = getDefaultMessage(codes[0]);
@ -256,25 +257,6 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
return null; return null;
} }
/**
* Render the given default message String. The default message is passed in
* as specified by the caller and can be rendered into a fully formatted
* default message shown to the user.
* <p>The default implementation passes the String to {@link #formatMessage},
* resolving any argument placeholders found in them. Subclasses may override
* this method to plug in custom processing of default messages.
* @param defaultMessage the passed-in default message String
* @param args array of arguments that will be filled in for params within
* the message, or <code>null</code> if none.
* @param locale the Locale used for formatting
* @return the rendered default message (with resolved arguments)
* @see #formatMessage(String, Object[], java.util.Locale)
*/
@Override
protected String renderDefaultMessage(String defaultMessage, Object[] args, Locale locale) {
return formatMessage(defaultMessage, args, locale);
}
/** /**
* Searches through the given array of objects, finds any MessageSourceResolvable * Searches through the given array of objects, finds any MessageSourceResolvable