KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > uddi4j > transport > TransportFactory


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  * All Rights Reserved.
6  *
7  */

8
9 package org.uddi4j.transport;
10
11 import java.util.Properties JavaDoc;
12
13 /**
14  * Factory to dynamically create a Transport implementation.
15  *
16  * @author David Melgar (dmelgar@us.ibm.com)
17  */

18 public class TransportFactory {
19
20    public static final String JavaDoc PROPERTY_NAME =
21      "org.uddi4j.TransportClassName";
22
23    public static final String JavaDoc DEFAULT_TRANSPORT_NAME=
24       "org.uddi4j.transport.ApacheSOAPTransport";
25
26    private Transport transport = null;
27    static private String JavaDoc transportClassName = null;
28
29    Properties JavaDoc config = null;
30
31    /**
32     * Private constructor used by newInstance method.
33     *
34     * @param p
35     */

36    private TransportFactory(Properties JavaDoc p) {
37       config = p;
38    }
39
40    /**
41     * Returns Transport implementation to be used.
42     * Transport is cached.
43     * Transport is dynamically loaded based on property
44     * org.uddi4j.transport.TransportClassName set as
45     * either a system property or in passed properties object.
46     * If this property is not set, the default transport
47     * is loaded.
48     *
49     * @return Transport
50     * @exception TransportException
51     * Thrown if transport class cannot be loaded.
52     */

53   public Transport getTransport() throws TransportException {
54
55      if (transport==null) {
56         transportClassName = config.getProperty(PROPERTY_NAME, DEFAULT_TRANSPORT_NAME);
57         // Load and return the class
58
try {
59            transport = (Transport)Class.forName(transportClassName).newInstance();
60            if ("true".equals(config.getProperty("org.uddi4j.logEnabled"))) {
61               System.err.println("TransportFactory: Using transport name:" + transportClassName);
62            }
63         } catch (Exception JavaDoc e) {
64            throw new TransportException(e);
65         }
66      }
67      return transport;
68    }
69
70    /**
71     * Create a TransportFactory.
72     *
73     * @return TransportFactory
74     */

75    static public TransportFactory newInstance() {
76       return new TransportFactory(System.getProperties());
77    }
78
79    /**
80     * Create a TransportFactory passing in configuration information
81     * in a properties object.
82     *
83     * @param p Properties
84     * @return TransportFactory
85     * @see org.uddi4j.client.UDDIProxy#UDDIProxy(Properties) UDDIProxy(Properties) constructor for information on configuration object.
86     */

87    static public TransportFactory newInstance(Properties JavaDoc p) {
88       return new TransportFactory(p);
89    }
90 }
91
Popular Tags