package net.hyperic.sigar;

import net.hyperic.jni.ArchLoader;
import net.hyperic.jni.ArchLoaderException;
import net.hyperic.jni.ArchName;
import net.hyperic.jni.ArchNotSupportedException;

public class SigarLoader extends ArchLoader {

    private static String location = null;

    public SigarLoader(Class loaderClass) {
        super(loaderClass);
    }

    //XXX same as super.getArchLibName()
    //but db2monitor.jar gets loaded first in jboss
    //results in NoSuchMethodError
    public String getArchLibName()
        throws ArchNotSupportedException {

        return getName() + "-" + ArchName.getName();
    }

    public String getDefaultLibName()
        throws ArchNotSupportedException {

        return getArchLibName(); //drop "java" prefix
    }

    //override these methods to ensure our ClassLoader
    //loads the native library.
    protected void systemLoadLibrary(String name) {
        System.loadLibrary(name);
    }

    protected void systemLoad(String name) {
        System.load(name);
    }

    /**
     * Returns the path where sigar.jar is located.
     */
    public synchronized static String getLocation() {
        if (location == null) {
            SigarLoader loader = new SigarLoader(Sigar.class);
            try {
                location = loader.findJarPath("sigar.jar");
            } catch (ArchLoaderException e) {
                location = ".";
            }
        }
        return location;
    }
}

@@ -273,16 +273,61 @@
  = null;
+%0A    private static String nativeName = null;
 %0A%0A    pu
@@ -1495,11 +1495,459 @@
 n;%0A    %7D
+%0A%0A    /**%0A     * Returns the name of the native sigar library.%0A     */%0A    public synchronized static String getNativeLibraryName() %7B%0A        if (nativeName == null) %7B%0A            SigarLoader loader = new SigarLoader(Sigar.class);%0A%0A            try %7B%0A                nativeName = loader.getLibraryName();%0A            %7D catch (ArchNotSupportedException e) %7B%0A                nativeName = null;%0A            %7D%0A        %7D%0A%0A        return nativeName;%0A    %7D
 %0A%7D%0A

add static helper getNativeLibraryName