KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Configurator


1 /*
2  * The source code contained herein is licensed under the IBM Public License
3  * Version 1.0, which has been approved by the Open Source Initiative.
4  * Copyright (C) 2001, International Business Machines Corporation
5  * Copyright (C) 2001, Hewlett-Packard Company
6  * All Rights Reserved.
7  *
8  */

9
10 import java.util.Properties JavaDoc;
11
12 import org.uddi4j.transport.TransportFactory;
13
14 /**
15  * Configures the environment for the UDDI4J samples.
16  * <OL>
17  * <LI>Reads samples property file.
18  * <LI>Sets SOAP transport according to property file.
19  * <LI>Configures SSL/JSSE provider
20  * </OL>
21  *
22  * @author David Melgar (dmelgar@us.ibm.com)
23  */

24
25 public class Configurator {
26
27    /**
28     * Loads configuration file. File may require
29     * modification before running samples.
30     *
31     * @return Loaded properties object
32     */

33    public static Properties JavaDoc load() {
34       Properties JavaDoc config = new Properties JavaDoc();
35       try {
36          config.load(new java.io.FileInputStream JavaDoc("samples.prop"));
37       } catch (Exception JavaDoc e) {
38          System.out.println("Error loading samples property file\n" + e);
39       }
40
41       // Configure UDDI4J system properties. Normally set on commandline or elsewhere
42
// SOAP transport being used
43
if (System.getProperty(TransportFactory.PROPERTY_NAME)==null) {
44          System.setProperty(TransportFactory.PROPERTY_NAME, config.getProperty("TransportClassName"));
45       }
46       // Logging
47
if (System.getProperty("org.uddi4j.logEnabled")==null) {
48          System.setProperty("org.uddi4j.logEnabled", config.getProperty("logEnabled"));
49       }
50
51       // Configure JSSE support
52
try {
53          System.setProperty("java.protocol.handler.pkgs", config.getProperty("handlerPackageName"));
54
55          // Dynamically loads security provider based on properties. Typically configured in JRE
56
java.security.Security.addProvider((java.security.Provider JavaDoc)
57             Class.forName(config.getProperty("securityClassName")).newInstance());
58       } catch (Exception JavaDoc e) {
59          System.out.println("Error configuring JSSE provider. Make sure JSSE is in classpath.\n" + e);
60       }
61       return config;
62    }
63 }
64
Popular Tags