KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tools > testrecorder > server > serverAdapter > ServerAdapterUtils


1 /*
2  * Copyright 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  * $Header:$
17  */

18
19 package org.apache.beehive.netui.tools.testrecorder.server.serverAdapter;
20
21 import org.apache.beehive.netui.tools.testrecorder.shared.Logger;
22
23 /**
24  * This is basically a Factory for creating a Service Adapter.
25  */

26 public class ServerAdapterUtils {
27
28     private static final Logger log = Logger.getInstance( ServerAdapterUtils.class );
29
30     private static final String JavaDoc SERVER_ADAPTER_PROP = "testRecorder.serveradapter";
31     private static final String JavaDoc CATALINA_HOME_PROP = "catalina.home";
32     private static final String JavaDoc WL_SERVER_ADAPTER_CLASS =
33             "org.apache.beehive.netui.tools.testrecorder.server.serverAdapter.WeblogicServerAdapter";
34     private static final String JavaDoc TOMCAT_SERVER_ADAPTER_CLASS =
35             "org.apache.beehive.netui.tools.testrecorder.server.serverAdapter.DefaultServerAdapter";
36
37     private static ServerAdapter SERVER_ADAPTER = createServerAdapter();
38
39     /**
40      * prevent the creation of the ServerAdapterUtils. This is only accessed statically.
41      */

42     private ServerAdapterUtils() {}
43
44     /**
45      * Return the current ServerAdaptor.
46      * @return
47      */

48     public static final ServerAdapter getServerAdapter() {
49         return SERVER_ADAPTER;
50     }
51
52     // this will create the ServerAdapter.
53
private static ServerAdapter createServerAdapter() {
54         String JavaDoc serverAdapterClassName = System.getProperty( SERVER_ADAPTER_PROP );
55         if ( serverAdapterClassName == null ) {
56             if ( System.getProperty( CATALINA_HOME_PROP ) != null ) {
57                 serverAdapterClassName = TOMCAT_SERVER_ADAPTER_CLASS;
58             }
59             else {
60                 serverAdapterClassName = WL_SERVER_ADAPTER_CLASS;
61             }
62         }
63         ServerAdapter serverAdapter = null;
64         try {
65             Class JavaDoc serverAdapterClass = Class.forName( serverAdapterClassName );
66             serverAdapter = (ServerAdapter) serverAdapterClass.newInstance();
67         }
68         catch ( ClassNotFoundException JavaDoc e ) {
69             String JavaDoc msg = "WARNING: Could not find ServerAdapter class( " +
70                     serverAdapterClassName + " ) exception( " + e.getMessage() + " )" +
71                     ", using " + DefaultServerAdapter.class.getName() + ".";
72             System.out.println( msg );
73             if ( log.isWarnEnabled() ) {
74                 log.warn( msg, e );
75             }
76             serverAdapter = new DefaultServerAdapter();
77         }
78         catch ( Exception JavaDoc e ) {
79             String JavaDoc msg = "WARNING: failed to instantiate ServerAdapter class( " +
80                     serverAdapterClassName + " ) exception( " + e.getMessage() + " )" +
81                     ", using " + DefaultServerAdapter.class.getName() + ".";
82             System.out.println( msg );
83             if ( log.isWarnEnabled() ) {
84                 log.warn( msg, e );
85             }
86             serverAdapter = new DefaultServerAdapter();
87         }
88         if ( log.isInfoEnabled() ) {
89             log.info( "Created server adapter of type( " +
90                     serverAdapter.getClass().getName() + " )" );
91         }
92         return serverAdapter;
93     }
94
95 }
96
Popular Tags