1 24 25 package org.objectweb.jtests.jms.admin; 26 27 import javax.naming.*; 28 import java.util.Properties ; 29 30 public class AdminFactory { 31 32 private static final String PROP_NAME = "jms.provider.admin.class"; 33 private static final String PROP_FILE_NAME = "provider.properties"; 34 35 protected static String getAdminClassName() { 36 String adminClassName; 37 try { 38 Properties props = new Properties (); 39 props.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME)); 40 adminClassName = props.getProperty(PROP_NAME); 41 } catch (Exception e) { 42 e.printStackTrace(); 44 adminClassName = null; 45 } 46 return adminClassName; 47 } 48 49 public static Admin getAdmin() { 50 String adminClassName = getAdminClassName(); 51 Admin admin = null; 52 if (adminClassName == null) { 53 System.err.println ("Property "+ PROP_NAME +" has not been found in the file "+ PROP_FILE_NAME +"."); 54 System.exit(1); 56 } 57 try { 58 Class adminClass = Class.forName(adminClassName); 59 admin = (Admin)adminClass.newInstance(); 60 } catch (ClassNotFoundException e) { 61 System.err.println("Class "+ adminClassName +" not found."); 63 System.exit(1); 64 } catch (Exception e) { 65 e.printStackTrace(); 67 System.exit(1); 68 } 69 70 72 return admin; 73 } 74 } 75 76 | Popular Tags |