KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > util > stringifier > StringifierRegistry


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-cli/cli-api/src/java/com/sun/cli/util/stringifier/StringifierRegistry.java,v 1.3 2005/12/25 03:46:09 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:46:09 $
28  */

29  
30 package com.sun.cli.util.stringifier;
31
32 import java.util.HashMap JavaDoc;
33 import java.util.Iterator JavaDoc;
34
35 import javax.management.*;
36
37 /*
38     Holds a lookup table for Stringifiers. Certain Stringifier classes
39     may use this registry to aid them in producing suitable output.
40  */

41 public class StringifierRegistry
42 {
43     public static StringifierRegistry DEFAULT = new StringifierRegistry();
44     
45     private final HashMap JavaDoc mLookup;
46     private final StringifierRegistry mNextRegistry;
47     
48     /*
49         Create a new registry. Use the DEFAULT registry if possible;
50         certain Stringifier classes depend on it.
51      */

52         public
53     StringifierRegistry( )
54     {
55         this( null );
56     }
57     
58         public
59     StringifierRegistry( StringifierRegistry registry )
60     {
61         mLookup = new HashMap JavaDoc( );
62         mNextRegistry = registry;
63     }
64     
65     /*
66         Add a mapping from a Class to a Stringifier
67         
68         @param theClass the Class to which the Stringifier should be associated
69         @param stringifier the Stringifier for the class
70      */

71         public void
72     add( Class JavaDoc theClass, Stringifier stringifier )
73     {
74         mLookup.remove( theClass );
75         mLookup.put( theClass, stringifier );
76     }
77     
78     
79     /*
80         Lookup a Stringifier from a Class.
81         
82         @param theClass the Class
83         @returns the Stringifier, or null if not found
84      */

85         public Stringifier
86     lookup( Class JavaDoc theClass )
87     {
88         Stringifier stringifier = (Stringifier)mLookup.get( theClass );
89         
90         if ( stringifier == null && mNextRegistry != null )
91         {
92         System.out.println( "can't find " + theClass.getName() );
93             stringifier = mNextRegistry.lookup( theClass );
94         }
95         
96         return( stringifier );
97     }
98 }
99
100
101
102
Popular Tags