1 16 package com.buchuki.ensmer; 17 18 import java.io.*; 19 import com.buchuki.ensmer.prevayler.*; 20 import org.prevayler.*; 21 import java.util.*; 22 23 33 public class EnsmerManager { 34 35 42 private EnsmerManager() { 43 } 44 45 51 public InterfaceManager getInterfaceManager() { 52 return interfaceManager; 53 } 54 55 61 public AreaManager getAreaManager() { 62 return areaManager; 63 } 64 65 71 public UserManager getUserManager() { 72 return userManager; 73 } 74 75 81 public Backhoe getBackhoe() { 82 return backhoe; 83 } 84 85 91 public SelectionManager getSelectionManager() { 92 return selectionManager; 93 } 94 95 101 public SpecialAreaManager getSpecialAreaManager() { 102 return specialAreaManager; 103 } 104 105 111 public ConfigManager getConfigManager() { 112 return configManager; 113 } 114 115 121 Prevayler getPrevayler() { 122 return prevayler; 123 } 124 125 130 void closeEnsmer() { 131 try { 132 prevayler.takeSnapshot(); 133 } catch (IOException e) { 134 } 136 System.exit(0); 137 } 138 139 155 private void initEnsmerManager(Properties props) throws Exception { 156 String settingsDir = props.getProperty("settingsDir"); 157 String worldDir = props.getProperty("world", "defaultWorld"); 158 configManager = settingsDir == null ? new ConfigManager() : 159 new ConfigManager(new File(settingsDir)); 160 File world = new File(worldDir); 161 String prevalenceBase = world.isAbsolute() ? worldDir : 162 new File(configManager.getSettingsDirectory(), worldDir).getAbsolutePath(); 163 System.out.println("Settings Directory: " + configManager.getSettingsDirectory()); 164 System.out.println("World Directory: " + prevalenceBase); 165 prevayler = PrevaylerFactory.createPrevayler(new EnsmerPrevayler(), prevalenceBase); 166 interfaceManager = new InterfaceManager(); 167 selectionManager = new SelectionManager(); 168 backhoe = new Backhoe(); 169 areaManager = new AreaManager(); 170 specialAreaManager = new SpecialAreaManager(); 171 userManager = new UserManager(); 172 areaManager.loadAreas(); 173 interfaceManager.displayArea(areaManager.getCurrentArea()); 174 } 175 176 184 public static EnsmerManager instance(Properties props) { 185 if (instance == null) { 186 try { 187 instance = new EnsmerManager(); 188 instance.initEnsmerManager(props); 189 } catch (Exception e) { 190 System.err.println("There was a problem running Ensmer. Please request support, providing the following output:\n"); 191 e.printStackTrace(); 192 System.exit(1); 193 } 194 } 195 return instance; 196 } 197 205 public static EnsmerManager instance() { 206 return instance(new Properties()); 207 } 208 209 213 private InterfaceManager interfaceManager; 214 215 219 private Backhoe backhoe; 220 221 224 private AreaManager areaManager; 225 226 232 private SpecialAreaManager specialAreaManager; 233 234 238 private UserManager userManager; 239 240 244 private SelectionManager selectionManager; 245 246 250 private ConfigManager configManager; 251 252 256 private Prevayler prevayler; 257 258 263 private static EnsmerManager instance; 264 } 265 266 | Popular Tags |