Source Code Cross Referenced for MessageSourceAccessor.java in  » J2EE » spring-framework-2.0.6 » org » springframework » context » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.context.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2005 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.context.support;
018:
019:        import java.util.Locale;
020:
021:        import org.springframework.context.MessageSource;
022:        import org.springframework.context.MessageSourceResolvable;
023:        import org.springframework.context.NoSuchMessageException;
024:        import org.springframework.context.i18n.LocaleContextHolder;
025:
026:        /**
027:         * Helper class for easy access to messages from a MessageSource,
028:         * providing various overloaded getMessage methods.
029:         *
030:         * <p>Available from ApplicationObjectSupport, but also reusable
031:         * as a standalone helper to delegate to in application objects.
032:         *
033:         * @author Juergen Hoeller
034:         * @since 23.10.2003
035:         * @see ApplicationObjectSupport#getMessageSourceAccessor
036:         */
037:        public class MessageSourceAccessor {
038:
039:            private final MessageSource messageSource;
040:
041:            private final Locale defaultLocale;
042:
043:            /**
044:             * Create a new MessageSourceAccessor, using LocaleContextHolder's locale
045:             * as default locale.
046:             * @param messageSource the MessageSource to wrap
047:             * @see org.springframework.context.i18n.LocaleContextHolder#getLocale()
048:             */
049:            public MessageSourceAccessor(MessageSource messageSource) {
050:                this .messageSource = messageSource;
051:                this .defaultLocale = null;
052:            }
053:
054:            /**
055:             * Create a new MessageSourceAccessor, using the given default locale.
056:             * @param messageSource the MessageSource to wrap
057:             * @param defaultLocale the default locale to use for message access
058:             */
059:            public MessageSourceAccessor(MessageSource messageSource,
060:                    Locale defaultLocale) {
061:                this .messageSource = messageSource;
062:                this .defaultLocale = defaultLocale;
063:            }
064:
065:            /**
066:             * Return the default locale to use if no explicit locale has been given.
067:             * <p>The default implementation returns the default locale passed into the
068:             * corresponding constructor, or LocaleContextHolder's locale as fallback.
069:             * Can be overridden in subclasses.
070:             * @see #MessageSourceAccessor(org.springframework.context.MessageSource, java.util.Locale)
071:             * @see org.springframework.context.i18n.LocaleContextHolder#getLocale()
072:             */
073:            protected Locale getDefaultLocale() {
074:                return (this .defaultLocale != null ? this .defaultLocale
075:                        : LocaleContextHolder.getLocale());
076:            }
077:
078:            /**
079:             * Retrieve the message for the given code and the default Locale.
080:             * @param code code of the message
081:             * @param defaultMessage String to return if the lookup fails
082:             * @return the message
083:             */
084:            public String getMessage(String code, String defaultMessage) {
085:                return this .messageSource.getMessage(code, null,
086:                        defaultMessage, getDefaultLocale());
087:            }
088:
089:            /**
090:             * Retrieve the message for the given code and the given Locale.
091:             * @param code code of the message
092:             * @param defaultMessage String to return if the lookup fails
093:             * @param locale Locale in which to do lookup
094:             * @return the message
095:             */
096:            public String getMessage(String code, String defaultMessage,
097:                    Locale locale) {
098:                return this .messageSource.getMessage(code, null,
099:                        defaultMessage, locale);
100:            }
101:
102:            /**
103:             * Retrieve the message for the given code and the default Locale.
104:             * @param code code of the message
105:             * @param args arguments for the message, or <code>null</code> if none
106:             * @param defaultMessage String to return if the lookup fails
107:             * @return the message
108:             */
109:            public String getMessage(String code, Object[] args,
110:                    String defaultMessage) {
111:                return this .messageSource.getMessage(code, args,
112:                        defaultMessage, getDefaultLocale());
113:            }
114:
115:            /**
116:             * Retrieve the message for the given code and the given Locale.
117:             * @param code code of the message
118:             * @param args arguments for the message, or <code>null</code> if none
119:             * @param defaultMessage String to return if the lookup fails
120:             * @param locale Locale in which to do lookup
121:             * @return the message
122:             */
123:            public String getMessage(String code, Object[] args,
124:                    String defaultMessage, Locale locale) {
125:                return this .messageSource.getMessage(code, args,
126:                        defaultMessage, locale);
127:            }
128:
129:            /**
130:             * Retrieve the message for the given code and the default Locale.
131:             * @param code code of the message
132:             * @return the message
133:             * @throws org.springframework.context.NoSuchMessageException if not found
134:             */
135:            public String getMessage(String code) throws NoSuchMessageException {
136:                return this .messageSource.getMessage(code, null,
137:                        getDefaultLocale());
138:            }
139:
140:            /**
141:             * Retrieve the message for the given code and the given Locale.
142:             * @param code code of the message
143:             * @param locale Locale in which to do lookup
144:             * @return the message
145:             * @throws org.springframework.context.NoSuchMessageException if not found
146:             */
147:            public String getMessage(String code, Locale locale)
148:                    throws NoSuchMessageException {
149:                return this .messageSource.getMessage(code, null, locale);
150:            }
151:
152:            /**
153:             * Retrieve the message for the given code and the default Locale.
154:             * @param code code of the message
155:             * @param args arguments for the message, or <code>null</code> if none
156:             * @return the message
157:             * @throws org.springframework.context.NoSuchMessageException if not found
158:             */
159:            public String getMessage(String code, Object[] args)
160:                    throws NoSuchMessageException {
161:                return this .messageSource.getMessage(code, args,
162:                        getDefaultLocale());
163:            }
164:
165:            /**
166:             * Retrieve the message for the given code and the given Locale.
167:             * @param code code of the message
168:             * @param args arguments for the message, or <code>null</code> if none
169:             * @param locale Locale in which to do lookup
170:             * @return the message
171:             * @throws org.springframework.context.NoSuchMessageException if not found
172:             */
173:            public String getMessage(String code, Object[] args, Locale locale)
174:                    throws NoSuchMessageException {
175:                return this .messageSource.getMessage(code, args, locale);
176:            }
177:
178:            /**
179:             * Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance)
180:             * in the default Locale.
181:             * @param resolvable the MessageSourceResolvable
182:             * @return the message
183:             * @throws org.springframework.context.NoSuchMessageException if not found
184:             */
185:            public String getMessage(MessageSourceResolvable resolvable)
186:                    throws NoSuchMessageException {
187:                return this .messageSource.getMessage(resolvable,
188:                        getDefaultLocale());
189:            }
190:
191:            /**
192:             * Retrieve the given MessageSourceResolvable (e.g. an ObjectError instance)
193:             * in the given Locale.
194:             * @param resolvable the MessageSourceResolvable
195:             * @param locale Locale in which to do lookup
196:             * @return the message
197:             * @throws org.springframework.context.NoSuchMessageException if not found
198:             */
199:            public String getMessage(MessageSourceResolvable resolvable,
200:                    Locale locale) throws NoSuchMessageException {
201:                return this.messageSource.getMessage(resolvable, locale);
202:            }
203:
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.