KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > stringifier > StringifierRegistryImpl


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.util.stringifier;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29
30
31 /**
32     Holds a lookup table for Stringifiers. Certain Stringifier classes
33     may use this registry to aid them in producing suitable output.
34  */

35 public class StringifierRegistryImpl implements StringifierRegistry
36 {
37     public static final StringifierRegistry DEFAULT = new StringifierRegistryImpl();
38     
39     private final Map JavaDoc<Class JavaDoc<?>,Stringifier> mLookup;
40     private final StringifierRegistry mNextRegistry;
41     
42     /**
43         Create a new registry with no next registry.
44      */

45         public
46     StringifierRegistryImpl()
47     {
48         this( null );
49     }
50     
51     /**
52         Create a new registry which is chained to an existing registry.
53         
54         When lookup() is called, if it cannot be found in this registry, then
55         the chainee is used.
56         
57         @param registry the registry to use if this registry fails to find a Stringifier
58      */

59         public
60     StringifierRegistryImpl( StringifierRegistry registry )
61     {
62         mLookup = new HashMap JavaDoc<Class JavaDoc<?>,Stringifier>();
63         mNextRegistry = registry;
64     }
65     
66         public void
67     add( Class JavaDoc theClass, Stringifier stringifier )
68     {
69         if ( lookup( theClass ) != null )
70         {
71             new Exception JavaDoc().printStackTrace();
72         }
73         
74         mLookup.remove( theClass );
75         mLookup.put( theClass, stringifier );
76     }
77     
78     
79         public Stringifier
80     lookup( Class JavaDoc theClass )
81     {
82         Stringifier stringifier = (Stringifier)mLookup.get( theClass );
83         
84         if ( stringifier == null && mNextRegistry != null )
85         {
86             stringifier = mNextRegistry.lookup( theClass );
87         }
88         
89         return( stringifier );
90     }
91 }
92
93
94
95
Popular Tags