1 23 24 package org.jboss.web.php; 25 26 33 public class Library { 34 35 36 private static String [] NAMES = { "php5servlet", "libphp5servlet" }; 37 38 41 private static Library engine = null; 42 private static boolean inited = false; 43 44 private Library() 45 { 46 boolean loaded = false; 47 String err = ""; 48 for (int i = 0; i < NAMES.length; i++) { 49 try { 50 System.loadLibrary(NAMES[i]); 51 loaded = true; 52 } catch (Throwable e) { 53 if ( i > 0) 54 err += ", "; 55 err += e.getMessage(); 56 } 57 if (loaded) 58 break; 59 } 60 if (!loaded) { 61 err += "("; 62 err += System.getProperty("java.library.path"); 63 err += ")"; 64 throw new UnsatisfiedLinkError (err); 65 } 66 } 67 68 private Library(String libraryName) 69 { 70 System.loadLibrary(libraryName); 71 } 72 73 74 public static int PHP_MAJOR_VERSION = 0; 75 76 public static int PHP_MINOR_VERSION = 0; 77 78 public static int PHP_PATCH_VERSION = 0; 79 80 83 private static native boolean startup(); 84 85 88 public static native void shutdown(); 89 90 91 private static native int version(int index); 92 93 98 public static boolean initialize(String libraryName) 99 throws Exception 100 { 101 if (engine == null) { 102 if (libraryName == null) 103 engine = new Library(); 104 else 105 engine = new Library(libraryName); 106 PHP_MAJOR_VERSION = version(1); 107 PHP_MINOR_VERSION = version(2); 108 PHP_PATCH_VERSION = version(3); 109 } 110 inited = startup(); 111 return inited; 112 } 113 114 117 public static boolean isInitialized() 118 { 119 return inited; 120 } 121 122 125 public static void terminate() 126 { 127 if (engine != null) { 128 shutdown(); 129 engine = null; 130 inited = false; 131 } 132 } 133 } 134 | Popular Tags |