Source Code Cross Referenced for XmlWebApplicationContext.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » context » support » 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.web.context.support 
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.web.context.support;
018:
019:        import java.io.IOException;
020:
021:        import org.springframework.beans.BeansException;
022:        import org.springframework.beans.factory.support.DefaultListableBeanFactory;
023:        import org.springframework.beans.factory.xml.ResourceEntityResolver;
024:        import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
025:
026:        /**
027:         * {@link org.springframework.web.context.WebApplicationContext} implementation
028:         * which takes its configuration from XML documents, understood by an
029:         * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
030:         * This is essentially the equivalent of
031:         * {@link org.springframework.context.support.AbstractXmlApplicationContext}
032:         * for a web environment.
033:         *
034:         * <p>By default, the configuration will be taken from "/WEB-INF/applicationContext.xml"
035:         * for the root context, and "/WEB-INF/test-servlet.xml" for a context with the namespace
036:         * "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").
037:         *
038:         * <p>The config location defaults can be overridden via the "contextConfigLocation"
039:         * context-param of {@link org.springframework.web.context.ContextLoader} and servlet
040:         * init-param of {@link org.springframework.web.servlet.FrameworkServlet}. Config locations
041:         * can either denote concrete files like "/WEB-INF/context.xml" or Ant-style patterns
042:         * like "/WEB-INF/*-context.xml" (see {@link org.springframework.util.PathMatcher}
043:         * javadoc for pattern details).
044:         *
045:         * <p>Note: In case of multiple config locations, later bean definitions will
046:         * override ones defined in earlier loaded files. This can be leveraged to
047:         * deliberately override certain bean definitions via an extra XML file.
048:         *
049:         * <p><b>For a WebApplicationContext that reads in a different bean definition format,
050:         * create an analogous subclass of {@link AbstractRefreshableWebApplicationContext}.</b>
051:         * Such a context implementation can be specified as "contextClass" context-param
052:         * for ContextLoader or "contextClass" init-param for FrameworkServlet.
053:         *
054:         * @author Rod Johnson
055:         * @author Juergen Hoeller
056:         * @see #setNamespace
057:         * @see #setConfigLocations
058:         * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
059:         * @see org.springframework.web.context.ContextLoader#initWebApplicationContext
060:         * @see org.springframework.web.servlet.FrameworkServlet#initWebApplicationContext
061:         */
062:        public class XmlWebApplicationContext extends
063:                AbstractRefreshableWebApplicationContext {
064:
065:            /** Default config location for the root context */
066:            public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";
067:
068:            /** Default prefix for building a config location for a namespace */
069:            public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/";
070:
071:            /** Default suffix for building a config location for a namespace */
072:            public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml";
073:
074:            /**
075:             * Loads the bean definitions via an XmlBeanDefinitionReader.
076:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
077:             * @see #initBeanDefinitionReader
078:             * @see #loadBeanDefinitions
079:             */
080:            protected void loadBeanDefinitions(
081:                    DefaultListableBeanFactory beanFactory) throws IOException {
082:                // Create a new XmlBeanDefinitionReader for the given BeanFactory.
083:                XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(
084:                        beanFactory);
085:
086:                // Configure the bean definition reader with this context's
087:                // resource loading environment.
088:                beanDefinitionReader.setResourceLoader(this );
089:                beanDefinitionReader
090:                        .setEntityResolver(new ResourceEntityResolver(this ));
091:
092:                // Allow a subclass to provide custom initialization of the reader,
093:                // then proceed with actually loading the bean definitions.
094:                initBeanDefinitionReader(beanDefinitionReader);
095:                loadBeanDefinitions(beanDefinitionReader);
096:            }
097:
098:            /**
099:             * Initialize the bean definition reader used for loading the bean
100:             * definitions of this context. Default implementation is empty.
101:             * <p>Can be overridden in subclasses, e.g. for turning off XML validation
102:             * or using a different XmlBeanDefinitionParser implementation.
103:             * @param beanDefinitionReader the bean definition reader used by this context
104:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setValidationMode
105:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader#setDocumentReaderClass
106:             */
107:            protected void initBeanDefinitionReader(
108:                    XmlBeanDefinitionReader beanDefinitionReader) {
109:            }
110:
111:            /**
112:             * Load the bean definitions with the given XmlBeanDefinitionReader.
113:             * <p>The lifecycle of the bean factory is handled by the refreshBeanFactory method;
114:             * therefore this method is just supposed to load and/or register bean definitions.
115:             * <p>Delegates to a ResourcePatternResolver for resolving location patterns
116:             * into Resource instances.
117:             * @throws org.springframework.beans.BeansException in case of bean registration errors
118:             * @throws java.io.IOException if the required XML document isn't found
119:             * @see #refreshBeanFactory
120:             * @see #getConfigLocations
121:             * @see #getResources
122:             * @see #getResourcePatternResolver
123:             */
124:            protected void loadBeanDefinitions(XmlBeanDefinitionReader reader)
125:                    throws BeansException, IOException {
126:                String[] configLocations = getConfigLocations();
127:                if (configLocations != null) {
128:                    for (int i = 0; i < configLocations.length; i++) {
129:                        reader.loadBeanDefinitions(configLocations[i]);
130:                    }
131:                }
132:            }
133:
134:            /**
135:             * The default location for the root context is "/WEB-INF/applicationContext.xml",
136:             * and "/WEB-INF/test-servlet.xml" for a context with the namespace "test-servlet"
137:             * (like for a DispatcherServlet instance with the servlet-name "test").
138:             */
139:            protected String[] getDefaultConfigLocations() {
140:                if (getNamespace() != null) {
141:                    return new String[] { DEFAULT_CONFIG_LOCATION_PREFIX
142:                            + getNamespace() + DEFAULT_CONFIG_LOCATION_SUFFIX };
143:                } else {
144:                    return new String[] { DEFAULT_CONFIG_LOCATION };
145:                }
146:            }
147:
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.