FileDocCategorySizeDatePackage
FindInSameDirectory.javaAPI DocFobs4JMF API 0.4.14351Tue Dec 19 14:26:54 GMT 2006com.moesol.bindings

FindInSameDirectory

public class FindInSameDirectory extends Object implements NativeLibraryFinderStrategy

Fields Summary
private static final Logger
s_logger
private String
m_classAsResourcePath
Constructors Summary
Methods Summary
public java.io.FilecomputeDirectoryForClass(java.lang.Class classInJar)
Computes the directory where NativeLibraryFinder will search for a native library. If classInJar is a class in a jar file then it will return the dirctory that contains the jar file. This is a common installation setup where foo.jar and foo.dll are installed into the same directory. If the jar file was downloaded via http then this method will return null.

If classInJar is a class that was not contained in a jar file, then this will return the directory that is the root of the class tree. This is the same location as a resource with the path of "/" would return. This is useful if the native library will eventually be packaged as a resource in a jar file, because finding the library directory here will allow the code to skip extracting the native library.

param
classInJar
return
the directory that will be searched for native libraries for classInJar or null if classInJar is downloaded.

		String strDir = computeDirectoryStringForClass(classInJar);
		if (strDir == null) {
			return null;
		}
		return new File(strDir);
	
java.lang.StringcomputeDirectoryForFileUrl(java.net.URL url)

		String strUrl = url.toExternalForm(); 
		String classesDirectory = strUrl.substring("file:".length(), strUrl.length() - m_classAsResourcePath.length());
		File dir = new File(classesDirectory);
		return dir.getAbsolutePath();
	
java.lang.StringcomputeDirectoryForJarUrl(java.net.URL url)

		File jarFile = computeJarFile(url);
		return jarFile.getParent();
	
private java.lang.StringcomputeDirectoryStringForClass(java.lang.Class classInJar)

		m_classAsResourcePath = computeResourceToFind(classInJar);
		URL url = classInJar.getResource(m_classAsResourcePath);
		String directory = null;
		if ("file".equals(url.getProtocol())) {
			directory = computeDirectoryForFileUrl(url);
		}
		if ("jar".equals(url.getProtocol())) {
			directory = computeDirectoryForJarUrl(url);
		}
		return directory;
	
protected java.io.FilecomputeJarFile(java.net.URL url)

		String strUrl = url.toExternalForm();
		String jarPath = strUrl.substring("jar:file:".length(), strUrl.length() - m_classAsResourcePath.length() - "!".length());
		
		File jarFile = new File(jarPath);
		return jarFile;
	
java.io.FilecomputePath(java.lang.String directory, java.lang.String osPrefix, java.lang.String mappedName)

		return new File(directory, osPrefix + mappedName);
	
private java.lang.StringcomputeResourceToFind(java.lang.Class classInJar)

		String pathToClass = classInJar.getName().replace('.", '/");
		String resourceToFind = "/" + pathToClass + ".class";
		return resourceToFind;
	
public voidfindAndLoad(java.lang.Class classInJar, java.lang.String libraryName)


	      
		String directory = computeDirectoryStringForClass(classInJar);
		if (directory != null) {
			tryOsPrefixes(directory, templateGetMappedName(classInJar, libraryName));
		}
	
public java.lang.StringgetClassAsResourcePath()

		return m_classAsResourcePath;
	
public voidsetClassAsResourcePath(java.lang.String resourceToFind)

		m_classAsResourcePath = resourceToFind;
	
protected java.lang.StringtemplateGetMappedName(java.lang.Class classInJar, java.lang.String libraryName)
Override to change the mapped name this class uses to search for the native library.

param
classInJar
param
libraryName
return
mapped name of library

		return System.mapLibraryName(libraryName);
	
voidtryOsPrefixes(java.lang.String directory, java.lang.String mappedName)

		for (int i = 0; i < NativeLibraryFinder.OS_PREFIXES.length; i++) {
			String osPrefix = NativeLibraryFinder.OS_PREFIXES[i];
			File fullPath = computePath(directory, osPrefix, mappedName);
			s_logger.log(Level.FINE, "trying {0}", fullPath);
			if (fullPath.exists()) {
				System.load(fullPath.getAbsolutePath());
				return;
			}
		}
		throw new UnsatisfiedLinkError("No library found");