KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > registry > spi > StatisticWorkaround


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
24 /* StatisticWorkaround.java
25  * $Id: StatisticWorkaround.java,v 1.3 2005/12/25 03:43:35 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:35 $
28  * Indentation Information:
29  * 0. Please (try to) preserve these settings.
30  * 1. Tabs are preferred over spaces.
31  * 2. In vi/vim -
32  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
33  * 3. In S1 Studio -
34  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
35  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = False.
36  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
37  */

38
39 package com.sun.enterprise.admin.monitor.registry.spi;
40 import javax.management.j2ee.statistics.Statistic JavaDoc;
41 import com.sun.enterprise.admin.monitor.stats.*;
42 import com.sun.enterprise.admin.common.constant.AdminConstants;
43 import java.util.logging.Logger JavaDoc;
44
45 /** This class is a workaround for returning the statistic descriptions. Please see bug 5045413.
46     This is a best case effort and in general not expected to be accurate.
47     We should revisit this in AS 8.2.
48     @since AS 8.1
49     @author Kedar.Mhaswade@Sun.Com
50 */

51
52 final class StatisticWorkaround {
53     private static final StatsDescriptionHelper helper = new StatsDescriptionHelper();
54     private static Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
55     static final Statistic JavaDoc[] populateDescriptions(final Statistic JavaDoc[] from) {
56         if (from == null) {
57             throw new IllegalArgumentException JavaDoc("null arg");
58         }
59         final int length = from.length;
60         final Statistic JavaDoc[] to = new Statistic JavaDoc[length];
61         for (int i = 0 ; i < length ; i++) {
62             final Statistic JavaDoc as = from[i];
63             final String JavaDoc name = as.getName();
64             final String JavaDoc desc = helper.getDescription(name);
65             if (StatsDescriptionHelper.NO_DESCRIPTION_AVAILABLE.equals(desc)) {
66                 //Localized Description was not available, do nothing
67
to[i] = from[i];
68             }
69             else {
70                             attemptSettingDescription(as, desc);
71                 to[i] = as;
72             }
73         }
74         return ( to );
75     }
76     private static void attemptSettingDescription(final Statistic JavaDoc s, final String JavaDoc nd) {
77         if (s instanceof StatisticImpl) {
78             ((StatisticImpl)s).setDescription(nd);
79             logger.finest("New Description was set: " + nd);
80         }
81         else if (s instanceof AverageRangeStatisticImpl) {
82             ((AverageRangeStatisticImpl)s).setDescription(nd);
83             logger.finest("New Description was set: " + nd);
84         }
85         else if (s instanceof MutableBoundedRangeStatisticImpl) {
86             ((MutableBoundedRangeStatisticImpl)s).setDescription(nd);
87             logger.finest("New Description was set: " + nd);
88         }
89         else if (s instanceof MutableCountStatisticImpl) {
90             ((MutableCountStatisticImpl)s).setDescription(nd);
91             logger.finest("New Description was set: " + nd);
92         }
93         else if (s instanceof MutableTimeStatisticImpl) {
94             ((MutableTimeStatisticImpl)s).setDescription(nd);
95             logger.finest("New Description was set: " + nd);
96         }
97     }
98 }
99
Popular Tags