1 21 22 package org.opensubsystems.core.util; 23 24 import java.util.logging.Logger ; 25 26 34 public final class J2EEUtils 35 { 36 38 41 public static final int J2EE_SERVER_UNINITIALIZED = -1; 42 43 46 public static final int J2EE_SERVER_NO = 0; 47 48 51 public static final int J2EE_SERVER_JONAS = 1; 52 53 56 public static final int J2EE_SERVER_JBOSS = 2; 57 58 61 public static final int J2EE_SERVER_WEBLOGIC = 3; 62 63 66 public static final int J2EE_SERVER_WEBSPHERE = 4; 67 68 76 public static final String JONAS_IDENTIFIER = ".objectweb.jonas"; 77 78 83 public static final String JBOSS_IDENTIFIER = ".jboss."; 84 85 90 public static final String WEBLOGIC_IDENTIFIER = "weblogic."; 91 92 97 public static final String WEBSPHERE_IDENTIFIER = ".ibm.ws."; 98 99 101 104 private static Logger s_logger = Log.getInstance(J2EEUtils.class); 105 106 110 protected static int s_iDetectedServer = J2EE_SERVER_UNINITIALIZED; 111 112 114 117 private J2EEUtils( 118 ) 119 { 120 } 122 123 125 132 public static int getJ2EEServerType( 133 ) 134 { 135 if (s_iDetectedServer == J2EE_SERVER_UNINITIALIZED) 138 { 139 int iRetValue = J2EE_SERVER_NO; 140 String strClassLoader; 141 142 strClassLoader = J2EEUtils.class.getClassLoader().getClass().getName(); 143 iRetValue = detectJ2EEServerType(strClassLoader); 144 if (iRetValue == J2EE_SERVER_NO) 145 { 146 strClassLoader = J2EEUtils.class.getClassLoader().getParent().getClass().getName(); 147 iRetValue = detectJ2EEServerType(strClassLoader); 148 } 149 150 s_iDetectedServer = iRetValue; 151 } 152 153 154 return s_iDetectedServer; 155 } 156 157 159 166 protected static int detectJ2EEServerType( 167 String strIdentifier 168 ) 169 { 170 int iRetValue = J2EE_SERVER_NO; 171 172 if (strIdentifier != null) 173 { 174 s_logger.finest("Trying to detect J2EE application server using identifier " 175 + strIdentifier); 176 if (strIdentifier.indexOf(JONAS_IDENTIFIER) > -1) 177 { 178 s_logger.fine("JOnAS application server detected."); 179 iRetValue = J2EE_SERVER_JONAS; 180 } 181 else if (strIdentifier.indexOf(JBOSS_IDENTIFIER) > -1) 182 { 183 s_logger.fine("JBoss application server detected."); 184 iRetValue = J2EE_SERVER_JBOSS; 185 } 186 else if (strIdentifier.indexOf(WEBLOGIC_IDENTIFIER) > -1) 187 { 188 s_logger.fine("Weblogic application server detected."); 189 iRetValue = J2EE_SERVER_WEBLOGIC; 190 } 191 else if (strIdentifier.indexOf(WEBSPHERE_IDENTIFIER) > -1) 192 { 193 s_logger.fine("Websphere application server detected."); 194 iRetValue = J2EE_SERVER_WEBSPHERE; 195 } 196 } 197 else 198 { 199 s_logger.finest("No J2EE application server detected since identifier" + 200 " is null."); 201 } 202 203 return iRetValue; 204 } 205 } 206 | Popular Tags |