Source Code Cross Referenced for ELUtil.java in  » Scripting » JUEL » javax » el » 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 » Scripting » JUEL » javax.el 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the "License").  You may not use this file except
005:         * in compliance with the License.
006:         *
007:         * You can obtain a copy of the license at
008:         * glassfish/bootstrap/legal/CDDLv1.0.txt or
009:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
010:         * See the License for the specific language governing
011:         * permissions and limitations under the License.
012:         *
013:         * When distributing Covered Code, include this CDDL
014:         * HEADER in each file and include the License file at
015:         * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable,
016:         * add the following below this CDDL HEADER, with the
017:         * fields enclosed by brackets "[]" replaced with your
018:         * own identifying information: Portions Copyright [yyyy]
019:         * [name of copyright owner]
020:         *
021:         * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
022:         */
023:
024:        package javax.el;
025:
026:        import java.text.MessageFormat;
027:        import java.util.HashMap;
028:        import java.util.Locale;
029:        import java.util.Map;
030:        import java.util.MissingResourceException;
031:        import java.util.ResourceBundle;
032:
033:        /**
034:         *
035:         * <p>Utility methods for this portion of the EL implementation</p>
036:         *
037:         * <p>Methods on this class use a Map instance stored in ThreadLocal storage
038:         * to minimize the performance impact on operations that take place multiple
039:         * times on a single Thread.  The keys and values of the Map
040:         * are implementation private.</p>
041:         *
042:         * @author edburns
043:         */
044:        class ELUtil {
045:
046:            /**
047:             * <p>This class may not be constructed.</p>
048:             */
049:
050:            private ELUtil() {
051:            }
052:
053:            /**
054:             * <p>The <code>ThreadLocal</code> variable used to record the
055:             * {@link FacesContext} instance for each processing thread.</p>
056:             */
057:            private static ThreadLocal instance = new ThreadLocal() {
058:                protected Object initialValue() {
059:                    return (null);
060:                }
061:            };
062:
063:            /**
064:             * @return a Map stored in ThreadLocal storage.  This may
065:             * be used by methods of this class to minimize the performance
066:             * impact for operations that may take place multiple times on a given
067:             * Thread instance.
068:             */
069:
070:            private static Map getCurrentInstance() {
071:                Map result = (Map) instance.get();
072:                if (null == result) {
073:                    result = new HashMap();
074:                    setCurrentInstance(result);
075:                }
076:                return result;
077:
078:            }
079:
080:            /**
081:             * <p>Replace the Map with the argument context.</p>
082:             *
083:             * @param context the Map to be stored in ThreadLocal storage.
084:             */
085:
086:            private static void setCurrentInstance(Map context) {
087:
088:                instance.set(context);
089:
090:            }
091:
092:            /*
093:             * <p>Convenience method, calls through to 
094:             * {@link #getExceptionMessageString(javax.el.ELContext,java.lang.String,Object []).
095:             * </p>
096:             *
097:             * @param context the ELContext from which the Locale for this message
098:             * is extracted.
099:             *
100:             * @param messageId the messageId String in the ResourceBundle
101:             *
102:             * @return a localized String for the argument messageId
103:             */
104:
105:            public static String getExceptionMessageString(ELContext context,
106:                    String messageId) {
107:                return getExceptionMessageString(context, messageId, null);
108:            }
109:
110:            /*
111:             * <p>Return a Localized message String suitable for use as an Exception message.
112:             * Examine the argument <code>context</code> for a <code>Locale</code>.  If
113:             * not present, use <code>Locale.getDefault()</code>.  Load the 
114:             * <code>ResourceBundle</code> "javax.el.Messages" using that locale.  Get
115:             * the message string for argument <code>messageId</code>.  If not found
116:             * return "Missing Resource in EL implementation ??? messageId ???" 
117:             * with messageId substituted with the runtime
118:             * value of argument <code>messageId</code>.  If found, and argument
119:             * <code>params</code> is non-null, format the message using the 
120:             * params.  If formatting fails, return a sensible message including 
121:             * the <code>messageId</code>.  If argument <code>params</code> is 
122:             * <code>null</code>, skip formatting and return the message directly, otherwise
123:             * return the formatted message.</p>
124:             *
125:             * @param context the ELContext from which the Locale for this message
126:             * is extracted.
127:             *
128:             * @param messageId the messageId String in the ResourceBundle
129:             *
130:             * @param params parameters to the message
131:             *
132:             * @return a localized String for the argument messageId
133:             */
134:
135:            public static String getExceptionMessageString(ELContext context,
136:                    String messageId, Object[] params) {
137:                String result = "";
138:                Locale locale = null;
139:
140:                if (null == context || null == messageId) {
141:                    return result;
142:                }
143:
144:                if (null == (locale = context.getLocale())) {
145:                    locale = Locale.getDefault();
146:                }
147:                if (null != locale) {
148:                    Map threadMap = getCurrentInstance();
149:                    ResourceBundle rb = null;
150:                    if (null == (rb = (ResourceBundle) threadMap.get(locale
151:                            .toString()))) {
152:                        rb = ResourceBundle.getBundle(
153:                                "javax.el.PrivateMessages", locale);
154:                        threadMap.put(locale.toString(), rb);
155:                    }
156:                    if (null != rb) {
157:                        try {
158:                            result = rb.getString(messageId);
159:                            if (null != params) {
160:                                result = MessageFormat.format(result, params);
161:                            }
162:                        } catch (IllegalArgumentException iae) {
163:                            result = "Can't get localized message: parameters to message appear to be incorrect.  Message to format: "
164:                                    + messageId;
165:                        } catch (MissingResourceException mre) {
166:                            result = "Missing Resource in EL implementation: ???"
167:                                    + messageId + "???";
168:                        } catch (Exception e) {
169:                            result = "Exception resolving message in EL implementation: ???"
170:                                    + messageId + "???";
171:                        }
172:                    }
173:                }
174:
175:                return result;
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.