001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)CLUtils.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import java.io.File;
032: import java.net.URL;
033: import java.lang.ClassLoader;
034: import java.net.URLClassLoader;
035: import java.util.Iterator;
036: import java.util.List;
037: import java.lang.StackTraceElement;
038:
039: public class CLUtils {
040: /*
041: * location of the path to the unit test data JAR files
042: */
043: public static String getTestJarsPath(String srcRoot) {
044: return (srcRoot + File.separator + "runtime/framework/regress/data/classloader");
045: }
046:
047: /*
048: * location of the path to the unit test data class files
049: */
050: public static String getTestClassPath(String srcRoot) {
051: return (srcRoot + File.separator + "runtime/framework/regress/data/classloader/classes");
052: }
053:
054: /*
055: * location of the path to the unit test data resource files
056: */
057: public static String getTestResourcePath(String srcRoot) {
058: return (srcRoot + File.separator + "runtime/framework/regress/data/classloader/resources");
059: }
060:
061: /*
062: * creates a generic java.net.URLClassLoader
063: * based on data provided
064: */
065: public static ClassLoader createClassLoader(URL[] urls,
066: ClassLoader parent) {
067: return URLClassLoader.newInstance(urls, parent);
068: }
069:
070: /**
071: * method to convert a List into a URL array.
072: *
073: * @param paths list of String elements representing paths and JAR file
074: * names
075: * @return java.net.URL[] array representing the URLs corresponding to the
076:
077: * paths, or null if the list is null or if there is an exception creating
078: * the array.
079: * @throws Exception If the array creation is unsucessful.
080: */
081: public static URL[] list2URLArray(List paths) throws Exception {
082: File f;
083: URL[] urls = new URL[paths.size()];
084: int i = 0;
085: for (Iterator itr = paths.listIterator(); itr.hasNext();) {
086: String nextCPElement = (String) itr.next();
087: f = new File(nextCPElement);
088: urls[i++] = f.toURL();
089: }
090:
091: return urls;
092: }
093:
094: /**
095: * logs a message to the system console
096: */
097: public static void log(String msg) {
098: System.out.println(msg);
099: }
100:
101: /*
102: * method to print out the stack trace elements of an exception
103: */
104: public static void dumpStackTrace(Throwable t) {
105: StackTraceElement[] steArr = t.getStackTrace();
106: log("-----------------------------------");
107: log("Stack Trace for :" + t.getMessage());
108:
109: String prefix = "-";
110: for (int i = 0; i < steArr.length; i++) {
111: StackTraceElement ste = steArr[i];
112: prefix += "-";
113: log(prefix + ste.getClassName() + ":" + ste.getMethodName()
114: + ":" + ste.getLineNumber());
115: }
116: log("-----------------------------------");
117: }
118: }
|