1 23 package com.sun.enterprise.server.logging.diagnostics; 24 25 import java.util.ArrayList ; 26 import java.util.ResourceBundle ; 27 import java.util.MissingResourceException ; 28 29 35 public class MessageIdCatalog{ 36 private static final MessageIdCatalog instance = 37 new MessageIdCatalog( ); 38 39 public static MessageIdCatalog getInstance( ) { 40 return instance; 41 } 42 43 48 public ArrayList getDiagnosticCausesForMessageId( String messageId ) { 49 ResourceBundle rb = 50 ResourceBundleLocator.getResourceBundleForMessageId( messageId ); 51 String cause = null; 52 ArrayList causes = null; 53 if( rb != null ) { 54 for( int i = 1; i < Constants.MAX_CAUSES_AND_CHECKS; i++ ) { 55 try { 60 cause = rb.getString( messageId + 61 Constants.CAUSE_PREFIX + i ); 62 } catch( MissingResourceException e ) { 63 break; 67 } 68 if( cause == null ) { break; } 69 if( causes == null ) { 70 causes = new ArrayList ( ); 71 } 72 causes.add( cause ); 73 } 74 } 75 return causes; 76 } 77 78 83 public ArrayList getDiagnosticChecksForMessageId( String messageId ) { 84 ResourceBundle rb = 85 ResourceBundleLocator.getResourceBundleForMessageId( messageId ); 86 String check = null; 87 ArrayList checks = null; 88 if( rb != null ) { 89 for( int i = 1; i < Constants.MAX_CAUSES_AND_CHECKS; i++ ) { 90 try { 95 check = rb.getString( messageId + 96 Constants.CHECK_PREFIX + i ); 97 } catch( MissingResourceException e ) { 98 break; 102 } 103 if( check == null ) break; 104 if( checks == null ) { 105 checks = new ArrayList ( ); 106 } 107 checks.add( check ); 108 } 109 } 110 return checks; 111 } 112 113 121 public String getDiagnosticURIForMessageId( String messageId ) { 122 String moduleId = ResourceBundleLocator.getModuleId( messageId ); 123 if( moduleId == null ) { return null; } 124 return Constants.URI_PREFIX + moduleId + "/" + messageId; 125 } 126 127 public Diagnostics getDiagnosticsForMessageId( String messageId ) { 128 ArrayList causes = getDiagnosticCausesForMessageId( messageId ); 129 ArrayList checks = getDiagnosticChecksForMessageId( messageId ); 130 if( ( causes == null ) 131 &&( checks == null ) ) { 132 return null; 133 } 134 Diagnostics diagnostics = new Diagnostics( messageId ); 135 diagnostics.setPossibleCauses( causes ); 136 diagnostics.setDiagnosticChecks( checks ); 137 diagnostics.setURI( getDiagnosticURIForMessageId( messageId ) ); 138 return diagnostics; 139 } 140 } 141 142 | Popular Tags |