File Source: StandaloneWebappClassLoader.java
/*
P/P * Method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 *
18 * StandaloneWebappClassLoader.java
19 * Created on October 20, 2006, 11:11 PM
20 */
21
22 package org.apache.roller.weblogger.util;
23
24 import java.io.File;
25 import java.io.FilenameFilter;
26 import java.net.URL;
27 import java.net.URLClassLoader;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32 * ClassLoader to enable running webapp classes outside of webapp.
33 * You provide webappDir and jarsDir paths and the classloader will include
34 * webappDir/WEB-INF/classes, webappDir/WEB-INF/lib/*jar and jarsDir/*.jar.
35 */
36 public class StandaloneWebappClassLoader extends URLClassLoader {
/*
P/P * Method: org.apache.roller.weblogger.util.StandaloneWebappClassLoader__static_init
*
* Presumptions:
* init'ed(java.io.File.separator)
*
* Postconditions:
* FS == java.io.File.separator
* (soft) init'ed(FS)
*/
37 public static String FS = File.separator;
38
39 /** Use calling class's parent classloader */
40 public StandaloneWebappClassLoader(String webappDir, String jarsDir) throws Exception {
/*
P/P * Method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String)
*
* Preconditions:
* init'ed(FS)
*/
41 super(buildURLsArray(webappDir, jarsDir));
42 }
43
44 /** Use a specific parent classloader, or null for no parent */
45 public StandaloneWebappClassLoader(String webappDir, String jarsDir, ClassLoader cl) throws Exception {
/*
P/P * Method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader(String, String, ClassLoader)
*
* Preconditions:
* init'ed(FS)
*/
46 super(buildURLsArray(webappDir, jarsDir), cl);
47 }
48
49 private static URL[] buildURLsArray(String webappDir, String jarsDir) throws Exception {
50 // Create collection of URLs needed for classloader
/*
P/P * Method: URL[] buildURLsArray(String, String)
*
* Preconditions:
* init'ed(FS)
*
* Presumptions:
* java.util.List:size(...)@64 >= 0
*
* Postconditions:
* init'ed(return_value)
*/
51 List urlList = new ArrayList();
52
53 // Add WEB-INF/lib jars
54 String libPath = webappDir + FS + "WEB-INF" + FS + "lib";
55 addURLs(libPath, urlList);
56
57 // Added WEB-INF/classes
58 String classesPath = webappDir + FS + "WEB-INF" + FS + "classes" + FS;
59 urlList.add(new URL("file://" + classesPath));
60
61 // Add additional jars
62 addURLs(jarsDir, urlList);
63
64 return (URL[])urlList.toArray(new URL[urlList.size()]);
65 }
66
67 private static void addURLs(String dirPath, List urlList) throws Exception {
/*
P/P * Method: void addURLs(String, List)
*
* Preconditions:
* (soft) init'ed(FS)
* (soft) urlList != null
*
* Presumptions:
* java.io.File:list(...)@69 != null
* libJarNames.length@69 <= 232-1
*/
68 File libDir = new File(dirPath);
/*
P/P * Method: void org.apache.roller.weblogger.util.StandaloneWebappClassLoader$1()
*/
69 String[] libJarNames = libDir.list(new FilenameFilter() {
70 public boolean accept(File dir, String pathname) {
/*
P/P * Method: bool accept(File, String)
*
* Preconditions:
* pathname != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.lang.String:endsWith(...)@71: {0}, {1}
*/
71 if (pathname.endsWith(".jar")) {
72 return true;
73 }
74 return false;
75 }
76 });
77 for (int i=0; i<libJarNames.length; i++) {
78 String url = "file://" + dirPath + FS + libJarNames[i];
79 urlList.add(new URL(url));
80 }
81 }
82 }
SofCheck Inspector Build Version : 2.18479
| StandaloneWebappClassLoader.java |
2009-Jan-02 14:25:18 |
| StandaloneWebappClassLoader.class |
2009-Sep-04 03:12:32 |
| StandaloneWebappClassLoader$1.class |
2009-Sep-04 03:12:32 |