Source Code Cross Referenced for ClassPathResource.java in  » Swing-Library » wings3 » org » wings » resource » 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 » Swing Library » wings3 » org.wings.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2000,2005 wingS development team.
003:         *
004:         * This file is part of wingS (http://wingsframework.org).
005:         *
006:         * wingS is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1
009:         * of the License, or (at your option) any later version.
010:         *
011:         * Please see COPYING for the complete licence.
012:         */
013:        package org.wings.resource;
014:
015:        import org.wings.StaticResource;
016:        import org.wings.externalizer.ExternalizeManager;
017:        import java.io.InputStream;
018:
019:        /**
020:         * A Classpath Resource is a static resource whose content is
021:         * read from a classloader.
022:         *
023:         * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
024:         * @author <a href="mailto:H.Zeller@acm.org">Henner Zeller</a>
025:         */
026:        public class ClassPathResource extends StaticResource implements 
027:                NamedResource {
028:            /**
029:             * The class loader from which the resource is loaded
030:             */
031:            private final transient ClassLoader classLoader;
032:
033:            /**
034:             * The name that identifies the resource in the classpath
035:             */
036:            protected final String resourceFileName;
037:
038:            /**
039:             * A static resource that is obtained from the default classpath.
040:             */
041:            public ClassPathResource(String resourceFileName) {
042:                this (null, resourceFileName, "unkonwn");
043:            }
044:
045:            /**
046:             * A static resource that is obtained from the default classpath.
047:             */
048:            public ClassPathResource(String resourceFileName, String mimeType) {
049:                this (null, resourceFileName, mimeType);
050:            }
051:
052:            /**
053:             * A static resource that is obtained from the specified class loader
054:             *
055:             * @param classLoader      the classLoader from which the resource is obtained
056:             * @param resourceFileName the resource relative to the baseClass
057:             */
058:            public ClassPathResource(ClassLoader classLoader,
059:                    String resourceFileName) {
060:                this (classLoader, resourceFileName, "unknown");
061:            }
062:
063:            /**
064:             * A static resource that is obtained from the specified class loader
065:             *
066:             * @param classLoader      the classLoader from which the resource is obtained
067:             * @param resourceFileName the resource relative to the baseClass
068:             */
069:            public ClassPathResource(ClassLoader classLoader,
070:                    String resourceFileName, String mimeType) {
071:                super (null, mimeType);
072:                this .classLoader = classLoader;
073:                this .resourceFileName = resourceFileName;
074:                int dotIndex = resourceFileName.lastIndexOf('.');
075:                if (dotIndex > -1) {
076:                    extension = resourceFileName.substring(dotIndex + 1);
077:                }
078:                externalizerFlags = ExternalizeManager.GLOBAL
079:                        | ExternalizeManager.FINAL;
080:            }
081:
082:            @Override
083:            protected InputStream getResourceStream()
084:                    throws ResourceNotFoundException {
085:                InputStream stream = getClassLoader().getResourceAsStream(
086:                        resourceFileName);
087:                if (stream == null)
088:                    throw new ResourceNotFoundException(
089:                            "Classpath resource not found: " + resourceFileName);
090:                return stream;
091:            }
092:
093:            /*
094:             * the equal() and hashCode() method make sure, that the same resources
095:             * get the same name in the SystemExternalizer.
096:             */
097:
098:            /**
099:             * resources using the same classloader and are denoting the same
100:             * name, do have the same hashCode(). Thus the same resources get the
101:             * same ID in the System externalizer.
102:             *
103:             * @return a hashcode, comprised from the hashcodes of the classloader
104:             *         and from the file name of the resource.
105:             */
106:            @Override
107:            public int hashCode() {
108:                return (classLoader != null ? classLoader.hashCode() : 0)
109:                        ^ resourceFileName.hashCode();
110:            }
111:
112:            /**
113:             * Two ClasspathResouces are equal if both of them use the same
114:             * classloader and point to a resource with the same name.
115:             *
116:             * @return true if classloader and resource name are equal.
117:             */
118:            @Override
119:            public boolean equals(Object o) {
120:                if (o instanceof  ClassPathResource) {
121:                    ClassPathResource other = (ClassPathResource) o;
122:                    return ((this  == other) || ((classLoader == other.classLoader || (classLoader != null && classLoader
123:                            .equals(other.classLoader))) && resourceFileName
124:                            .equals(other.resourceFileName)));
125:                }
126:                return false;
127:            }
128:
129:            /**
130:             * @return The stored classloader or the current context classloader if none fixed passed (prefer this case due to session serialization!)
131:             */
132:            protected ClassLoader getClassLoader() {
133:                return this .classLoader == null ? Thread.currentThread()
134:                        .getContextClassLoader() : this .classLoader;
135:            }
136:
137:            public String getResourceName() {
138:                return resourceFileName;
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.