Source Code Cross Referenced for ApplicationContext.java in  » J2EE » Sofia » com » salmonllc » util » 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 » Sofia » com.salmonllc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        //Copyright (C) 1999 - 2004, Salmon LLC
004:        //
005:        //This program is free software; you can redistribute it and/or
006:        //modify it under the terms of the GNU General Public License version 2
007:        //as published by the Free Software Foundation;
008:        //
009:        //This program is distributed in the hope that it will be useful,
010:        //but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        //GNU General Public License for more details.
013:        //
014:        //You should have received a copy of the GNU General Public License
015:        //along with this program; if not, write to the Free Software
016:        //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        //
018:        //For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:        package com.salmonllc.util;
021:
022:        import java.io.File;
023:
024:        /**
025:         * Creates an application context object that can be used by other framwork
026:         * classes to determine information on the web application
027:         */
028:        public class ApplicationContext {
029:            private static ThreadLocal _context = new ContextThreadLocal();
030:            private String _appID;
031:            private String _appDocumentRoot;
032:            private String _appPropsPath;
033:            private MessageLog _logger;
034:
035:            private static class ContextThread extends Thread {
036:                ApplicationContext _parentThreadContext;
037:
038:                private ContextThread(ApplicationContext parentContext,
039:                        Runnable o) {
040:                    super (o);
041:                    _parentThreadContext = parentContext;
042:                }
043:
044:                private ApplicationContext getContext() {
045:                    return _parentThreadContext;
046:                }
047:            }
048:
049:            private static class ContextThreadLocal extends ThreadLocal {
050:                protected Object initialValue() {
051:                    Thread t = Thread.currentThread();
052:                    if (t instanceof  ContextThread)
053:                        return ((ContextThread) t).getContext();
054:                    else
055:                        return super .initialValue();
056:                }
057:            }
058:
059:            /**
060:             * Creates a new thread that shares the same application context as the current thread
061:             */
062:            public static Thread createThreadWithContext(Runnable r) {
063:                return new ContextThread(getContext(), r);
064:            }
065:
066:            /**
067:             * Creates a new thread with a clone of the application context as the current thread
068:             */
069:            public static Thread createThreadWithContextClone(Runnable r) {
070:                ApplicationContext from = getContext();
071:                if (from != null) {
072:                    ApplicationContext to = new ApplicationContext();
073:                    to.setAppDocumentRoot(from.getAppDocumentRoot());
074:                    to.setAppID(from.getAppID());
075:                    to.setLogger(from.getLogger());
076:                    return new ContextThread(to, r);
077:                } else
078:                    return new ContextThread(null, r);
079:
080:            }
081:
082:            public static void setContext(ApplicationContext cont) {
083:                _context.set(cont);
084:            }
085:
086:            public static ApplicationContext getContext() {
087:                return (ApplicationContext) _context.get();
088:            }
089:
090:            /**
091:             * @return Returns the appID.
092:             */
093:            public String getAppID() {
094:                if (_appID == null)
095:                    return "";
096:                else
097:                    return _appID;
098:            }
099:
100:            /**
101:             * @param appID
102:             * The appID to set.
103:             */
104:            public void setAppID(String appID) {
105:                _appID = appID;
106:            }
107:
108:            /**
109:             * @return Returns the contextRoot.
110:             */
111:            public String getAppDocumentRoot() {
112:                return _appDocumentRoot;
113:            }
114:
115:            /**
116:             * @return Returns the logger.
117:             */
118:            public MessageLog getLogger() {
119:                return _logger;
120:            }
121:
122:            /**
123:             * @param Framework method, don't call directly
124:             */
125:            public void setLogger(MessageLog logger) {
126:                _logger = logger;
127:            }
128:
129:            /**
130:             * @param Framework method, don't call directly
131:             */
132:            public void setAppDocumentRoot(String contextRoot) {
133:                _appDocumentRoot = contextRoot;
134:                _appPropsPath = contextRoot;
135:                if (!_appPropsPath.endsWith(File.separator))
136:                    _appPropsPath += File.separator;
137:                _appPropsPath += "WEB-INF" + File.separator + "properties";
138:            }
139:
140:            /**
141:             * Returns the directory where framework properties are stored
142:             * @return
143:             */
144:            public String getAppPropertiesPath() {
145:                return _appPropsPath;
146:            }
147:
148:            public String toString() {
149:                return "AppID:" + _appID + " DocumentRoot:" + _appDocumentRoot;
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.