KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > logging > diagnostics > MessageIdCatalog


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.server.logging.diagnostics;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import java.util.MissingResourceException JavaDoc;
28
29 /**
30  * Simple catalog class to locate Diagnostic Information based on
31  * message id as the key.
32  *
33  * @author Hemanth Puttaswamy
34  */

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      /**
44       * Get all the documented DiagnosticCauses for a given message id.
45       * The results will be localized based on the current locale of
46       * the AppServer's JVM.
47       */

48      public ArrayList JavaDoc getDiagnosticCausesForMessageId( String JavaDoc messageId ) {
49          ResourceBundle JavaDoc rb =
50              ResourceBundleLocator.getResourceBundleForMessageId( messageId );
51          String JavaDoc cause = null;
52          ArrayList JavaDoc causes = null;
53          if( rb != null ) {
54              for( int i = 1; i < Constants.MAX_CAUSES_AND_CHECKS; i++ ) {
55                  // The convention used to document diagnostic causes in
56
// resource bundle is
57
// <MsgId>.diag.cause.1= <Cause 1>
58
// <MsgId>.diag.cause.2= <Cause 2> ....
59
try {
60                      cause = rb.getString( messageId +
61                              Constants.CAUSE_PREFIX + i );
62                  } catch( MissingResourceException JavaDoc e ) {
63                      // We couldn't find any causes listed for the message
64
// id or we have found all. In either case we are
65
// covered here.
66
break;
67                  }
68                  if( cause == null ) { break; }
69                  if( causes == null ) {
70                          causes = new ArrayList JavaDoc( );
71                  }
72                  causes.add( cause );
73              }
74         }
75         return causes;
76      }
77
78      /**
79       * Get all the documented DiagnosticChecks for a given message id.
80       * The results will be localized based on the current locale of
81       * the AppServer's JVM.
82       */

83      public ArrayList JavaDoc getDiagnosticChecksForMessageId( String JavaDoc messageId ) {
84          ResourceBundle JavaDoc rb =
85              ResourceBundleLocator.getResourceBundleForMessageId( messageId );
86          String JavaDoc check = null;
87          ArrayList JavaDoc checks = null;
88          if( rb != null ) {
89              for( int i = 1; i < Constants.MAX_CAUSES_AND_CHECKS; i++ ) {
90                  // The convention used to document diagnostic checks in
91
// resource bundle is
92
// <MsgId>.diag.check.1= <Check 1>
93
// <MsgId>.diag.check.2= <Check 2> ....
94
try {
95                          check = rb.getString( messageId +
96                                  Constants.CHECK_PREFIX + i );
97                  } catch( MissingResourceException JavaDoc e ) {
98                      // We couldn't find any checks listed for the message
99
// id or we have found all. In either case we are
100
// covered here.
101
break;
102                  }
103                  if( check == null ) break;
104                  if( checks == null ) {
105                      checks = new ArrayList JavaDoc( );
106                  }
107                  checks.add( check );
108              }
109          }
110          return checks;
111      }
112
113      /**
114       * We may collect lot of diagnostic causes and diagnostic checks for
115       * some common message id from the field. We may document those
116       * even after the product is shipped. We are planning to generate the
117       * HTML's from the resource bundle's diagnostics and update the javadoc
118       * or knowledgebase site. This URI should help us to locate the latest
119       * and greatest diagnostic info based on the message id.
120       */

121      public String JavaDoc getDiagnosticURIForMessageId( String JavaDoc messageId ) {
122          String JavaDoc moduleId = ResourceBundleLocator.getModuleId( messageId );
123          if( moduleId == null ) { return null; }
124          return Constants.URI_PREFIX + moduleId + "/" + messageId;
125      }
126
127      public Diagnostics getDiagnosticsForMessageId( String JavaDoc messageId ) {
128          ArrayList JavaDoc causes = getDiagnosticCausesForMessageId( messageId );
129          ArrayList JavaDoc 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