1 23 package com.sun.enterprise.server.logging.diagnostics; 24 25 import java.util.Hashtable ; 26 import java.util.ResourceBundle ; 27 import java.util.Locale ; 28 29 39 public class ResourceBundleLocator { 40 private static Hashtable moduleIdToResourceBundleTable; 41 42 private static String [] jdoResourceBundles = { 43 "com.sun.jdo.spi.persistence.support.ejb.ejbc.Bundle", 44 "com.sun.jdo.spi.persistence.generator.database.Bundle", 45 "com.sun.jdo.spi.persistence.support.ejb.ejbqlc.Bundle", 46 "com.sun.jdo.spi.persistence.support.sqlstore.Bundle", 47 "com.sun.jdo.spi.persistence.utility.logging.Bundle" }; 48 49 static { 50 moduleIdToResourceBundleTable = new Hashtable ( ); 51 moduleIdToResourceBundleTable.put( "ADM", 52 "com.sun.logging.enterprise.system.tools.admin.LogStrings" ); 53 moduleIdToResourceBundleTable.put( "CONF", 54 "com.sun.logging.enterprise.system.core.config.LogStrings" ); 55 moduleIdToResourceBundleTable.put( "DPL", 56 "com.sun.logging.enterprise.system.tools.deployment.LogStrings" ); 57 moduleIdToResourceBundleTable.put( "EJB", 58 "com.sun.logging.enterprise.system.container.ejb.LogStrings" ); 59 moduleIdToResourceBundleTable.put( "IOP", 60 "com.sun.corba.ee.impl.logging.LogStrings" ); 61 moduleIdToResourceBundleTable.put( "JAXR", 62 "com.sun.logging.enterprise.system.webservices.registry.LogDomains" ); 63 moduleIdToResourceBundleTable.put( "NAM", 64 "com.sun.logging.enterprise.system.core.naming.LogStrings" ); 65 moduleIdToResourceBundleTable.put( "DTX", 66 "com.sun.logging.enterprise.resource.jta.LogStrings" ); 67 moduleIdToResourceBundleTable.put( "SYNC", 68 "com.sun.logging.ee.enterprise.system.tools.synchronization.LogStrings" ); 69 moduleIdToResourceBundleTable.put( "HADBMG", 70 "com.sun.enterprise.ee.admin.hadbmgmt.LocalStrings" ); 71 moduleIdToResourceBundleTable.put( "JAXRPC", 72 "com.sun.logging.enterprise.system.webservices.rpc.LogDomains" ); 73 moduleIdToResourceBundleTable.put( "JML", 74 "com.sun.logging.enterprise.resource.javamail.LogStrings"); 75 moduleIdToResourceBundleTable.put( "JMS", 76 "com.sun.logging.enterprise.resource.jms.LogStrings"); 77 moduleIdToResourceBundleTable.put( "JTS", 78 "com.sun.logging.enterprise.system.core.transaction.LogStrings"); 79 moduleIdToResourceBundleTable.put( "LDR", 80 "com.sun.logging.enterprise.system.core.classloading.LogStrings"); 81 moduleIdToResourceBundleTable.put( "MDB", 82 "com.sun.logging.enterprise.system.container.ejb.mdb.LogStrings" ); 83 moduleIdToResourceBundleTable.put( "JNDI", 84 "com.sun.logging.enterprise.system.core.naming.LogStrings" ); 85 moduleIdToResourceBundleTable.put( "RAR", 86 "com.sun.logging.enterprise.resource.resourceadapter.LogStrings" ); 87 moduleIdToResourceBundleTable.put( "SAAJ", 88 "com.sun.logging.enterprise.system.webservices.saaj.LogDomains" ); 89 moduleIdToResourceBundleTable.put( "SEC", 90 "com.sun.logging.enterprise.system.core.security.LogStrings" ); 91 moduleIdToResourceBundleTable.put( "SERVER", 92 "com.sun.logging.enterprise.system.LogStrings"); 93 moduleIdToResourceBundleTable.put( "TLS", 94 "com.sun.logging.enterprise.system.tools.LogStrings"); 95 moduleIdToResourceBundleTable.put( "UTIL", 96 "com.sun.logging.enterprise.system.util.LogStrings" ); 97 moduleIdToResourceBundleTable.put( "VRFY", 98 "com.sun.logging.enterprise.system.tools.verifier.LogStrings"); 99 moduleIdToResourceBundleTable.put( "WEB", 100 "com.sun.logging.enterprise.system.container.web.LogStrings"); 101 moduleIdToResourceBundleTable.put( "PWC", 102 "com.sun.enterprise.web.logging.pwc.LogStrings"); 103 moduleIdToResourceBundleTable.put( "CMNUTL", 104 "com.sun.common.util.logging.LogStrings"); 105 moduleIdToResourceBundleTable.put( "TEST", 106 "com.sun.enterprise.server.logging.diagnostics.LogStrings" ); 107 } 108 109 112 public static ResourceBundle getResourceBundleForMessageId( String messageId ) { 113 String moduleId = getModuleId( messageId ); 114 if( moduleId == null ) { return null; } 115 ResourceBundle rb = null; 116 if( moduleId.equals( Constants.JDO_MESSAGE_PREFIX ) ) { 117 rb = getResourceBundleForJDOMessageId( messageId ); 119 } else { 120 rb = getResourceBundleForModuleId( moduleId ); 121 } 122 return rb; 123 } 124 125 126 132 public static ResourceBundle getResourceBundleForModuleId( String moduleId ) { 133 if( moduleId == null ) { return null; } 134 String bundleName = null; 135 try { 136 bundleName = (String )moduleIdToResourceBundleTable.get( moduleId ); 137 if( bundleName == null ) return null; 138 return ResourceBundle.getBundle(bundleName, 139 Locale.getDefault(), getClassLoader( ) ); 140 } catch( Exception e) { 141 System.err.println( e ); 142 e.printStackTrace( ); 143 } 144 return null; 145 } 146 147 148 153 public static ResourceBundle getResourceBundleForJDOMessageId( 154 String messageId ) 155 { 156 for( int i = 0; i < jdoResourceBundles.length; i++ ) { 157 ResourceBundle rb = ResourceBundle.getBundle(jdoResourceBundles[i], 158 Locale.getDefault(), getClassLoader( ) ); 159 if( rb != null ) { 160 try { 161 if( rb.getString( 162 messageId + Constants.CAUSE_PREFIX + 1 ) != null ) 163 { 164 return rb; 167 } 168 } catch( java.util.MissingResourceException e ) { 169 } 173 } 174 } 175 return null; 176 } 177 178 private static ClassLoader getClassLoader( ) { 179 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 182 if (cl == null) { 183 cl = ClassLoader.getSystemClassLoader(); 184 } 185 return cl; 186 } 187 188 191 public static String getModuleId( String messageId ) { 192 if( (messageId == null ) 193 ||(messageId.length() == 0 ) ) 194 { 195 return null; 196 } 197 int lastIndex = 6; 198 if( messageId.length() < lastIndex ) { lastIndex = messageId.length();} 199 200 char[] moduleIdCharacters = 201 messageId.substring(0,lastIndex).toCharArray( ); 202 lastIndex = moduleIdCharacters.length; 203 if( Character.isDigit(moduleIdCharacters[moduleIdCharacters.length-1]) ) 206 { 207 for( int index = (moduleIdCharacters.length-1); index > 0; 208 index-- ) 209 { 210 if( !Character.isDigit(moduleIdCharacters[index]) ) { 211 lastIndex = index + 1; 212 break; 213 } 214 } 215 } 216 return messageId.substring( 0, lastIndex ); 217 } 218 } 219 | Popular Tags |