1 23 24 29 30 package com.sun.enterprise.admin.dottedname; 31 32 import java.util.ResourceBundle ; 33 import java.util.Properties ; 34 import java.util.MissingResourceException ; 35 import java.text.MessageFormat ; 36 37 38 public class DottedNameStrings 39 { 40 private DottedNameStrings() {} 41 private static final ResourceStringSource mImpl = initImpl(); 42 43 private final static String PACKAGE_NAME = "com.sun.enterprise.admin.dottedname"; 44 private final static String STRINGS_FILENAME = "DottedNameStrings"; 46 private static ResourceStringSource 47 initImpl() 48 { 49 ResourceStringSource src = null; 50 51 try 52 { 53 src = new ResourceStringSource( PACKAGE_NAME, STRINGS_FILENAME ); 54 } 55 catch( MissingResourceException e) 56 { 57 DottedNameLogger.logException( e ); 58 } 59 60 return( src ); 61 } 62 63 public static String 64 getString( String key ) 65 { 66 if ( mImpl == null ) 67 { 68 return( key ); 69 } 70 71 return( mImpl.getString( key ) ); 72 } 73 74 public static String 75 getString( String key, final Object toInsert) 76 { 77 return( getString( key, new Object [] { toInsert } ) ); 78 } 79 80 public static String 81 getString( String key, final Object toInsert1, final Object toInsert2) 82 { 83 return( getString( key, new Object [] { toInsert1, toInsert2 } ) ); 84 } 85 86 public static String 87 getString( String key, final Object [] toInsert) 88 { 89 if ( mImpl == null ) 90 { 91 return( key ); 92 } 93 94 return( mImpl.getString( key, toInsert) ); 95 } 96 97 98 public final static String OBJECT_INSTANCE_NOT_FOUND_KEY = "ObjectInstanceNotFound"; 99 public final static String MALFORMED_DOTTED_NAME_KEY = "MalformedDottedName"; 100 public final static String WILDCARD_DISALLOWED_FOR_SET_KEY = "WildcardDisallowedForSet"; 101 public final static String ATTRIBUTE_NOT_FOUND_KEY = "AttributeNotFound"; 102 public final static String ILLEGAL_TO_SET_NULL_KEY = "IllegalToSetNull"; 103 public final static String ILLEGAL_CHARACTER_KEY = "IllegalCharacter"; 104 public final static String MISSING_EXPECTED_NAME_PART_KEY = "MissingExpectedNamePart"; 105 public final static String DOTTED_NAME_MUST_HAVE_ONE_PART_KEY = "DottedNameMustHaveAtLeastOnePart"; 106 public final static String NO_VALUE_NAME_SPECIFIED_KEY = "NoValueNameSpecified"; 107 108 109 } 110 111 112 class ResourceStringSource 113 { 114 private final String mPackageName; 115 private final String mPropertyFile; 116 private final ResourceBundle mResourceBundle; 117 118 public static String DEFAULT_STRING_VALUE = "Key not found"; 119 120 121 public 122 ResourceStringSource(String packageName, String propertyFile) 123 { 124 mPackageName = packageName; 125 mPropertyFile = propertyFile; 126 mResourceBundle = ResourceBundle.getBundle( packageName + "." + propertyFile); 127 } 128 129 public String getPropertiesFile() 130 { 131 return mPropertyFile; 132 } 133 134 public String getPackageName() 135 { 136 return mPackageName; 137 } 138 139 public String getString(String key) 140 { 141 return( getString( key, DEFAULT_STRING_VALUE + " (" + key + ")" ) ); 142 } 143 144 public String getString(String key, String defaultValue) 145 { 146 String value = defaultValue; 147 148 try 149 { 150 value = mResourceBundle.getString(key); 151 } 152 catch (MissingResourceException mre) 153 { 154 } 156 return value; 157 } 158 159 162 public String getString(String key, Object [] toInsert) 163 { 164 String template = getString(key); 165 String result = template; 166 167 final MessageFormat msgFormat = new MessageFormat ( template ); 168 result = msgFormat.format(toInsert); 169 170 return result; 171 } 172 } 173 | Popular Tags |