1 23 package com.sun.appserv.management.util.misc; 24 25 import java.lang.reflect.Constructor ; 26 import java.util.ResourceBundle ; 27 import java.util.Locale ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 32 import com.sun.appserv.management.util.misc.ClassUtil; 33 34 41 public class PackageStringSources 42 { 43 static final Map <Class ,StringSource> mSources = new HashMap <Class ,StringSource>(); 44 45 49 public static StringSource 50 get( final Class theClass, final StringSource delegate ) 51 { 52 StringSource source = mSources.get( theClass ); 53 if ( source == null ) 54 { 55 source = init( theClass, delegate ); 56 mSources.put( theClass, source ); 57 } 58 59 return( source ); 60 } 61 62 private PackageStringSources() {} 63 64 private static StringSource 65 init( final Class theClass, final StringSource delegate ) 66 { 67 StringSource source = null; 68 final String packageName = theClass.getPackage().getName(); 69 70 try 71 { 72 final String classname = packageName + ".PackageStrings"; 73 74 final Class packageStringSourceClass = ClassUtil.getClassFromName( classname ); 75 76 final Constructor c = packageStringSourceClass.getConstructor( new Class [] { StringSource.class } ); 77 78 source = (StringSource)c.newInstance( new Object [] { delegate } ); 79 } 80 catch( Exception e ) 81 { 82 e.printStackTrace(); 84 } 85 86 if ( source == null ) 87 { 88 final ResourceBundle bundle = ResourceBundle.getBundle( packageName + ".Strings", 89 Locale.getDefault(), theClass.getClassLoader()); 90 91 source = new ResourceBundleStringSource( bundle, delegate ); 92 } 93 94 return( source ); 95 } 96 }; 97 98 99 100 | Popular Tags |