Source Code Cross Referenced for CayenneSupportBeforeAction.java in  » Web-Framework » jpublish » org » jpublish » module » cayenne » 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 » Web Framework » jpublish » org.jpublish.module.cayenne 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007 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:
018:        package org.jpublish.module.cayenne;
019:
020:        import com.anthonyeden.lib.config.Configuration;
021:        import org.apache.cayenne.access.DataContext;
022:        import org.apache.cayenne.conf.ServletUtil;
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:        import org.jpublish.JPublishContext;
026:
027:        import javax.servlet.http.HttpSession;
028:
029:        /**
030:         * Action executed before rendering a page, so the Cayenne support can be added
031:         *
032:         * @author <a href="mailto:florin.patrascu@gmail.com">Florin T.PATRASCU</a>
033:         * @since $Revision$ (created: Sep 23, 2007 2:43:42 PM)
034:         */
035:        public class CayenneSupportBeforeAction extends CayenneSupportAction {
036:            private static final Log log = LogFactory
037:                    .getLog(CayenneSupportBeforeAction.class);
038:            private static JPCayenneService jpCayenneService = new JPCayenneService();
039:
040:            public CayenneSupportBeforeAction(JPCayenneModule jpCayenneModule) {
041:                super (jpCayenneModule);
042:            }
043:
044:            /**
045:             * Execute the action using the given context.
046:             *
047:             * @param context       The current context
048:             * @param configuration The configuration
049:             * @throws Exception Any error
050:             */
051:            public void execute(JPublishContext context,
052:                    Configuration configuration) throws Exception {
053:                // Bind DataContext to the request thread
054:                DataContext dc = getDataContext(context.getSession());
055:                DataContext.bindThreadDataContext(dc);
056:
057:                context.put(JPCayenneModule.JPCAYENNE_SERVICE_NAME,
058:                        jpCayenneService);
059:                context.getRequest().setAttribute(
060:                        JPCayenneModule.JPCAYENNE_SERVICE_NAME,
061:                        jpCayenneService);
062:                context.getRequest().setAttribute(
063:                        JPCayenneModule.JPCAYENNE_DATA_CONTEXT, dc);
064:                context.put(JPCayenneModule.JPCAYENNE__UTILS, jpCayenneModule
065:                        .getJPCayenneUtils());
066:                context.getRequest().setAttribute(
067:                        JPCayenneModule.JPCAYENNE__UTILS,
068:                        jpCayenneModule.getJPCayenneUtils());
069:
070:                if (jpCayenneModule.isDebugEnabled()) {
071:                    context.put(JPCayenneModule.JPCAYENNE_DATA_CONTEXT, dc);
072:                }
073:            }
074:
075:            /**
076:             * Return a DataContext instance. If the DataContextFilter is configured
077:             * to associate the DataContext with the session (which is the default
078:             * behaviour), the DataContext will be bound to the users session. If
079:             * the DataContext is already available, the existing DataContext will be
080:             * used otherwise a new DataContex object will be created.
081:             * <p/>
082:             * If this filter is configured with <tt>create-each-request</tt> to be true
083:             * then a new DataContext will be created for each request and the DataContext
084:             * will not be bound to the session.
085:             * <p/>
086:             * If this filter is configured with <tt>use-shared-cache</tt> to be true
087:             * (which is the default behaviour) this method will create DataContext objects
088:             * using the Cayenne shared cache, otherwise they will not use the shared cache.
089:             *
090:             * @param session the users session
091:             * @return the session DataContext object
092:             */
093:            protected synchronized DataContext getDataContext(
094:                    HttpSession session) {
095:
096:                DataContext dataContext = null;
097:
098:                if (jpCayenneModule.isSessionScope()) {
099:                    dataContext = (DataContext) session
100:                            .getAttribute(ServletUtil.DATA_CONTEXT_KEY);
101:                }
102:
103:                if (dataContext == null) {
104:                    dataContext = DataContext.createDataContext(jpCayenneModule
105:                            .isSharedCache());
106:
107:                    if (jpCayenneModule.isDebugEnabled()) {
108:                        String msg = "[DEBUG] created DataContex with shared-cache="
109:                                + jpCayenneModule.isSharedCache();
110:                        log.info(msg);
111:                    }
112:
113:                    if (jpCayenneModule.isSessionScope()) {
114:                        session.setAttribute(ServletUtil.DATA_CONTEXT_KEY,
115:                                dataContext);
116:                    }
117:                }
118:
119:                return dataContext;
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.