KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > naming > interceptors > ENCManager


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@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  * --------------------------------------------------------------------------
22  * $Id: ENCManager.java 399 2006-04-24 16:38:14Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.naming.interceptors;
27
28 import org.objectweb.easybeans.log.JLog;
29 import org.objectweb.easybeans.log.JLogFactory;
30
31 /**
32  * Detects the server type and return the correct interceptor to use depending of the application server.
33  * It could be EasyBeans, JOnAS or Tomcat.
34  * @author Florent Benoit
35  */

36 public final class ENCManager {
37
38     /**
39      * Logger.
40      */

41     private static JLog logger = JLogFactory.getLog(ENCManager.class);
42
43     /**
44      * Class used for the interceptor.
45      */

46     private static Class JavaDoc encInterceptor = null;
47
48     /**
49      * No public constructor (utility class).
50      */

51     private ENCManager() {
52
53     }
54
55     /**
56      * @return the class to use depending of the application server.
57      */

58     public static Class JavaDoc getInterceptorClass() {
59         if (encInterceptor == null) {
60             ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
61
62             // try to load JOnAS class.
63
try {
64                 loader.loadClass(JOnASENCInterceptor.JONAS_NAMING_MANAGER_CLASS);
65                 encInterceptor = JOnASENCInterceptor.class;
66                 logger.info("Detecting JOnAS : using JOnAS ENC for the naming.");
67             } catch (ClassNotFoundException JavaDoc e) {
68                 // not found, try with Tomcat
69
try {
70                     loader.loadClass(TomcatENCInterceptor.TOMCAT_NAMING_CLASS);
71                     encInterceptor = TomcatENCInterceptor.class;
72                     logger.info("Detecting Tomcat : using Tomcat ENC for the naming.");
73                 } catch (ClassNotFoundException JavaDoc e1) {
74                     // Not found, use EZB.
75
encInterceptor = EZBENCInterceptor.class;
76                     logger.debug("Using EasyBeans ENC for the naming.");
77                 }
78             }
79
80         }
81         return encInterceptor;
82     }
83 }
84
Popular Tags