1 11 12 package org.eclipse.osgi.internal.baseadaptor; 13 14 import java.io.File ; 15 import java.security.ProtectionDomain ; 16 import java.util.ArrayList ; 17 import org.eclipse.osgi.baseadaptor.BaseData; 18 import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry; 19 import org.eclipse.osgi.baseadaptor.hooks.ClassLoadingHook; 20 import org.eclipse.osgi.baseadaptor.loader.*; 21 import org.eclipse.osgi.framework.adaptor.BundleProtectionDomain; 22 import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate; 23 import org.eclipse.osgi.framework.debug.Debug; 24 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 25 import org.eclipse.osgi.util.ManifestElement; 26 27 public class BaseClassLoadingHook implements ClassLoadingHook { 28 private static final String [] LIB_EXTENSIONS = ManifestElement.getArrayFromList(FrameworkProperties.getProperty("osgi.framework.library.extensions"), ","); private static final String [] EMPTY_STRINGS = new String [0]; 30 31 36 public static String [] mapLibraryNames(String mappedLibName) { 37 int extIndex = mappedLibName.lastIndexOf('.'); 38 if (LIB_EXTENSIONS.length == 0 || extIndex < 0) 39 return EMPTY_STRINGS; 40 String libNameBase = mappedLibName.substring(0, extIndex); 41 String [] results = new String [LIB_EXTENSIONS.length]; 42 for (int i = 0; i < results.length; i++) 43 results[i] = libNameBase + LIB_EXTENSIONS[i]; 44 return results; 45 } 46 47 public String findLibrary(BaseData data, String libName) { 48 String mappedName = System.mapLibraryName(libName); 49 String path = null; 50 if (Debug.DEBUG && Debug.DEBUG_LOADER) 51 Debug.println(" mapped library name: " + mappedName); path = findNativePath(data, mappedName); 53 if (path == null) { 54 String [] mappedNames = mapLibraryNames(mappedName); 55 for (int i = 0; i < mappedNames.length && path == null; i++) 56 path = findNativePath(data, mappedNames[i]); 57 } 58 if (path == null) { 59 if (Debug.DEBUG && Debug.DEBUG_LOADER) 60 Debug.println(" library does not exist: " + mappedName); path = findNativePath(data, libName); 62 } 63 if (Debug.DEBUG && Debug.DEBUG_LOADER) 64 Debug.println(" returning library: " + path); return path; 66 } 67 68 private String findNativePath(BaseData bundledata, String libname) { 69 int slash = libname.lastIndexOf('/'); 70 if (slash >= 0) 71 libname = libname.substring(slash + 1); 72 String [] nativepaths = getNativePaths(bundledata); 73 if (nativepaths == null) 74 return null; 75 for (int i = 0; i < nativepaths.length; i++) { 76 slash = nativepaths[i].lastIndexOf('/'); 77 String path = slash < 0 ? nativepaths[i] : nativepaths[i].substring(slash + 1); 78 if (path.equals(libname)) { 79 if (nativepaths[i].startsWith(BaseStorageHook.EXTERNAL_LIB_PREFIX)) { 80 String externalPath = BaseStorageHook.substituteVars(nativepaths[i].substring(BaseStorageHook.EXTERNAL_LIB_PREFIX.length())); 82 File nativeFile = new File (externalPath); 83 return nativeFile.getAbsolutePath(); 84 } 85 File nativeFile = bundledata.getBundleFile().getFile(nativepaths[i], true); 87 if (nativeFile != null) 88 return nativeFile.getAbsolutePath(); 89 } 90 } 91 return null; 92 } 93 94 private String [] getNativePaths(BaseData bundledata) { 95 BaseStorageHook storageHook = (BaseStorageHook) bundledata.getStorageHook(BaseStorageHook.KEY); 96 return storageHook != null ? storageHook.getNativePaths() : null; 97 } 98 99 public boolean addClassPathEntry(ArrayList cpEntries, String cp, ClasspathManager hostmanager, BaseData sourcedata, ProtectionDomain sourcedomain) { 100 return false; 102 } 103 104 public ClassLoader getBundleClassLoaderParent() { 105 return null; 107 } 108 109 public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) { 110 return null; 112 } 113 114 public BaseClassLoader createClassLoader(ClassLoader parent, ClassLoaderDelegate delegate, BundleProtectionDomain domain, BaseData data, String [] bundleclasspath) { 115 return null; 117 } 118 119 public void initializedClassLoader(BaseClassLoader baseClassLoader, BaseData data) { 120 } 122 123 } 124 | Popular Tags |