Source Code Cross Referenced for DlogActionBase.java in  » Portal » DLOG4J » dlog4j » action » 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 » DLOG4J » dlog4j.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This program is free software; you can redistribute it and/or modify
003:         *  it under the terms of the GNU General Public License as published by
004:         *  the Free Software Foundation; either version 2 of the License, or
005:         *  (at your option) any later version.
006:         *
007:         *  This program is distributed in the hope that it will be useful,
008:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *  GNU Library General Public License for more details.
011:         *
012:         *  You should have received a copy of the GNU General Public License
013:         *  along with this program; if not, write to the Free Software
014:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015:         */
016:        package dlog4j.action;
017:
018:        import java.sql.Connection;
019:        import java.sql.ResultSet;
020:        import java.sql.SQLException;
021:        import java.sql.Statement;
022:
023:        import javax.servlet.ServletContext;
024:        import javax.servlet.http.HttpServletRequest;
025:        import javax.servlet.http.HttpServletResponse;
026:
027:        import org.apache.struts.action.ActionErrors;
028:        import org.apache.struts.action.ActionForm;
029:        import org.apache.struts.action.ActionForward;
030:        import org.apache.struts.action.ActionMapping;
031:
032:        import dlog4j.Globals;
033:        import dlog4j.formbean.UserForm;
034:
035:        import web.struts.ActionExtend;
036:        import net.sf.hibernate.HibernateException;
037:        import net.sf.hibernate.Session;
038:        import net.sf.hibernate.SessionFactory;
039:
040:        /**
041:         * DLOG项目的基础Action类
042:         * @author Liudong
043:         */
044:        public abstract class DlogActionBase extends ActionExtend {
045:
046:            /**
047:             * 该方法覆盖了父类的功能,主要是为了resin 3.0.x的兼容性做了改进
048:             * 对于其他应用服务器并没有影响,同时统一了formbean的自动validate功能
049:             * 要求所有的action都必须关闭自动validate功能,而在此处进行统一处理
050:             * Action类执行入口
051:             */
052:            public ActionForward execute(ActionMapping mapping,
053:                    ActionForm form, HttpServletRequest req,
054:                    HttpServletResponse res) throws Exception {
055:                ActionForward forward = null;
056:                //统一validate
057:                if (form != null) {
058:                    ActionErrors errors = form.validate(mapping, req);
059:                    if (errors != null && !errors.isEmpty()) {
060:                        saveErrors(req, errors);
061:                        forward = mapping.getInputForward();
062:                    }
063:                }
064:                if (forward == null)
065:                    forward = super .execute(mapping, form, req, res);
066:                //处理resin 3.0.x 的兼容性问题 -> jspe小服务程序
067:                if (!forward.getRedirect()) {
068:                    //传递要forward的路径给jspe小服务程序
069:                    req
070:                            .setAttribute(Globals.ACTION_PATH_KEY, forward
071:                                    .getPath());
072:                }
073:                return forward;
074:            }
075:
076:            /**
077:             * 获取当前操作用户的信息
078:             * @param req
079:             * @return
080:             */
081:            public static UserForm getLoginUser(HttpServletRequest req) {
082:                return UserForm.getLoginUser(req);
083:            }
084:
085:            /**
086:             * 获取Hibernate持久层的操作实例
087:             * @return
088:             */
089:            protected Session getSession() throws SQLException {
090:                ServletContext context = servlet.getServletContext();
091:                SessionFactory sessions = (SessionFactory) context
092:                        .getAttribute(dlog4j.Globals.HIBERNATE_SESSIONS_KEY);
093:                return sessions.openSession(getConnection());
094:            }
095:
096:            /**
097:             * 提交Hibernate操作
098:             * @param session
099:             * @throws SQLException
100:             * @throws HibernateException
101:             */
102:            protected void commitSession(Session session, boolean close)
103:                    throws SQLException, HibernateException {
104:                session.flush();
105:                session.connection().commit();
106:                if (close) {
107:                    session.connection().close();
108:                    session.close();
109:                }
110:            }
111:
112:            /**
113:             * 关闭session
114:             * @param session
115:             * @throws SQLException
116:             * @throws HibernateException
117:             */
118:            protected void closeSession(Session session) throws SQLException,
119:                    HibernateException {
120:                session.connection().close();
121:                session.close();
122:            }
123:
124:            /**
125:             * 一般用于释放数据库资源,例如 close(ps,conn);
126:             * @param obj1
127:             * @param obj2
128:             */
129:            public static void close(Object obj1, Object obj2) {
130:                close(obj1);
131:                close(obj2);
132:            }
133:
134:            /**
135:             * 一般用于释放数据库资源,例如 close(rs,ps,conn);
136:             * @param obj1
137:             * @param obj2
138:             * @param obj3
139:             */
140:            public static void close(Object obj1, Object obj2, Object obj3) {
141:                close(obj1);
142:                close(obj2);
143:                close(obj3);
144:            }
145:
146:            /**
147:             * 资源释放
148:             * @param obj
149:             */
150:            public static void close(Object obj) {
151:                if (obj == null)
152:                    return;
153:                try {
154:                    if (obj instanceof  Connection)
155:                        ((Connection) obj).close();
156:                    else if (obj instanceof  Statement)
157:                        ((Statement) obj).close();
158:                    else if (obj instanceof  ResultSet)
159:                        ((ResultSet) obj).close();
160:                    else if (obj instanceof  Session) {
161:                        Session snn = (Session) obj;
162:                        snn.connection().close();
163:                        snn.close();
164:                    }
165:                } catch (Exception e) {
166:                }
167:                obj = null;
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.