Source Code Cross Referenced for ClassPathXmlApplicationContext.java in  » J2EE » spring-framework-2.5 » org » springframework » 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.5 » org.springframework.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.context.support;
018:
019:        import org.springframework.beans.BeansException;
020:        import org.springframework.context.ApplicationContext;
021:        import org.springframework.core.io.ClassPathResource;
022:        import org.springframework.core.io.Resource;
023:        import org.springframework.util.Assert;
024:        import org.springframework.util.StringUtils;
025:
026:        /**
027:         * Standalone XML application context, taking the context definition files
028:         * from the class path, interpreting plain paths as class path resource names
029:         * that include the package path (e.g. "mypackage/myresource.txt"). Useful for
030:         * test harnesses as well as for application contexts embedded within JARs.
031:         *
032:         * <p>The config location defaults can be overridden via {@link #getConfigLocations},
033:         * Config locations can either denote concrete files like "/myfiles/context.xml"
034:         * or Ant-style patterns like "/myfiles/*-context.xml" (see the
035:         * {@link org.springframework.util.AntPathMatcher} javadoc for pattern details).
036:         *
037:         * <p>Note: In case of multiple config locations, later bean definitions will
038:         * override ones defined in earlier loaded files. This can be leveraged to
039:         * deliberately override certain bean definitions via an extra XML file.
040:         *
041:         * <p><b>This is a simple, one-stop shop convenience ApplicationContext.
042:         * Consider using the {@link GenericApplicationContext} class in combination
043:         * with an {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}
044:         * for more flexible context setup.</b>
045:         *
046:         * @author Rod Johnson
047:         * @author Juergen Hoeller
048:         * @see #getResource
049:         * @see #getResourceByPath
050:         * @see GenericApplicationContext
051:         */
052:        public class ClassPathXmlApplicationContext extends
053:                AbstractXmlApplicationContext {
054:
055:            private Resource[] configResources;
056:
057:            private String[] configLocations;
058:
059:            /**
060:             * Create a new ClassPathXmlApplicationContext, loading the definitions
061:             * from the given XML file and automatically refreshing the context.
062:             * @param configLocation resource location
063:             * @throws BeansException if context creation failed
064:             */
065:            public ClassPathXmlApplicationContext(String configLocation)
066:                    throws BeansException {
067:                this (new String[] { configLocation }, true, null);
068:            }
069:
070:            /**
071:             * Create a new ClassPathXmlApplicationContext, loading the definitions
072:             * from the given XML files and automatically refreshing the context.
073:             * @param configLocations array of resource locations
074:             * @throws BeansException if context creation failed
075:             */
076:            public ClassPathXmlApplicationContext(String[] configLocations)
077:                    throws BeansException {
078:                this (configLocations, true, null);
079:            }
080:
081:            /**
082:             * Create a new ClassPathXmlApplicationContext with the given parent,
083:             * loading the definitions from the given XML files and automatically
084:             * refreshing the context.
085:             * @param configLocations array of resource locations
086:             * @param parent the parent context
087:             * @throws BeansException if context creation failed
088:             */
089:            public ClassPathXmlApplicationContext(String[] configLocations,
090:                    ApplicationContext parent) throws BeansException {
091:                this (configLocations, true, parent);
092:            }
093:
094:            /**
095:             * Create a new ClassPathXmlApplicationContext, loading the definitions
096:             * from the given XML files.
097:             * @param configLocations array of resource locations
098:             * @param refresh whether to automatically refresh the context,
099:             * loading all bean definitions and creating all singletons.
100:             * Alternatively, call refresh manually after further configuring the context.
101:             * @throws BeansException if context creation failed
102:             * @see #refresh()
103:             */
104:            public ClassPathXmlApplicationContext(String[] configLocations,
105:                    boolean refresh) throws BeansException {
106:                this (configLocations, refresh, null);
107:            }
108:
109:            /**
110:             * Create a new ClassPathXmlApplicationContext with the given parent,
111:             * loading the definitions from the given XML files.
112:             * @param configLocations array of resource locations
113:             * @param refresh whether to automatically refresh the context,
114:             * loading all bean definitions and creating all singletons.
115:             * Alternatively, call refresh manually after further configuring the context.
116:             * @param parent the parent context
117:             * @throws BeansException if context creation failed
118:             * @see #refresh()
119:             */
120:            public ClassPathXmlApplicationContext(String[] configLocations,
121:                    boolean refresh, ApplicationContext parent)
122:                    throws BeansException {
123:
124:                super (parent);
125:                this .configLocations = StringUtils
126:                        .trimArrayElements(configLocations);
127:                if (refresh) {
128:                    refresh();
129:                }
130:            }
131:
132:            /**
133:             * Create a new ClassPathXmlApplicationContext, loading the definitions
134:             * from the given XML file and automatically refreshing the context.
135:             * <p>This is a convenience method to load class path resources relative to a
136:             * given Class. For full flexibility, consider using a GenericApplicationContext
137:             * with an XmlBeanDefinitionReader and a ClassPathResource argument.
138:             * @param path relative (or absolute) path within the class path
139:             * @param clazz the class to load resources with (basis for the given paths)
140:             * @throws BeansException if context creation failed
141:             * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
142:             * @see org.springframework.context.support.GenericApplicationContext
143:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
144:             */
145:            public ClassPathXmlApplicationContext(String path, Class clazz)
146:                    throws BeansException {
147:                this (new String[] { path }, clazz);
148:            }
149:
150:            /**
151:             * Create a new ClassPathXmlApplicationContext, loading the definitions
152:             * from the given XML files and automatically refreshing the context.
153:             * @param paths array of relative (or absolute) paths within the class path
154:             * @param clazz the class to load resources with (basis for the given paths)
155:             * @throws BeansException if context creation failed
156:             * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
157:             * @see org.springframework.context.support.GenericApplicationContext
158:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
159:             */
160:            public ClassPathXmlApplicationContext(String[] paths, Class clazz)
161:                    throws BeansException {
162:                this (paths, clazz, null);
163:            }
164:
165:            /**
166:             * Create a new ClassPathXmlApplicationContext with the given parent,
167:             * loading the definitions from the given XML files and automatically
168:             * refreshing the context.
169:             * @param paths array of relative (or absolute) paths within the class path
170:             * @param clazz the class to load resources with (basis for the given paths)
171:             * @param parent the parent context
172:             * @throws BeansException if context creation failed
173:             * @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
174:             * @see org.springframework.context.support.GenericApplicationContext
175:             * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
176:             */
177:            public ClassPathXmlApplicationContext(String[] paths, Class clazz,
178:                    ApplicationContext parent) throws BeansException {
179:
180:                super (parent);
181:                Assert.notNull(paths, "Path array must not be null");
182:                Assert.notNull(clazz, "Class argument must not be null");
183:                this .configResources = new Resource[paths.length];
184:                for (int i = 0; i < paths.length; i++) {
185:                    this .configResources[i] = new ClassPathResource(paths[i],
186:                            clazz);
187:                }
188:                refresh();
189:            }
190:
191:            protected Resource[] getConfigResources() {
192:                return this .configResources;
193:            }
194:
195:            protected String[] getConfigLocations() {
196:                return this.configLocations;
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.