Source Code Cross Referenced for Configuration.java in  » Sevlet-Container » jetty-modules » org » mortbay » jetty » plus » webapp » 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 » Sevlet Container » jetty modules » org.mortbay.jetty.plus.webapp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // $Id: Configuration.java 1448 2006-12-29 20:46:57Z janb $
003:        // Copyright 2006 Mort Bay Consulting Pty. Ltd.
004:        // ------------------------------------------------------------------------
005:        // Licensed under the Apache License, Version 2.0 (the "License");
006:        // you may not use this file except in compliance with the License.
007:        // You may obtain a copy of the License at 
008:        // http://www.apache.org/licenses/LICENSE-2.0
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:        // ========================================================================
015:
016:        package org.mortbay.jetty.plus.webapp;
017:
018:        import java.util.Random;
019:
020:        import javax.naming.Context;
021:        import javax.naming.InitialContext;
022:
023:        import org.mortbay.jetty.plus.naming.EnvEntry;
024:        import org.mortbay.jetty.plus.naming.NamingEntry;
025:        import org.mortbay.jetty.plus.naming.Resource;
026:        import org.mortbay.jetty.plus.naming.Transaction;
027:        import org.mortbay.log.Log;
028:        import org.mortbay.naming.NamingUtil;
029:
030:        /**
031:         * Configuration
032:         *
033:         *
034:         */
035:        public class Configuration extends AbstractConfiguration {
036:
037:            private Integer _key;
038:
039:            /** 
040:             * @see org.mortbay.jetty.plus.webapp.AbstractConfiguration#bindEnvEntry(java.lang.String, java.lang.String)
041:             * @param name
042:             * @param value
043:             * @throws Exception
044:             */
045:            public void bindEnvEntry(String name, Object value)
046:                    throws Exception {
047:                EnvEntry envEntry = EnvEntry.getEnvEntry(
048:                        NamingEntry.SCOPE_LOCAL, name);
049:                if ((envEntry != null) && envEntry.isOverrideWebXml())
050:                    return; //already bound a locally scoped value which should override web.xml
051:
052:                envEntry = EnvEntry.getEnvEntry(NamingEntry.SCOPE_GLOBAL, name);
053:                if ((envEntry == null) || !envEntry.isOverrideWebXml()) {
054:
055:                    //if either there isn't an env-entry in jetty-env.xml or a global one,
056:                    //or there is one and it isn't set to override the web.xml one, then
057:                    //bind the web.xml one
058:                    InitialContext ic = new InitialContext();
059:                    Context envCtx = (Context) ic.lookup("java:comp/env");
060:                    NamingUtil.bind(envCtx, name, value);
061:                    Log.debug("Bound java:comp/env/" + name + "=" + value);
062:                }
063:            }
064:
065:            /** 
066:             * @see org.mortbay.jetty.plus.webapp.AbstractConfiguration#bindResourceRef(java.lang.String)
067:             * @param name
068:             * @throws Exception
069:             */
070:            public void bindResourceRef(String name, Class typeClass)
071:                    throws Exception {
072:
073:                Resource resource = Resource.getResource(
074:                        NamingEntry.SCOPE_LOCAL, name);
075:
076:                if (resource != null)
077:                    return; //already bound the locally scoped resource of that name
078:
079:                resource = Resource.getResource(NamingEntry.SCOPE_GLOBAL, name);
080:                if (resource != null) {
081:                    //no locally scoped overrides, so bind the global one, if the
082:                    //TODO: check type is appropriate
083:                    resource.bindToEnv();
084:                    Log.debug("Bound resourceref java:comp/env/" + name);
085:                } else {
086:                    Log.warn("No resource to bind matching name=" + name);
087:                }
088:            }
089:
090:            /** 
091:             * @see org.mortbay.jetty.plus.webapp.AbstractConfiguration#bindResourceEnvRef(java.lang.String)
092:             * @param name
093:             * @throws Exception
094:             */
095:            public void bindResourceEnvRef(String name, Class typeClass)
096:                    throws Exception {
097:
098:                Resource resource = Resource.getResource(
099:                        NamingEntry.SCOPE_LOCAL, name);
100:                if (resource != null)
101:                    return; //already bound
102:                resource = Resource.getResource(NamingEntry.SCOPE_GLOBAL, name);
103:                if (resource != null) {
104:                    resource.bindToEnv();
105:                    Log.debug("Bound resource-env-ref java:comp/env/" + name);
106:                } else
107:                    Log.warn("No resource to bind matching name=" + name);
108:            }
109:
110:            public void bindMessageDestinationRef(String name, Class typeClass)
111:                    throws Exception {
112:                Resource resource = Resource.getResource(
113:                        NamingEntry.SCOPE_LOCAL, name);
114:                if (resource != null)
115:                    return; //already bound
116:                resource = Resource.getResource(NamingEntry.SCOPE_GLOBAL, name);
117:                if (resource != null) {
118:                    resource.bindToEnv();
119:                    Log.debug("Bound message-destination-ref java:comp/env/"
120:                            + name);
121:                } else
122:                    Log.warn("No resource to bind matching name=" + name);
123:            }
124:
125:            public void bindUserTransaction() throws Exception {
126:                Transaction transaction = Transaction
127:                        .getTransaction(NamingEntry.SCOPE_LOCAL);
128:                if (transaction != null) {
129:                    //special case, still need to bind it because it has to be bound to java:comp instead
130:                    //of java:comp/env
131:                    transaction.bindToEnv();
132:                    return;
133:                }
134:
135:                transaction = Transaction
136:                        .getTransaction(NamingEntry.SCOPE_GLOBAL);
137:                if (transaction != null) {
138:                    transaction.bindToEnv();
139:                    Log.debug("Bound UserTransaction to java:comp/"
140:                            + transaction.getJndiName());
141:                }
142:            }
143:
144:            public void configureClassLoader() throws Exception {
145:                super .configureClassLoader();
146:            }
147:
148:            public void configureDefaults() throws Exception {
149:                super .configureDefaults();
150:            }
151:
152:            public void configureWebApp() throws Exception {
153:                super .configureWebApp();
154:                //lock this webapp's java:comp namespace as per J2EE spec
155:                ClassLoader oldLoader = Thread.currentThread()
156:                        .getContextClassLoader();
157:                Thread.currentThread().setContextClassLoader(
158:                        getWebAppContext().getClassLoader());
159:                lockCompEnv();
160:                Thread.currentThread().setContextClassLoader(oldLoader);
161:            }
162:
163:            public void deconfigureWebApp() throws Exception {
164:                ClassLoader oldLoader = Thread.currentThread()
165:                        .getContextClassLoader();
166:                Thread.currentThread().setContextClassLoader(
167:                        getWebAppContext().getClassLoader());
168:                unlockCompEnv();
169:                Thread.currentThread().setContextClassLoader(oldLoader);
170:                super .deconfigureWebApp();
171:            }
172:
173:            protected void lockCompEnv() throws Exception {
174:                Random random = new Random();
175:                _key = new Integer(random.nextInt());
176:                Context context = new InitialContext();
177:                Context compCtx = (Context) context.lookup("java:comp");
178:                compCtx.addToEnvironment("org.mortbay.jndi.lock", _key);
179:            }
180:
181:            protected void unlockCompEnv() throws Exception {
182:                Context context = new InitialContext();
183:                Context compCtx = (Context) context.lookup("java:comp");
184:                compCtx.addToEnvironment("org.mortbay.jndi.unlock", _key);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.