1 23 24 29 package com.sun.enterprise.admin.dottedname; 30 31 import java.util.HashMap ; 32 33 import com.sun.enterprise.admin.util.ClassUtil; 34 35 41 public final class DottedNameFactory 42 { 43 static final Factory sImpl = newInstance(); 44 45 public interface Factory 46 { 47 public DottedName get( final String dottedNameString ); 49 public void clear(); 50 public void add( final DottedName dn ); 51 } 52 53 54 private 55 DottedNameFactory() 56 { 57 } 59 60 public static Factory 61 newInstance() 62 { 63 return( new Impl() ); 64 } 65 66 public static Factory 67 getInstance() 68 { 69 return( sImpl ); 70 } 71 72 73 74 private static final class Impl implements Factory 75 { 76 final HashMap mMapping; 77 78 public 79 Impl() 80 { 81 mMapping = new HashMap ( 300 ); 83 } 84 85 public synchronized void 86 add( final DottedName dottedName ) 87 { 88 mMapping.put( dottedName.toString(), dottedName ); 89 } 90 91 public synchronized void 92 clear() 93 { 94 mMapping.clear(); 95 } 96 97 98 public DottedName 99 get( final String dottedNameString ) 100 { 101 DottedName dn = lookup( dottedNameString ); 102 103 if ( dn == null ) 104 { 105 dn = new DottedName( dottedNameString ); 106 add( dn ); 107 } 108 109 return( dn ); 110 } 111 112 113 synchronized DottedName 114 lookup( final String dottedNameString ) 115 { 116 final DottedName dn = (DottedName)mMapping.get( dottedNameString ); 117 118 assert( dn == null || dn.toString().equals( dottedNameString ) ); 119 120 return( dn ); 121 } 122 123 } 124 } 125 126 127 128 | Popular Tags |