Source Code Cross Referenced for ContextJndiBeanFactoryLocator.java in  » J2EE » spring-framework-2.0.6 » org » springframework » context » access » 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 » spring framework 2.0.6 » org.springframework.context.access 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.context.access;
018:
019:        import javax.naming.NamingException;
020:
021:        import org.springframework.beans.BeansException;
022:        import org.springframework.beans.factory.access.BeanFactoryLocator;
023:        import org.springframework.beans.factory.access.BeanFactoryReference;
024:        import org.springframework.beans.factory.access.BootstrapException;
025:        import org.springframework.context.ApplicationContext;
026:        import org.springframework.context.support.ClassPathXmlApplicationContext;
027:        import org.springframework.jndi.JndiLocatorSupport;
028:        import org.springframework.util.StringUtils;
029:
030:        /**
031:         * BeanFactoryLocator implementation that creates the BeanFactory from one or
032:         * more classpath locations specified in a JNDI environment variable.
033:         *
034:         * <p>This default implementation creates a
035:         * {@link org.springframework.context.support.ClassPathXmlApplicationContext}.
036:         * Subclasses may override {@link #createBeanFactory} for custom instantiation.
037:         *
038:         * @author Colin Sampaleanu
039:         * @author Juergen Hoeller
040:         * @see #createBeanFactory
041:         */
042:        public class ContextJndiBeanFactoryLocator extends JndiLocatorSupport
043:                implements  BeanFactoryLocator {
044:
045:            /**
046:             * Any number of these characters are considered delimiters between
047:             * multiple bean factory config paths in a single String value.
048:             */
049:            public static final String BEAN_FACTORY_PATH_DELIMITERS = ",; \t\n";
050:
051:            /**
052:             * Load/use a bean factory, as specified by a factory key which is a JNDI
053:             * address, of the form <code>java:comp/env/ejb/BeanFactoryPath</code>. The
054:             * contents of this JNDI location must be a string containing one or more
055:             * classpath resource names (separated by any of the delimiters '<code>,; \t\n</code>'
056:             * if there is more than one. The resulting BeanFactory (or ApplicationContext)
057:             * will be created from the combined resources.
058:             * @see #createBeanFactory
059:             */
060:            public BeanFactoryReference useBeanFactory(String factoryKey)
061:                    throws BeansException {
062:                try {
063:                    String beanFactoryPath = (String) lookup(factoryKey,
064:                            String.class);
065:                    if (logger.isTraceEnabled()) {
066:                        logger
067:                                .trace("Bean factory path from JNDI environment variable ["
068:                                        + factoryKey
069:                                        + "] is: "
070:                                        + beanFactoryPath);
071:                    }
072:                    String[] paths = StringUtils.tokenizeToStringArray(
073:                            beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS);
074:                    return createBeanFactory(paths);
075:                } catch (NamingException ex) {
076:                    throw new BootstrapException(
077:                            "Define an environment variable ["
078:                                    + factoryKey
079:                                    + "] containing "
080:                                    + "the class path locations of XML bean definition files",
081:                            ex);
082:                }
083:            }
084:
085:            /**
086:             * Create the BeanFactory instance, given an array of class path resource Strings
087:             * which should be combined. This is split out as a separate method so that
088:             * subclasses can override the actual BeanFactory implementation class.
089:             * <p>Delegates to <code>createApplicationContext</code> by default,
090:             * wrapping the result in a ContextBeanFactoryReference.
091:             * @param resources an array of Strings representing classpath resource names
092:             * @return the created BeanFactory, wrapped in a BeanFactoryReference
093:             * (for example, a ContextBeanFactoryReference wrapping an ApplicationContext)
094:             * @throws BeansException if factory creation failed
095:             * @see #createApplicationContext
096:             * @see ContextBeanFactoryReference
097:             */
098:            protected BeanFactoryReference createBeanFactory(String[] resources)
099:                    throws BeansException {
100:                ApplicationContext ctx = createApplicationContext(resources);
101:                return new ContextBeanFactoryReference(ctx);
102:            }
103:
104:            /**
105:             * Create the ApplicationContext instance, given an array of class path resource
106:             * Strings which should be combined
107:             * @param resources an array of Strings representing classpath resource names
108:             * @return the created ApplicationContext
109:             * @throws BeansException if context creation failed
110:             */
111:            protected ApplicationContext createApplicationContext(
112:                    String[] resources) throws BeansException {
113:                return new ClassPathXmlApplicationContext(resources);
114:            }
115:
116:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.