KickJava   Java API By Example, From Geeks To Geeks.

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


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.appserv.management.j2ee.statistics;
24
25 import java.util.Map JavaDoc;
26 import java.io.Serializable JavaDoc;
27
28 import com.sun.appserv.management.util.misc.MapUtil;
29 import com.sun.appserv.management.util.misc.ObjectUtil;
30 import com.sun.appserv.management.util.misc.TypeCast;
31
32 /**
33     Implements getXXX() based on a Map whose keys are the XXX part of the getXXX() method name.
34     Serializable so that it may be used to return a result remotely.
35     <br><b>Internal use only</b>
36  */

37 public class MapGetterInvocationHandler<T>
38     extends GetterInvocationHandler<T>
39     implements Serializable JavaDoc
40 {
41     static final long serialVersionUID = -8751876448821319456L;
42
43     private final Map JavaDoc<String JavaDoc,T> mMap;
44     
45     /**
46         Create a new instance using the Map, which is <b>not</b> copied.
47      */

48         public
49     MapGetterInvocationHandler( final Map JavaDoc<String JavaDoc,T> map )
50     {
51         mMap = map;
52     }
53     
54         protected Map JavaDoc<String JavaDoc,T>
55     getMap()
56     {
57         return( mMap );
58     }
59     
60         protected T
61     getValue( final String JavaDoc name )
62     {
63         return( mMap.get( name ) );
64     }
65
66         protected boolean
67     containsValue( String JavaDoc name )
68     {
69         return( mMap.containsKey( name ) );
70     }
71     
72         public int
73     hashCode()
74     {
75         return ObjectUtil.hashCode( mMap );
76     }
77     
78         public boolean
79     equals( final Object JavaDoc rhsIn )
80     {
81         boolean equals = false;
82         
83         if ( rhsIn instanceof MapGetterInvocationHandler )
84         {
85             final MapGetterInvocationHandler<?> rhs =
86                 MapGetterInvocationHandler.class.cast( rhsIn );
87                 
88             equals = MapUtil.mapsEqual( getMap(), rhs.getMap() );
89         }
90          
91         return( equals );
92     }
93     
94     
95         public String JavaDoc
96     toString( )
97     {
98         return( MapUtil.toString( mMap ) );
99     }
100 }
101
102
103
104
105
106
Popular Tags