1 23 24 29 30 package com.sun.enterprise.cli.framework; 31 32 import java.util.HashMap ; 34 import java.util.Iterator ; 35 import java.util.Vector ; 36 import java.util.Properties ; 37 38 43 public class LocalStringsManagerFactory { 44 45 private static HashMap stringManagers = new HashMap (); 46 private static String PROPERTY_FILE = "LocalStrings"; 47 private final static String FRAMEWORK_BASE_PACKAGE = LocalStringsManagerFactory.class.getPackage().getName(); 48 private static LocalStringsManager commandLocalStringsManager = null; 49 50 51 protected LocalStringsManagerFactory() 52 { 53 } 54 55 60 public static void setInstance(String packageName, 61 LocalStringsManager stringsManager) 62 { 63 stringManagers.put(packageName, stringsManager); 64 } 65 66 71 public static LocalStringsManager getLocalStringsManager( 72 String packageName, 73 String propertiesFileName) 74 throws CommandValidationException 75 { 76 LocalStringsManager stringsManager = 77 (LocalStringsManager) stringManagers.get(packageName); 78 if ((stringsManager == null) || 79 (!stringsManager.getPropertiesFile().equals(propertiesFileName))) 80 { 81 try 82 { 83 stringsManager = new LocalStringsManager(packageName, 84 propertiesFileName); 85 stringManagers.put(packageName, stringsManager); 86 } 87 catch(java.util.MissingResourceException mre) 88 { 89 throw new CommandValidationException(mre.getLocalizedMessage(), mre); 91 } 92 } 93 return stringsManager; 94 } 95 96 97 103 public static LocalStringsManager getFrameworkLocalStringsManager() 104 throws CommandValidationException 105 { 106 return getLocalStringsManager(FRAMEWORK_BASE_PACKAGE, PROPERTY_FILE); 107 } 108 109 115 public static void setCommandLocalStringsManagerProperties( 116 Iterator propertiesIter) 117 throws CommandValidationException 118 { 119 Vector localizePropertiesList = new Vector (); 120 while (propertiesIter.hasNext()) 121 { 122 Properties localizeProperties = new Properties (); 123 Properties properties = (Properties ) propertiesIter.next(); 124 String basePackage = properties.getProperty("base-package"); 125 String propertyFile = properties.getProperty("property-file-name", 126 LocalStringsManagerFactory.PROPERTY_FILE); 127 if ((basePackage != null) && (!basePackage.equals(""))) 128 { 129 CLILogger.getInstance().printDebugMessage("basePackage: " + basePackage); 130 CLILogger.getInstance().printDebugMessage("propertyFile: " + propertyFile); 131 localizeProperties.setProperty("base-package", basePackage); 132 localizeProperties.setProperty("property-file-name", propertyFile); 133 localizePropertiesList.add(localizeProperties); 134 } 135 } 136 if (localizePropertiesList.size() > 0) 137 { 138 commandLocalStringsManager = 139 new LocalStringsManager(localizePropertiesList); 140 } 141 } 142 143 148 public static LocalStringsManager getCommandLocalStringsManager() 149 throws CommandValidationException 150 { 151 if (commandLocalStringsManager == null) 152 { 153 LocalStringsManager lsm = 154 LocalStringsManagerFactory.getFrameworkLocalStringsManager(); 155 throw new CommandValidationException( 156 lsm.getString("CouldNotFindLocalStringsProperties")); 157 } 158 return commandLocalStringsManager; 159 } 160 161 } 162 | Popular Tags |