KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > components > net > SocketFactoryFactory


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.components.net;
17
18 import org.apache.axis.AxisProperties;
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.commons.logging.Log;
21
22 import java.util.Hashtable JavaDoc;
23
24 /**
25  * Class SocketFactoryFactory
26  *
27  * @author
28  * @version %I%, %G%
29  */

30 public class SocketFactoryFactory {
31
32     /** Field log */
33     protected static Log log =
34             LogFactory.getLog(SocketFactoryFactory.class.getName());
35
36     /** socket factory */
37     private static Hashtable JavaDoc factories = new Hashtable JavaDoc();
38
39     private static final Class JavaDoc classes[] = new Class JavaDoc[] { Hashtable JavaDoc.class };
40
41
42     static {
43         AxisProperties.setClassOverrideProperty(SocketFactory.class,
44                                        "axis.socketFactory");
45
46         AxisProperties.setClassDefault(SocketFactory.class,
47                                        "org.apache.axis.components.net.DefaultSocketFactory");
48
49         AxisProperties.setClassOverrideProperty(SecureSocketFactory.class,
50                                        "axis.socketSecureFactory");
51
52         AxisProperties.setClassDefault(SecureSocketFactory.class,
53                                        "org.apache.axis.components.net.JSSESocketFactory");
54     }
55     
56     /**
57      * Returns a copy of the environment's default socket factory.
58      *
59      * @param protocol Today this only supports "http" & "https".
60      * @param attributes
61      *
62      * @return
63      */

64     public static synchronized SocketFactory getFactory(String JavaDoc protocol,
65                                                         Hashtable JavaDoc attributes) {
66         SocketFactory theFactory = (SocketFactory)factories.get(protocol);
67
68         if (theFactory == null) {
69             Object JavaDoc objects[] = new Object JavaDoc[] { attributes };
70     
71             if (protocol.equalsIgnoreCase("http")) {
72                 theFactory = (SocketFactory)
73                     AxisProperties.newInstance(SocketFactory.class, classes, objects);
74             } else if (protocol.equalsIgnoreCase("https")) {
75                 theFactory = (SecureSocketFactory)
76                     AxisProperties.newInstance(SecureSocketFactory.class, classes, objects);
77             }
78             
79             if (theFactory != null) {
80                 factories.put(protocol, theFactory);
81             }
82         }
83         return theFactory;
84     }
85 }
86
Popular Tags