KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > j2ee > statistics > CompositeDataStats


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 /*
25  * $Header: /cvs/glassfish/admin-core/mbeanapi/src/java/com/sun/appserv/management/j2ee/statistics/CompositeDataStats.java,v 1.4 2006/03/09 20:30:28 llc Exp $
26  * $Revision: 1.4 $
27  * $Date: 2006/03/09 20:30:28 $
28  */

29
30 package com.sun.appserv.management.j2ee.statistics;
31
32 import java.util.Set JavaDoc;
33 import java.util.Map JavaDoc;
34
35
36 import javax.management.openmbean.CompositeData JavaDoc;
37
38 import javax.management.j2ee.statistics.Stats JavaDoc;
39 import javax.management.j2ee.statistics.Statistic JavaDoc;
40
41 import com.sun.appserv.management.util.jmx.OpenMBeanUtil;
42
43 /**
44     Implementation of Stats which expects a CompositeData to contain
45     the Statistics keyed by name, with values of CompositeData.
46  */

47 public final class CompositeDataStats implements Stats JavaDoc
48 {
49     final Map JavaDoc<String JavaDoc,?> mItems;
50     
51     /**
52         Create a new CompositeDataStats using the specified CompositeData
53      */

54         public
55     CompositeDataStats( final CompositeData JavaDoc compositeData )
56     {
57         mItems = OpenMBeanUtil.compositeDataToMap( compositeData );
58     }
59     
60         public Statistic JavaDoc
61     getStatistic( String JavaDoc statisticName )
62     {
63         final CompositeData JavaDoc statData = (CompositeData JavaDoc)mItems.get( statisticName );
64         if ( statData == null && ! mItems.containsKey( statisticName ) )
65         {
66             throw new IllegalArgumentException JavaDoc( statisticName );
67         }
68         
69         return( new CompositeDataStatistic( statData ) );
70     }
71     
72         public String JavaDoc[]
73     getStatisticNames()
74     {
75         final Set JavaDoc<String JavaDoc> nameSet = mItems.keySet();
76         
77         return( (String JavaDoc[])nameSet.toArray( new String JavaDoc[ nameSet.size() ] ) );
78     }
79     
80         public Statistic JavaDoc[]
81     getStatistics()
82     {
83         final String JavaDoc[] names = getStatisticNames();
84         final Statistic JavaDoc[] statistics = new Statistic JavaDoc[ names.length ];
85         
86         for( int i = 0; i < names.length; ++i )
87         {
88             statistics[ i ] = getStatistic( names[ i ] );
89         }
90         
91         return( statistics );
92     }
93    
94 }
95
96
97
98
99
100
Popular Tags