Source Code Cross Referenced for UserContext.java in  » Database-ORM » Velosurf » velosurf » util » 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 » Database ORM » Velosurf » velosurf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003 The Apache Software Foundation.
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 velosurf.util;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:        import java.util.Locale;
022:        import java.util.Arrays;
023:        import java.util.Map;
024:        import java.util.HashMap;
025:        import java.text.MessageFormat;
026:
027:        import velosurf.web.l10n.Localizer;
028:        import velosurf.model.Entity;
029:
030:        /**
031:         * Used to store contextual values relatives to the user (in a web context, there is one UserContext per http session).
032:         *
033:         * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
034:         */
035:        public class UserContext {
036:
037:            /** key used to store the user context in the http session.
038:             */
039:            public static final String USER_CONTEXT_KEY = "velosurf.util.UserContext:session-key";
040:
041:            /**
042:             * Constructor.
043:             */
044:            public UserContext() {
045:                //        Logger.dumpStack();
046:            }
047:
048:            /**
049:             * Last error setter.
050:             * @param err error
051:             */
052:            public synchronized void setError(String err) {
053:                error = err;
054:            }
055:
056:            /**
057:             * Last error getter.
058:             * @return last error message.
059:             */
060:            public String getError() {
061:                return error;
062:            }
063:
064:            /** Localizer setter.
065:             *
066:             * @param loc localizer
067:             */
068:            public synchronized void setLocalizer(Localizer loc) {
069:                localizer = loc;
070:            }
071:
072:            /** Locale setter.
073:             *
074:             * @param loc Locale
075:             */
076:            public synchronized void setLocale(Locale loc) {
077:                locale = loc;
078:            }
079:
080:            /**
081:             * Localize a parameterized message.
082:             * @param str message to localize
083:             * @param params parameters that are meant to replace "{0}", "{1}", ... in the message
084:             * @return localized message
085:             */
086:            public String localize(String str, Object... params) {
087:                if (localizer == null) {
088:                    return MessageFormat.format(str, params);
089:                } else if (params.length == 0) {
090:                    return localizer.get(str);
091:                } else {
092:                    return localizer.get(str, params);
093:                }
094:            }
095:
096:            /**
097:             * Clear validation errors.
098:             */
099:            public synchronized void clearValidationErrors() {
100:                validationErrors.clear();
101:            }
102:
103:            /**
104:             * Add a validation error.
105:             * @param err validation error
106:             */
107:            public synchronized void addValidationError(String err) {
108:                validationErrors.add(err);
109:            }
110:
111:            /** Get all validation error messages.
112:             *
113:             * @return validation error messages
114:             */
115:            public synchronized List<String> getValidationErrors() {
116:                /* returning null allows a test like "#if($db.validationErrors)" */
117:                if (validationErrors.size() == 0) {
118:                    return null;
119:                }
120:                List<String> ret = new ArrayList<String>(validationErrors);
121:                validationErrors.clear();
122:                return ret;
123:            }
124:
125:            /** generic getter.
126:             *
127:             */
128:            public Object get(String key) {
129:                if ("error".equalsIgnoreCase(key)) {
130:                    return getError();
131:                } else if ("validationErrors".equalsIgnoreCase(key)) {
132:                    return getValidationErrors();
133:                } else if ("locale".equalsIgnoreCase(key)) {
134:                    return getLocale();
135:                }
136:                return null;
137:            }
138:
139:            /**
140:             * Locale getter.
141:             * @return current locale
142:             */
143:            public Locale getLocale() {
144:                if (localizer != null) {
145:                    return localizer.getLocale();
146:                } else if (locale != null) {
147:                    return locale;
148:                } else {
149:                    return Locale.getDefault();
150:                }
151:            }
152:
153:            /**
154:             * Set the last inserted ID for an entity.
155:             * @param entity entity
156:             * @param id last inserted id
157:             */
158:            public synchronized void setLastInsertedID(Entity entity, long id) {
159:                lastInsertedIDs.put(entity, id);
160:            }
161:
162:            /**
163:             * Get the last inserted ID for an entity.
164:             * @param entity entity
165:             * @return last inserted ID of -1
166:             */
167:            public long getLastInsertedID(Entity entity) {
168:                Long id = lastInsertedIDs.get(entity);
169:                if (id != null) {
170:                    return id.longValue();
171:                } else {
172:                    Logger.error("getLastInsertID called for entity '" + entity
173:                            + "' which doesn't have any");
174:                    return -1;
175:                }
176:            }
177:
178:            /** last error message */
179:            private String error = "";
180:            /** list of validation error messages */
181:            private List<String> validationErrors = new ArrayList<String>();
182:            /** localizer */
183:            private Localizer localizer = null;
184:            /** locale */
185:            private Locale locale = null;
186:            /** map of last inserted IDs */
187:            private Map<Entity, Long> lastInsertedIDs = new HashMap<Entity, Long>();
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.