Source Code Cross Referenced for JoFilterHolder.java in  » Web-Server » jo » com » tagtraum » jo » 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 Server » jo » com.tagtraum.jo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.tagtraum.jo;
002:
003:        import com.tagtraum.framework.log.Log;
004:
005:        import javax.servlet.*;
006:        import javax.swing.event.ChangeEvent;
007:        import javax.swing.event.ChangeListener;
008:        import java.io.IOException;
009:        import java.util.Enumeration;
010:        import java.util.Vector;
011:
012:        /**
013:         *
014:         * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
015:         * @version 1.1beta1 ($Revision: 1.2 $)
016:         */
017:        public class JoFilterHolder implements  I_JoWebAppElement {
018:
019:            private static final int DESTROY_TIMEOUT = 10000; // ms
020:            private I_JoServletContextPeer peer;
021:            private Filter filter;
022:            private String filterClassname;
023:            private JoFilterConfig filterConfig;
024:            private Log log = Log.getLog();
025:            private UnavailableException unavailableException;
026:            private long unavailableSince;
027:            private int threadCount;
028:            private String name;
029:            private String displayName;
030:            private String description;
031:            private JoIcon icon;
032:            private String logPrefix = "";
033:            private Vector changeListeners;
034:
035:            public JoFilterHolder() {
036:                this .filterConfig = new JoFilterConfig();
037:                this .changeListeners = new Vector();
038:                this .icon = new JoIcon();
039:            }
040:
041:            public void setName(String name) {
042:                this .name = name;
043:            }
044:
045:            public String getName() {
046:                return name;
047:            }
048:
049:            public String getDisplayName() {
050:                return displayName;
051:            }
052:
053:            public void setDisplayName(String displayName) {
054:                this .displayName = displayName;
055:            }
056:
057:            public String getDescription() {
058:                return description;
059:            }
060:
061:            public void setDescription(String description) {
062:                this .description = description;
063:            }
064:
065:            public void setIcon(JoIcon icon) {
066:                this .icon = icon;
067:            }
068:
069:            public JoIcon getIcon() {
070:                return icon;
071:            }
072:
073:            public String getInitParameter(String aKey) {
074:                return filterConfig.getInitParameter(aKey);
075:            }
076:
077:            public void setInitParameter(String aKey, String aValue) {
078:                filterConfig.setInitParameter(aKey, aValue);
079:            }
080:
081:            public Enumeration getInitParameterNames() {
082:                return filterConfig.getInitParameterNames();
083:            }
084:
085:            public ClassLoader getClassLoader() {
086:                // TODO: what the heck is this for...?
087:                return null;
088:            }
089:
090:            public void setServletContextPeer(I_JoServletContextPeer peer) {
091:                this .peer = peer;
092:                this .filterConfig.setServletContext(peer.getServletContext());
093:                this .log = Log.getLog(peer.getHost().getName());
094:                this .logPrefix = "[" + peer.getName() + "]: ";
095:            }
096:
097:            public void setFilterClassname(String filterClassname) {
098:                this .filterClassname = filterClassname;
099:            }
100:
101:            public String getFilterClassname() {
102:                return filterClassname;
103:            }
104:
105:            public void service(ServletRequest request,
106:                    ServletResponse response, FilterChain filterChain)
107:                    throws IOException, ServletException {
108:                synchronized (this ) {
109:                    threadCount++;
110:                }
111:                try {
112:                    checkUnavailable();
113:                    initializeFilter();
114:                    filter(request, response, filterChain);
115:                } finally {
116:                    synchronized (this ) {
117:                        threadCount--;
118:                    }
119:                }
120:            }
121:
122:            public synchronized void destroy() {
123:                // TODO: review doug lea classes for this.
124:                long destroyStart = System.currentTimeMillis();
125:                while (threadCount != 0
126:                        && System.currentTimeMillis() - destroyStart < DESTROY_TIMEOUT) {
127:                    try {
128:                        wait(500);
129:                    } catch (InterruptedException e) {
130:                        // ignore
131:                    }
132:                }
133:                if (filter != null)
134:                    filter.destroy();
135:                filter = null;
136:            }
137:
138:            private void filter(ServletRequest request,
139:                    ServletResponse response, FilterChain filterChain)
140:                    throws IOException, ServletException {
141:                try {
142:                    filter.doFilter(request, response, filterChain);
143:                } catch (UnavailableException e) {
144:                    if (!e.isPermanent())
145:                        unavailableSince = System.currentTimeMillis();
146:                    unavailableException = e;
147:                    throw e;
148:                }
149:            }
150:
151:            private synchronized void checkUnavailable()
152:                    throws UnavailableException {
153:                if (unavailableException != null) {
154:                    if (unavailableException.isPermanent())
155:                        throw unavailableException;
156:                    else if ((System.currentTimeMillis() - unavailableException
157:                            .getUnavailableSeconds() * 1000) < unavailableSince)
158:                        throw unavailableException;
159:                    else
160:                        unavailableException = null;
161:                }
162:            }
163:
164:            private synchronized void initializeFilter()
165:                    throws ServletException {
166:                if (filter == null) {
167:                    try {
168:                        filter = (Filter) Class.forName(filterClassname, true,
169:                                peer.getClassLoader()).newInstance();
170:                    } catch (Exception e) {
171:                        if (log.isLog(Log.ERROR)) {
172:                            log.log(logPrefix
173:                                    + "Failed to instantiate filter: "
174:                                    + e.toString(), Log.ERROR);
175:                            log.log(e, Log.ERROR);
176:                        }
177:                        unavailableException = new UnavailableException(
178:                                "Failed to instantiate filter: " + e.toString());
179:                        throw unavailableException;
180:                    }
181:                    try {
182:                        filter.init(filterConfig);
183:                    } catch (UnavailableException e) {
184:                        if (!e.isPermanent())
185:                            unavailableSince = System.currentTimeMillis();
186:                        unavailableException = e;
187:                        throw e;
188:                    }
189:                    fireChangeEvent();
190:                }
191:            }
192:
193:            public synchronized boolean isLoaded() {
194:                return filter != null;
195:            }
196:
197:            /**
198:             * Eventlistener for possible UI.
199:             */
200:            public void addChangeListener(ChangeListener cl) {
201:                if (!changeListeners.contains(cl))
202:                    changeListeners.add(cl);
203:            }
204:
205:            /**
206:             * Eventlistener for possible UI.
207:             */
208:            public boolean removeChangeListener(ChangeListener cl) {
209:                return changeListeners.remove(cl);
210:            }
211:
212:            /**
213:             * Eventlistener for possible UI.
214:             */
215:            private void fireChangeEvent() {
216:                ChangeEvent ce = new ChangeEvent(this );
217:                for (int i = 0; i < changeListeners.size(); i++) {
218:                    ((ChangeListener) changeListeners.get(i)).stateChanged(ce);
219:                }
220:            }
221:
222:            public String toString() {
223:                return this .name + " " + this.filterClassname;
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.