1 18 19 package sync4j.syncclient.spap.launcher; 20 21 import java.util.Hashtable ; 22 23 24 import sync4j.syncclient.spap.AssetInstallationException; 25 import sync4j.syncclient.spdm.DMException; 26 import sync4j.syncclient.spdm.DeviceManager; 27 import sync4j.syncclient.spdm.SimpleDeviceManager; 28 29 37 38 public class LauncherFactory { 39 40 private static Hashtable fileExtensionMapping = null; 43 44 static { 45 DeviceManager dm = SimpleDeviceManager.getDeviceManager(); 47 48 try { 49 fileExtensionMapping = 50 dm.getManagementTree("").getNodeValues("spap/launcherFactoryConfig"); 51 } 52 catch (DMException ex) { 53 throw new IllegalStateException ("Error in LauncherFactory config"); 54 } 55 } 56 57 58 60 69 public static Launcher getLauncher(String programName) throws AssetInstallationException { 70 Launcher launcher = null; 71 72 int indexPoint = programName.lastIndexOf("."); 73 String extension = programName.substring(indexPoint + 1, programName.length()); 74 75 String classLauncher = (String )fileExtensionMapping.get(extension); 76 77 if (classLauncher != null) { 78 79 try { 80 launcher = (Launcher)(Class.forName(classLauncher).newInstance()); 81 } catch (ClassNotFoundException ex) { 82 throw new AssetInstallationException( 83 "Error in launcher inizialization for class '" + 84 classLauncher + "' (Class not found)" 85 ); 86 } catch (Exception ex) { 87 throw new AssetInstallationException( 88 "Error in launcher inizialization for class '" + 89 classLauncher + "' (" + ex.getMessage() + ")"); 90 } 91 92 } else { 93 throw new AssetInstallationException("Launcher not defined for " + 94 extension + " program"); 95 } 96 return launcher; 97 } 98 99 100 } | Popular Tags |