1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.script.framework.provider;
25 
26 import java.net.*;
27 
28 import com.sun.star.script.framework.log.LogUtils;
29 import com.sun.star.script.framework.container.ScriptMetaData;
30 
31 /**
32  *  Class Loader Factory
33  *
34  * @author     Noel Power
35  * @created    August 2, 2002
36  */
37 public class ClassLoaderFactory
38 {
ClassLoaderFactory()39     private ClassLoaderFactory() {}
40 
getURLClassLoader( ScriptMetaData scriptData )41     public static ClassLoader getURLClassLoader( ScriptMetaData scriptData )
42         throws NoSuitableClassLoaderException, MalformedURLException
43     {
44         ClassLoader parent = scriptData.getClass().getClassLoader();
45         URL[] classPath = scriptData.getClassPath();
46         LogUtils.DEBUG("Classpath has length " + classPath.length );
47         for ( int i=0; i < classPath.length; i++ )
48         {
49             LogUtils.DEBUG("ClassPath " + i + "} is " + classPath[ i ].toString() );
50         }
51         return getURLClassLoader( parent, classPath );
52     }
getURLClassLoader( ClassLoader parent, URL[] classpath)53     public static ClassLoader getURLClassLoader( ClassLoader parent, URL[] classpath)
54         throws NoSuitableClassLoaderException
55     {
56         ClassLoader loader =
57             new URLClassLoader( classpath, parent);
58 
59         if (loader != null)
60         {
61             return loader;
62         }
63         else
64         {
65             throw new NoSuitableClassLoaderException(
66                 "Unable to create URLClassLoader");
67         }
68     }
69 
70 }
71