KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > net > SSLImplementation


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

17
18 package org.apache.tomcat.util.net;
19
20 import java.net.Socket JavaDoc;
21 import javax.net.ssl.SSLSession;
22
23 /* SSLImplementation:
24
25    Abstract factory and base class for all SSL implementations.
26
27    @author EKR
28 */

29 abstract public class SSLImplementation {
30     private static org.apache.commons.logging.Log logger =
31         org.apache.commons.logging.LogFactory.getLog(SSLImplementation.class);
32
33     // The default implementations in our search path
34
private static final String JavaDoc PureTLSImplementationClass=
35     "org.apache.tomcat.util.net.puretls.PureTLSImplementation";
36     private static final String JavaDoc JSSEImplementationClass=
37     "org.apache.tomcat.util.net.jsse.JSSEImplementation";
38     
39     private static final String JavaDoc[] implementations=
40     {
41         PureTLSImplementationClass,
42         JSSEImplementationClass
43     };
44
45     public static SSLImplementation getInstance() throws ClassNotFoundException JavaDoc
46     {
47     for(int i=0;i<implementations.length;i++){
48         try {
49                SSLImplementation impl=
50             getInstance(implementations[i]);
51         return impl;
52         } catch (Exception JavaDoc e) {
53         if(logger.isTraceEnabled())
54             logger.trace("Error creating " + implementations[i],e);
55         }
56     }
57
58     // If we can't instantiate any of these
59
throw new ClassNotFoundException JavaDoc("Can't find any SSL implementation");
60     }
61
62     public static SSLImplementation getInstance(String JavaDoc className)
63     throws ClassNotFoundException JavaDoc
64     {
65     if(className==null) return getInstance();
66
67     try {
68         // Workaround for the J2SE 1.4.x classloading problem (under Solaris).
69
// Class.forName(..) fails without creating class using new.
70
// This is an ugly workaround.
71
if( JSSEImplementationClass.equals(className) ) {
72         return new org.apache.tomcat.util.net.jsse.JSSEImplementation();
73         }
74         Class JavaDoc clazz=Class.forName(className);
75         return (SSLImplementation)clazz.newInstance();
76     } catch (Exception JavaDoc e){
77         if(logger.isDebugEnabled())
78         logger.debug("Error loading SSL Implementation "
79                  +className, e);
80         throw new ClassNotFoundException JavaDoc("Error loading SSL Implementation "
81                       +className+ " :" +e.toString());
82     }
83     }
84
85     abstract public String JavaDoc getImplementationName();
86     abstract public ServerSocketFactory getServerSocketFactory();
87     abstract public SSLSupport getSSLSupport(Socket JavaDoc sock);
88     abstract public SSLSupport getSSLSupport(SSLSession session);
89 }
90
Popular Tags