Source Code Cross Referenced for RequestPreProcessingManager.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » 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 » J2EE » Enhydra Application Framework » com.lutris.appserver.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Takes care of request pre-processing.
003:         */package com.lutris.appserver.server;
004:
005:        import java.lang.reflect.Constructor;
006:        import java.lang.reflect.InvocationTargetException;
007:        import java.util.Vector;
008:
009:        import org.enhydra.util.RequestPreProcessor;
010:        import org.enhydra.util.ResponsePostProcessor;
011:
012:        import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
013:        import com.lutris.logging.LogChannel;
014:        import com.lutris.logging.Logger;
015:        import com.lutris.util.Config;
016:        import com.lutris.util.ConfigException;
017:        import com.lutris.util.KeywordValueException;
018:
019:        /**
020:         * @author Slobodan Vujasinovic
021:         * 
022:         */
023:        public class RequestPreProcessingManager {
024:
025:            /**
026:             * RequestPreProcessingManager configuration prefix
027:             */
028:            public static final String CONFIG_PREFIX = "RequestPreProcessor";
029:
030:            /**
031:             * LogChannel used by RequestPreProcessingManager
032:             */
033:            private LogChannel logChannel;
034:
035:            /**
036:             * Vector containing registered preprocessor implementations for
037:             * corresponding application.
038:             */
039:            private Vector preProcessors;
040:
041:            /**
042:             * Request pre-processing profiling level
043:             * 
044:             * Negative - profile everything 
045:             * Zero - profile nothing 
046:             * Positive - profile only processing that lasted longer 
047:             * 			  than specified number of milliseconds
048:             */
049:            private int profileLevel = 0;
050:
051:            /**
052:             * To do profiling or not
053:             */
054:            private boolean doProfile = false;
055:
056:            /**
057:             * Initialize preprocessing manager according to application configuration!
058:             * 
059:             * @param config
060:             */
061:            public RequestPreProcessingManager(Config config,
062:                    LogChannel logChannel) {
063:                this .logChannel = logChannel;
064:                preProcessors = new Vector();
065:                try {
066:                    // Profiling Initialization
067:                    profileLevel = config.getInt("TimeProfiler", 0);
068:                    if (profileLevel != 0) {
069:                        doProfile = true;
070:                    }
071:
072:                    String[] ppNames = config.getStrings("Names", null);
073:                    if (ppNames != null) {
074:                        for (int i = 0; i < ppNames.length; i++) {
075:                            Config ppConfig = null;
076:                            try {
077:                                ppConfig = config.getConfig(ppNames[i]);
078:                                if (config.getConfigFile() != null
079:                                        && ppConfig != null)
080:                                    ppConfig.setConfigFile(config
081:                                            .getConfigFile());
082:                            } catch (KeywordValueException kwe) {
083:                                kwe.printStackTrace();
084:                            }
085:                            if (ppConfig != null) {
086:                                String ppClassName = ppConfig.getString(
087:                                        "Class", null);
088:                                if (ppClassName != null) {
089:                                    Class ppClass = null;
090:                                    try {
091:                                        ppClass = Class.forName(ppClassName);
092:                                    } catch (ClassNotFoundException cnf) {
093:                                        cnf.printStackTrace();
094:                                    }
095:                                    if (ppClass != null) {
096:                                        Class[] ArgClassArray = new Class[] {};
097:                                        Object[] ArgObject = new Object[] {};
098:
099:                                        Constructor ppConstructor = null;
100:                                        try {
101:                                            ppConstructor = ppClass
102:                                                    .getDeclaredConstructor(ArgClassArray);
103:                                        } catch (NoSuchMethodException nsm) {
104:                                            nsm.printStackTrace();
105:                                        }
106:                                        if (ppConstructor != null) {
107:                                            RequestPreProcessor rPP = null;
108:                                            try {
109:                                                rPP = (RequestPreProcessor) (ppConstructor
110:                                                        .newInstance(ArgObject));
111:                                                rPP.setName(ppNames[i]);
112:                                                rPP.setLogChannel(logChannel);
113:                                            } catch (InstantiationException ie) {
114:                                                ie.printStackTrace();
115:                                            } catch (InvocationTargetException ite) {
116:                                                ite.printStackTrace();
117:                                            } catch (IllegalAccessException iae) {
118:                                                iae.printStackTrace();
119:                                            }
120:                                            if (rPP != null) {
121:                                                rPP.configure(ppConfig);
122:                                                preProcessors.add(rPP);
123:                                            }
124:                                        }
125:                                    }
126:                                }
127:                            }
128:                        }
129:                    }
130:                } catch (ConfigException ce) {
131:                    if (logChannel != null) {
132:                        logChannel
133:                                .write(Logger.ERROR,
134:                                        "Problem with RequestPreProcessing initialization!");
135:                    }
136:                    ce.printStackTrace();
137:                }
138:            }
139:
140:            /**
141:             * Manages request preprocessing.
142:             * 
143:             * @param comms
144:             * @return
145:             */
146:            public boolean manage(HttpPresentationComms comms) {
147:                boolean returnValue = false;
148:                if (logChannel != null) {
149:                    logChannel.write(Logger.DEBUG,
150:                            "Managing request preprocessing!");
151:                }
152:                for (int i = 0; i < preProcessors.size(); i++) {
153:                    boolean tempReturnValue = false;
154:                    RequestPreProcessor rPP = (RequestPreProcessor) ((RequestPreProcessor) preProcessors
155:                            .get(i)).clone();
156:                    // RequestPreProcessor rPP = (RequestPreProcessor) preProcessors
157:                    // .get(i);
158:
159:                    // Start Profiling Time
160:                    long processingTime = startProfiler();
161:
162:                    tempReturnValue = rPP.process(comms);
163:
164:                    // End Profiling Time
165:                    stopProfiler(processingTime, rPP.getName());
166:
167:                    returnValue = tempReturnValue || returnValue;
168:                }
169:                return returnValue;
170:            }
171:
172:            private long startProfiler() {
173:                return doProfile ? System.currentTimeMillis() : -1;
174:            }
175:
176:            private void stopProfiler(long processingTime, String name) {
177:                if (doProfile) {
178:                    processingTime = System.currentTimeMillis()
179:                            - processingTime;
180:                    if (processingTime > profileLevel) {
181:                        if (logChannel != null) {
182:                            logChannel
183:                                    .write(
184:                                            Logger.WARNING,
185:                                            "RequestPreProcessor "
186:                                                    + name
187:                                                    + " took "
188:                                                    + processingTime
189:                                                    + " milliseconds for request processing!");
190:                        }
191:                    }
192:                }
193:            }
194:
195:            public boolean addPreProcessor(int position, RequestPreProcessor rPP) {
196:                if (position >= 0) {
197:                    preProcessors.add(position, rPP);
198:                    if (logChannel != null) {
199:                        logChannel.write(Logger.INFO,
200:                                "New RequestPreProcessor introduced!");
201:                    }
202:                } else {
203:                    return preProcessors.add(rPP);
204:                }
205:                return true;
206:            }
207:
208:            public boolean removePreProcessor(int position) {
209:                if (position >= 0) {
210:                    preProcessors.removeElementAt(position);
211:                    if (logChannel != null) {
212:                        logChannel.write(Logger.INFO,
213:                                "RequestPreProcessor removed!");
214:                    }
215:                } else {
216:                    return false;
217:                }
218:                return true;
219:            }
220:
221:            public boolean removePreProcessor(RequestPreProcessor rPP) {
222:                return preProcessors.removeElement(rPP);
223:            }
224:
225:            public boolean removePreProcessor(String ppName) {
226:                if (ppName != null) {
227:                    for (int i = 0; i < preProcessors.size(); i++) {
228:                        if (ppName
229:                                .equals(((ResponsePostProcessor) preProcessors
230:                                        .elementAt(i)).getName())) {
231:                            preProcessors.removeElementAt(i);
232:                            return true;
233:                        }
234:                    }
235:                }
236:                return false;
237:
238:            }
239:
240:            public Vector getPreProcessors() {
241:                return preProcessors;
242:            }
243:
244:            public void setPreProcessors(Vector preProcessors) {
245:                try {
246:                    for (int i = 0; i < preProcessors.size(); i++) {
247:                        RequestPreProcessor pp = (RequestPreProcessor) preProcessors
248:                                .elementAt(i);
249:                    }
250:                    this .preProcessors = preProcessors;
251:                } catch (Exception ex) {
252:                    // in case of exception - do nothing
253:                    if (logChannel != null) {
254:                        logChannel
255:                                .write(Logger.ERROR,
256:                                        "Problem occurred during pre-processor vector acceptance!");
257:                    }
258:                    ex.printStackTrace();
259:                }
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.