Source Code Cross Referenced for TurbineNamingService.java in  » Project-Management » turbine » org » apache » turbine » services » naming » 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 » Project Management » turbine » org.apache.turbine.services.naming 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.naming;
002:
003:        /*
004:         * Copyright 2001-2005 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License")
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.Map;
022:        import java.util.Properties;
023:
024:        import javax.naming.Context;
025:        import javax.naming.InitialContext;
026:
027:        import org.apache.commons.configuration.Configuration;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        import org.apache.turbine.Turbine;
033:        import org.apache.turbine.services.InitializationException;
034:        import org.apache.turbine.services.TurbineBaseService;
035:        import org.apache.turbine.util.RunData;
036:
037:        /**
038:         * This class is the default implementation of NamingService, which
039:         * provides JNDI naming contexts.
040:         *
041:         * @author <a href="mailto:greg@shwoop.com">Greg Ritter</a>
042:         * @author <a href="mailto:colin.chalmers@maxware.nl">Colin Chalmers</a>
043:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
044:         * @version $Id: TurbineNamingService.java 264148 2005-08-29 14:21:04Z henning $
045:         */
046:        public class TurbineNamingService extends TurbineBaseService implements 
047:                NamingService {
048:            /** Logging */
049:            private static Log log = LogFactory
050:                    .getLog(TurbineNamingService.class);
051:
052:            /**
053:             * A global Map of Property objects which are initialised using
054:             * parameters from the ResourcesFile
055:             */
056:            private Map contextPropsList = null;
057:
058:            /** All initial contexts known to this service */
059:            private Map initialContexts = new HashMap();
060:
061:            /**
062:             * Called the first time the Service is used.<br>
063:             *
064:             */
065:            public void init() throws InitializationException {
066:                // Context properties are specified in lines in the properties
067:                // file that begin with "context.contextname.", allowing
068:                // multiple named contexts to be used.  Everything after the
069:                // "contextname."  is the name of the property that will be
070:                // used by the InitialContext class to create a new context
071:                // instance.
072:
073:                Configuration conf = Turbine.getConfiguration();
074:                try {
075:                    contextPropsList = new HashMap();
076:
077:                    for (Iterator contextKeys = conf.subset("context")
078:                            .getKeys(); contextKeys.hasNext();) {
079:                        String key = (String) contextKeys.next();
080:                        int end = key.indexOf(".");
081:
082:                        if (end == -1) {
083:                            continue;
084:                        }
085:
086:                        String contextName = key.substring(0, end);
087:                        Properties contextProps = null;
088:
089:                        if (contextPropsList.containsKey(contextName)) {
090:                            contextProps = (Properties) contextPropsList
091:                                    .get(contextName);
092:                        } else {
093:                            contextProps = new Properties();
094:                        }
095:
096:                        contextProps.put(key.substring(end + 1), conf
097:                                .getString(key));
098:
099:                        contextPropsList.put(contextName, contextProps);
100:                    }
101:
102:                    for (Iterator contextPropsKeys = contextPropsList.keySet()
103:                            .iterator(); contextPropsKeys.hasNext();) {
104:                        String key = (String) contextPropsKeys.next();
105:                        Properties contextProps = (Properties) contextPropsList
106:                                .get(key);
107:                        InitialContext context = new InitialContext(
108:                                contextProps);
109:                        initialContexts.put(key, context);
110:                    }
111:
112:                    setInit(true);
113:                } catch (Exception e) {
114:                    log.error("Failed to initialize JDNI contexts!", e);
115:
116:                    throw new InitializationException(
117:                            "Failed to initialize JDNI contexts!");
118:                }
119:            }
120:
121:            /**
122:             * Places the contexts defined in the TurbineResources instance
123:             * (if any) into the data.contexts Map.
124:             *
125:             * @param data The RunData object for the current request.
126:             * @exception InitializationException, if there was a problem
127:             * during initialization.
128:             * @deprecated This should never have been here. No replacement.
129:             */
130:            public void init(RunData data) throws InitializationException {
131:                try {
132:                    if (contextPropsList == null) {
133:                        init();
134:                    }
135:
136:                    for (Iterator it = contextPropsList.keySet().iterator(); it
137:                            .hasNext();) {
138:                        String key = (String) it.next();
139:                        Properties contextProps = (Properties) contextPropsList
140:                                .get(key);
141:                        InitialContext context = new InitialContext(
142:                                contextProps);
143:                        data.getJNDIContexts().put(key, context);
144:                    }
145:                } catch (Exception e) {
146:                    log.error("Failed to initialize JDNI contexts!", e);
147:
148:                    throw new InitializationException(
149:                            "Failed to initialize JDNI contexts!");
150:                }
151:            }
152:
153:            /**
154:             * Return the Context with the specified name.  The Context is
155:             * constructed using the properties for the context with the
156:             * specified name; ie. those properties that start with
157:             * "services.servicename.properties.name.".
158:             *
159:             * @param contextName The name of the context.
160:             * @return The context with the specified name, or null if no
161:             * context exists with that name.
162:             */
163:            public Context getContext(String contextName) {
164:                // Get just the properties for the context with the specified
165:                // name.
166:                Properties contextProps = null;
167:
168:                if (contextPropsList.containsKey(contextName)) {
169:                    contextProps = (Properties) contextPropsList
170:                            .get(contextName);
171:                } else {
172:                    contextProps = new Properties();
173:                }
174:
175:                // Construct a new context with the properties.
176:                try {
177:                    return new InitialContext(contextProps);
178:                } catch (Exception e) {
179:                    return null;
180:                }
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.