1 package org.catacomb.druid.load; 2 3 4 import java.io.File; 5 6 import org.catacomb.interlish.report.Logger; 7 import org.catacomb.interlish.report.PrintLogger; 8 import org.catacomb.interlish.service.AppPersist; 9 import org.catacomb.interlish.service.AppPersistProvider; 10 import org.catacomb.report.E; 11 12 13 public final class DruidAppBase implements AppPersistProvider { 14 15 static DruidAppBase instance; 16 17 18 String applicationName; 19 Logger logger; 20 Settings settings; 21 22 23 static String defaultApplicationName = "druid-application"; 24 25 26 27 public static void init() { 28 init(null, null); 29 } 30 31 32 public static void init(String s, Object projroot) { 33 String apn = null; 34 if (s == null || s.length() == 0) { 35 apn = defaultApplicationName; 36 } else { 37 apn = s; 38 } 39 40 if (instance == null) { 41 instance = new DruidAppBase(apn); 42 AppPersist.setProvider(instance); 43 44 DruidContentLoader.initLoader(projroot); 45 46 47 48 } else { 49 E.debugError("Sys.init called when it has already been initialized"); 50 } 51 52 53 54 } 55 56 57 58 public DruidAppBase(String ap) { 59 applicationName = ap; 60 61 } 62 63 64 65 public static DruidAppBase getSys() { 66 if (instance == null) { 67 init(); 68 } 69 return instance; 70 } 71 72 73 74 75 76 public String getApplicationName() { 77 return applicationName; 78 } 79 80 81 public Settings getSettings() { 82 if (settings == null) { 83 settings = new Settings(applicationName); 84 } 85 return settings; 86 } 87 88 89 90 91 92 93 94 public Logger getLogger() { 95 if (logger == null) { 96 logger = new PrintLogger(); 97 } 98 return logger; 99 } 100 101 102 103 public void requestExit() { 104 105 System.exit(0); 106 107 108 } 109 110 111 112 113 114 public boolean hasValueFor(String pel) { 115 return getSettings().hasElement(pel); 116 } 117 118 public boolean hasValue(String pel, String val) { 119 return getSettings().hasElement(pel, val); 120 } 121 122 public String getValueFor(String pel) { 123 return getSettings().getValue(pel); 124 } 125 126 public void addRecentFile(File f) { 127 getSettings().addRecentFile(f); 128 } 129 130 public void setValue(String lab, String val) { 131 getSettings().setElement(lab, val); 132 } 133 134 public String[] getRecentPaths() { 135 return getSettings().getRecentPaths(); 136 } 137 138 139 public void forceExit() { 140 System.exit(0); 141 } 142 143 144 }