1 23 package com.sun.appserv.management.util.stringifier; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 29 30 31 35 public class StringifierRegistryImpl implements StringifierRegistry 36 { 37 public static final StringifierRegistry DEFAULT = new StringifierRegistryImpl(); 38 39 private final Map <Class <?>,Stringifier> mLookup; 40 private final StringifierRegistry mNextRegistry; 41 42 45 public 46 StringifierRegistryImpl() 47 { 48 this( null ); 49 } 50 51 59 public 60 StringifierRegistryImpl( StringifierRegistry registry ) 61 { 62 mLookup = new HashMap <Class <?>,Stringifier>(); 63 mNextRegistry = registry; 64 } 65 66 public void 67 add( Class theClass, Stringifier stringifier ) 68 { 69 if ( lookup( theClass ) != null ) 70 { 71 new Exception ().printStackTrace(); 72 } 73 74 mLookup.remove( theClass ); 75 mLookup.put( theClass, stringifier ); 76 } 77 78 79 public Stringifier 80 lookup( Class 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 |