1 18 19 package org.apache.beehive.netui.tools.testrecorder.server.serverAdapter; 20 21 import org.apache.beehive.netui.tools.testrecorder.shared.Logger; 22 23 26 public class ServerAdapterUtils { 27 28 private static final Logger log = Logger.getInstance( ServerAdapterUtils.class ); 29 30 private static final String SERVER_ADAPTER_PROP = "testRecorder.serveradapter"; 31 private static final String CATALINA_HOME_PROP = "catalina.home"; 32 private static final String WL_SERVER_ADAPTER_CLASS = 33 "org.apache.beehive.netui.tools.testrecorder.server.serverAdapter.WeblogicServerAdapter"; 34 private static final String TOMCAT_SERVER_ADAPTER_CLASS = 35 "org.apache.beehive.netui.tools.testrecorder.server.serverAdapter.DefaultServerAdapter"; 36 37 private static ServerAdapter SERVER_ADAPTER = createServerAdapter(); 38 39 42 private ServerAdapterUtils() {} 43 44 48 public static final ServerAdapter getServerAdapter() { 49 return SERVER_ADAPTER; 50 } 51 52 private static ServerAdapter createServerAdapter() { 54 String 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 serverAdapterClass = Class.forName( serverAdapterClassName ); 66 serverAdapter = (ServerAdapter) serverAdapterClass.newInstance(); 67 } 68 catch ( ClassNotFoundException e ) { 69 String 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 e ) { 79 String 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 |