Source code: org/objectweb/jtests/jms/admin/AdminFactory.java
1 /*
2 * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3 * Copyright (C) 2002 INRIA
4 * Contact: joram-team@objectweb.org
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 *
21 * Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
22 * Contributor(s): ______________________________________.
23 */
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 //XXX
43 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 //XXX
55 System.exit(1);
56 }
57 try {
58 Class adminClass = Class.forName(adminClassName);
59 admin = (Admin)adminClass.newInstance();
60 } catch (ClassNotFoundException e) {
61 //XXX
62 System.err.println("Class "+ adminClassName +" not found.");
63 System.exit(1);
64 } catch (Exception e) {
65 //XXX
66 e.printStackTrace();
67 System.exit(1);
68 }
69
70 // System.out.println("JMS Provider: "+ admin.getName());
71
72 return admin;
73 }
74 }
75