Source Code Cross Referenced for DefaultResourceLoader.java in  » J2EE » spring-framework-2.5 » org » springframework » core » io » 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.core.io 
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.core.io;
018:
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:
022:        import org.springframework.util.Assert;
023:        import org.springframework.util.ClassUtils;
024:
025:        /**
026:         * Default implementation of the {@link ResourceLoader} interface.
027:         * Used by {@link ResourceEditor}, and serves as base class for
028:         * {@link org.springframework.context.support.AbstractApplicationContext}.
029:         * Can also be used standalone.
030:         *
031:         * <p>Will return a {@link UrlResource} if the location value is a URL,
032:         * and a {@link ClassPathResource} if it is a non-URL path or a
033:         * "classpath:" pseudo-URL.
034:         *
035:         * @author Juergen Hoeller
036:         * @since 10.03.2004
037:         * @see FileSystemResourceLoader
038:         * @see org.springframework.context.support.ClassPathXmlApplicationContext
039:         */
040:        public class DefaultResourceLoader implements  ResourceLoader {
041:
042:            private ClassLoader classLoader;
043:
044:            /**
045:             * Create a new DefaultResourceLoader.
046:             * <p>ClassLoader access will happen using the thread context class loader
047:             * at the time of this ResourceLoader's initialization.
048:             * @see java.lang.Thread#getContextClassLoader()
049:             */
050:            public DefaultResourceLoader() {
051:                this .classLoader = ClassUtils.getDefaultClassLoader();
052:            }
053:
054:            /**
055:             * Create a new DefaultResourceLoader.
056:             * @param classLoader the ClassLoader to load class path resources with, or <code>null</code>
057:             * for using the thread context class loader at the time of actual resource access
058:             */
059:            public DefaultResourceLoader(ClassLoader classLoader) {
060:                this .classLoader = classLoader;
061:            }
062:
063:            /**
064:             * Specify the ClassLoader to load class path resources with, or <code>null</code>
065:             * for using the thread context class loader at the time of actual resource access.
066:             * <p>The default is that ClassLoader access will happen using the thread context
067:             * class loader at the time of this ResourceLoader's initialization.
068:             */
069:            public void setClassLoader(ClassLoader classLoader) {
070:                this .classLoader = classLoader;
071:            }
072:
073:            /**
074:             * Return the ClassLoader to load class path resources with,
075:             * or <code>null</code> if using the thread context class loader on actual access
076:             * (applying to the thread that constructs the ClassPathResource object).
077:             * <p>Will get passed to ClassPathResource's constructor for all
078:             * ClassPathResource objects created by this resource loader.
079:             * @see ClassPathResource
080:             */
081:            public ClassLoader getClassLoader() {
082:                return this .classLoader;
083:            }
084:
085:            public Resource getResource(String location) {
086:                Assert.notNull(location, "Location must not be null");
087:                if (location.startsWith(CLASSPATH_URL_PREFIX)) {
088:                    return new ClassPathResource(location
089:                            .substring(CLASSPATH_URL_PREFIX.length()),
090:                            getClassLoader());
091:                } else {
092:                    try {
093:                        // Try to parse the location as a URL...
094:                        URL url = new URL(location);
095:                        return new UrlResource(url);
096:                    } catch (MalformedURLException ex) {
097:                        // No URL -> resolve as resource path.
098:                        return getResourceByPath(location);
099:                    }
100:                }
101:            }
102:
103:            /**
104:             * Return a Resource handle for the resource at the given path.
105:             * <p>The default implementation supports class path locations. This should
106:             * be appropriate for standalone implementations but can be overridden,
107:             * e.g. for implementations targeted at a Servlet container.
108:             * @param path the path to the resource
109:             * @return the corresponding Resource handle
110:             * @see ClassPathResource
111:             * @see org.springframework.context.support.FileSystemXmlApplicationContext#getResourceByPath
112:             * @see org.springframework.web.context.support.XmlWebApplicationContext#getResourceByPath
113:             */
114:            protected Resource getResourceByPath(String path) {
115:                return new ClassPathContextResource(path, getClassLoader());
116:            }
117:
118:            /**
119:             * ClassPathResource that explicitly expresses a context-relative path
120:             * through implementing the ContextResource interface.
121:             */
122:            private static class ClassPathContextResource extends
123:                    ClassPathResource implements  ContextResource {
124:
125:                public ClassPathContextResource(String path,
126:                        ClassLoader classLoader) {
127:                    super (path, classLoader);
128:                }
129:
130:                public String getPathWithinContext() {
131:                    return getPath();
132:                }
133:            }
134:
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.