Source Code Cross Referenced for CacheManagerImpl.java in  » Portal » Open-Portal » com » sun » portal » wsrp » consumer » markup » impl » 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 » Portal » Open Portal » com.sun.portal.wsrp.consumer.markup.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2003 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.wsrp.consumer.markup.impl;
013:
014:        import java.util.Map;
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.Collections;
018:        import java.util.logging.Level;
019:        import java.util.logging.Logger;
020:
021:        import com.sun.portal.container.ContainerRequest;
022:        import com.sun.portal.wsrp.consumer.markup.MarkupConfig;
023:        import com.sun.portal.wsrp.common.stubs.MarkupParams;
024:
025:        import com.sun.portal.providers.context.ProviderContext;
026:        import com.sun.portal.providers.context.ProviderContextException;
027:        import com.sun.portal.wsrp.consumer.markup.CacheEntry;
028:        import com.sun.portal.wsrp.consumer.markup.CacheManager;
029:        import com.sun.portal.log.common.PortalLogger;
030:
031:        public class CacheManagerImpl implements  CacheManager {
032:
033:            public static final String CACHED_PORTLETS = "wsrp.cacheEntryMap";
034:
035:            private static Logger logger = PortalLogger
036:                    .getLogger(CacheManagerImpl.class);
037:
038:            /**
039:             * Returns the cached content for a container request.
040:             * 
041:             * @param request
042:             */
043:
044:            public CacheEntry getCacheEntry(MarkupConfig markupConfig,
045:                    ContainerRequest request, MarkupParams markupParams) {
046:
047:                CacheEntry cacheEntry = null;
048:                if (!MarkupUtil.isAuthless(request)) {
049:                    String entityId = request.getEntityID();
050:                    Map cachedPortlets = getCachedPortletsMap(request);
051:
052:                    cacheEntry = (CacheEntry) cachedPortlets.get(entityId);
053:
054:                    if (cacheEntry != null) {
055:                        if ((!sameMarkupParams(markupParams, cacheEntry
056:                                .getMarkupParams()))) {
057:                            if (logger.isLoggable(Level.FINEST))
058:                                logger.log(Level.FINEST, "PSWS_CSPWCMI0001",
059:                                        request.getEntityID());
060:                            cachedPortlets.remove(entityId);
061:                            cacheEntry = null;
062:                        } else {
063:                            if (logger.isLoggable(Level.FINEST))
064:                                logger.log(Level.FINEST, "PSWS_CSPWCMI0002",
065:                                        request.getEntityID());
066:                        }
067:                    } else {
068:                        if (logger.isLoggable(Level.FINEST))
069:                            logger.log(Level.FINEST, "PSWS_CSPWCMI0003",
070:                                    request.getEntityID());
071:                    }
072:
073:                }
074:
075:                return cacheEntry;
076:
077:            }
078:
079:            /**
080:             * 
081:             * 
082:             * @param request
083:             * @param cacheControl
084:             * @param entry
085:             * Anonymous user -- look again for forAll case.
086:             */
087:            public void putCacheEntry(MarkupConfig markupConfig,
088:                    ContainerRequest request, CacheEntry cacheEntry) {
089:
090:                if (!MarkupUtil.isAuthless(request)) {
091:                    if (logger.isLoggable(Level.FINEST))
092:                        logger.log(Level.FINEST, "PSWS_CSPWCMI0004", request
093:                                .getEntityID());
094:
095:                    Map cachedPortlets = getCachedPortletsMap(request);
096:                    cachedPortlets.put(request.getEntityID(), cacheEntry);
097:                }
098:
099:            }
100:
101:            /** 
102:             * Invalidte the cache 
103:             * 
104:             * @param request 
105:             */
106:            public void invalidateCacheEntry(MarkupConfig markupConfig,
107:                    ContainerRequest request) {
108:
109:                if (!MarkupUtil.isAuthless(request)) {
110:                    Map cachedPortlets = getCachedPortletsMap(request);
111:
112:                    if (cachedPortlets.containsKey(request.getEntityID())) {
113:                        if (logger.isLoggable(Level.FINEST))
114:                            logger.log(Level.FINEST, "PSWS_CSPWCMI0005",
115:                                    request.getEntityID());
116:                        cachedPortlets.remove(request.getEntityID());
117:                    }
118:                }
119:
120:            }
121:
122:            /**
123:             * convenient method to retrieve the cache Map from the
124:             * encapsulated <code>PorviderContext</code> in the <code>
125:             * ContainerRequest</code> object.
126:             * <p>
127:             * @param request The <code>ContainerRequest</code> object that
128:             *        encapsulates the <code>PorviderContext</code> object
129:             * <p>
130:             * @return a Map that contains all the cache entries for 
131:             *         the user session
132:             */
133:            private Map getCachedPortletsMap(ContainerRequest request) {
134:
135:                ProviderContext pc = MarkupUtil.getProviderContext(request);
136:                // Use DCL mechanism to improve the performance. Although 
137:                // DCL is known not to be always safe, it should not be a
138:                // problem here since the object is retrieved from a 
139:                // synchronized HashMap in desktop context and will be 
140:                // instantiated, if not already exists, before being set 
141:                // in the map.
142:
143:                Map cachedPortlets = (Map) pc
144:                        .getSessionProperty(CACHED_PORTLETS);
145:                if (cachedPortlets == null) {
146:                    synchronized (pc) {
147:                        if ((cachedPortlets = (Map) pc
148:                                .getSessionProperty(CACHED_PORTLETS)) == null) {
149:                            cachedPortlets = Collections
150:                                    .synchronizedMap(new HashMap());
151:                            pc.setSessionProperty(CACHED_PORTLETS,
152:                                    cachedPortlets);
153:                            if (logger.isLoggable(Level.FINEST))
154:                                logger.log(Level.FINEST, "PSWS_CSPWCMI0006");
155:                        }
156:                    }
157:                }
158:                return cachedPortlets;
159:            }
160:
161:            private boolean sameMarkupParams(MarkupParams first,
162:                    MarkupParams second) {
163:
164:                boolean same = false;
165:                if (!strSame(first.getWindowState(), second.getWindowState())) {
166:                    return false;
167:                }
168:                if (!strSame(first.getMode(), second.getMode())) {
169:                    return false;
170:                }
171:                if (!strSame(first.getNavigationalState(), second
172:                        .getNavigationalState())) {
173:                    return false;
174:                }
175:                if (first.isSecureClientCommunication() != second
176:                        .isSecureClientCommunication()) {
177:
178:                    return false;
179:                }
180:                if (!listSame(first.getValidNewWindowStates(), second
181:                        .getValidNewWindowStates())) {
182:                    return false;
183:                }
184:                if (!listSame(first.getMimeTypes(), second.getMimeTypes())) {
185:                    return false;
186:                }
187:                if (!listSame(first.getValidNewModes(), second
188:                        .getValidNewModes())) {
189:                    return false;
190:                }
191:                if (!listSame(first.getLocales(), second.getLocales())) {
192:                    return false;
193:                }
194:                if (!listSame(first.getMimeTypes(), second.getMimeTypes())) {
195:                    return false;
196:                }
197:                if (!listSame(first.getMarkupCharacterSets(), second
198:                        .getMarkupCharacterSets())) {
199:                    return false;
200:                }
201:                if (!strSame(first.getClientData().getUserAgent(), second
202:                        .getClientData().getUserAgent())) {
203:                    return false;
204:                }
205:
206:                return true;
207:            }
208:
209:            private static boolean strSame(String a, String b) {
210:                if (a == null && b == null) {
211:                    return true;
212:                }
213:                if (a != null && a.equals(b)) {
214:                    return true;
215:                }
216:                return false;
217:            }
218:
219:            private static boolean listSame(String[] a, String[] b) {
220:
221:                if (a == null && b == null) {
222:                    return true;
223:                }
224:
225:                if (a != null && b != null) {
226:                    if (a.length == b.length) {
227:                        for (int i = 0; i < a.length; i++) {
228:                            if (!strSame(a[i], b[i])) {
229:                                // element not same
230:                                return false;
231:                            }
232:                        }
233:                        // all elements same
234:                        return true;
235:                    } else {
236:                        // length is not same
237:                        return false;
238:                    }
239:                } else {
240:                    // only one of them is null
241:                    return false;
242:                }
243:            }
244:
245:        }
w___w___w___.__ja___v___a___2s___.__c_o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.