Source Code Cross Referenced for CompositeFileOpener.java in  » Database-Client » LiquiBase » liquibase » 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 » Database Client » LiquiBase » liquibase 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package liquibase;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.net.URL;
006:        import java.util.*;
007:
008:        /**
009:         * A FileOpener that will search in a List of other FileOpeners until it finds
010:         * one that has a resource of the appropriate name and path.
011:         *
012:         * @author <a href="mailto:csuml@yahoo.co.uk>Paul Keeble</a>
013:         */
014:        public class CompositeFileOpener implements  FileOpener {
015:            List<FileOpener> openers;
016:
017:            /**
018:             * Creates a Composite Opener with the list specified. The List will
019:             * be searched in order from beginning to end.
020:             *
021:             * @param openers The list of Openers to use
022:             */
023:            public CompositeFileOpener(List<FileOpener> openers) {
024:                this .openers = openers;
025:            }
026:
027:            /**
028:             * Creates a CompositeFileOpener with 2 entries.
029:             *
030:             * @param openers The list of Openers to use
031:             */
032:            public CompositeFileOpener(FileOpener... openers) {
033:                this .openers = Arrays.asList(openers);
034:            }
035:
036:            /**
037:             * Searches through all of the FileOpeners in order for the file.
038:             * <p/>
039:             * If none of the FileOpeners was able to produce a stream to the file
040:             * then null is returned.
041:             */
042:            public InputStream getResourceAsStream(String file)
043:                    throws IOException {
044:                for (FileOpener o : openers) {
045:                    InputStream is = o.getResourceAsStream(file);
046:                    if (is != null)
047:                        return is;
048:                }
049:                return null;
050:            }
051:
052:            /**
053:             * Searches all of the FileOpeners for a directory named packageName. If no
054:             * results are found within any of the directories then an empty
055:             * Enumeration is returned.
056:             */
057:            public Enumeration<URL> getResources(String packageName)
058:                    throws IOException {
059:                for (FileOpener o : openers) {
060:                    Enumeration<URL> e = o.getResources(packageName);
061:                    if (e.hasMoreElements())
062:                        return e;
063:                }
064:                return new Vector<URL>().elements();
065:            }
066:
067:            public ClassLoader toClassLoader() {
068:                List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
069:                for (FileOpener fo : openers) {
070:                    classLoaders.add(fo.toClassLoader());
071:                }
072:
073:                return new CompositeClassLoader(classLoaders
074:                        .toArray(new ClassLoader[classLoaders.size()]));
075:            }
076:
077:            //based on code from http://fisheye.codehaus.org/browse/xstream/trunk/xstream/src/java/com/thoughtworks/xstream/core/util/CompositeClassLoader.java?r=root
078:            private static class CompositeClassLoader extends ClassLoader {
079:
080:                private final List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
081:
082:                public CompositeClassLoader(ClassLoader... classLoaders) {
083:                    this .classLoaders.addAll(Arrays.asList(classLoaders));
084:                }
085:
086:                public Class loadClass(String name)
087:                        throws ClassNotFoundException {
088:                    for (Object classLoader1 : classLoaders) {
089:                        ClassLoader classLoader = (ClassLoader) classLoader1;
090:                        try {
091:                            return classLoader.loadClass(name);
092:                        } catch (ClassNotFoundException notFound) {
093:                            // ok.. try another one
094:                        }
095:                    }
096:
097:                    // One last try - the context class loader associated with the current thread. Often used in j2ee servers.
098:                    // Note: The contextClassLoader cannot be added to the classLoaders list up front as the thread that constructs
099:                    // liquibase is potentially different to thread that uses it.
100:                    ClassLoader contextClassLoader = Thread.currentThread()
101:                            .getContextClassLoader();
102:                    if (contextClassLoader != null) {
103:                        return contextClassLoader.loadClass(name);
104:                    } else {
105:                        throw new ClassNotFoundException(name);
106:                    }
107:
108:                }
109:
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.