Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) FuseSource, Inc. http://fusesource.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 
 package org.fusesource.fabric.dosgi.util.internal;
 
 import java.net.URL;
 
 import  org.osgi.framework.Bundle;
 import  org.osgi.framework.BundleReference;

Deprecated:
Please use AriesFrameworkUtil.getClassLoader to get a class loader for a bundle instead of this method
 
 public class BundleToClassLoaderAdapter extends ClassLoader implements BundleReference {
     private Bundle b;
 
     public BundleToClassLoaderAdapter(Bundle bundle) {
          = bundle;
     }
 
     @Override
     public URL getResource(final String name) {
         return AccessController.doPrivileged(new PrivilegedAction<URL>() {
             public URL run() {
                 return .getResource(name);
             }
         });
     }
 
     @Override
     public InputStream getResourceAsStream(String name) {
         URL url = getResource(name);
 
         InputStream result = null;
 
         if (url != null) {
             try {
                 result = url.openStream();
             } catch (IOException e) {
             }
         }
 
         return result;
     }
 
     @Override
     public Enumeration<URLgetResources(final String namethrows IOException {
         Enumeration<URLurls;
         try {
             urls = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
                 @SuppressWarnings("unchecked")
                 public Enumeration<URLrun() throws IOException {
                     return .getResources(name);
                 }
             });
         } catch (PrivilegedActionException e) {
             Exception cause = e.getException();
 
             if (cause instanceof IOExceptionthrow (IOExceptioncause;
             if (cause instanceof RuntimeExceptionthrow (RuntimeExceptioncause;
             throw new IOException(namecause);
         }
 
         if (urls == null) {
             urls = Collections.enumeration(new ArrayList<URL>());
         }
 
         return urls;
     }
 
     @Override
     public Class<?> loadClass(final String namethrows ClassNotFoundException {
         try {
             return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
                public Class<?> run() throws ClassNotFoundException {
                    return .loadClass(name);
                }
            });
        } catch (PrivilegedActionException e) {
            Exception cause = e.getException();
            if (cause instanceof ClassNotFoundExceptionthrow (ClassNotFoundExceptioncause;
            if (cause instanceof RuntimeExceptionthrow (RuntimeExceptioncause;
            throw new ClassNotFoundException(namecause);
        }
    }
    public Bundle getBundle() {
        return ;
    }
New to GrepCode? Check out our FAQ X