1 package org.ashkelon.pages; 2 3 import java.util.*; 4 import java.io.*; 5 import java.net.*; 6 7 import org.exolab.castor.mapping.*; 8 import org.exolab.castor.xml.*; 9 import org.ashkelon.*; 10 11 14 public class ConfigInfo 15 { 16 private Collection commandList; 17 private String defaultCmd; 18 private String defaultPkg; 19 private Map commandMap; 20 private int maxTrailLength; 21 private int traceLevel; 22 private String traceFile; 23 private String inlineTagResolver; 24 25 public ConfigInfo() {} 26 27 public ConfigInfo load() throws Exception 28 { 29 ClassLoader loader = this.getClass().getClassLoader(); 30 31 URL resource = loader.getResource("org/ashkelon/pages/configmapping.xml"); 32 Mapping mapping = new Mapping(loader); 33 mapping.loadMapping(resource); 34 35 InputStream is = loader.getResourceAsStream("org/ashkelon/pages/configinfo.xml"); 36 Reader reader = new InputStreamReader(is); 37 Unmarshaller ums = new Unmarshaller(ConfigInfo.class); 38 ums.setMapping(mapping); 39 ConfigInfo info = (ConfigInfo) ums.unmarshal(reader); 40 41 Map commandMap = new HashMap(); 42 Iterator itr = info.getCommandList().iterator(); 43 CommandInfo cmdinfo; 44 while (itr.hasNext()) 45 { 46 cmdinfo = (CommandInfo) itr.next(); 47 commandMap.put(cmdinfo.getCommand(), cmdinfo); 48 } 49 info.setCommandMap(commandMap); 50 return info; 51 } 52 53 public String getDefaultCmd() 54 { 55 return defaultCmd; 56 } 57 public void setDefaultCmd(String defaultCmd) 58 { 59 this.defaultCmd = defaultCmd; 60 } 61 62 public String getDefaultPkg() 63 { 64 return defaultPkg; 65 } 66 public void setDefaultPkg(String defaultPkg) 67 { 68 this.defaultPkg = defaultPkg; 69 } 70 71 public Collection getCommandList() 72 { 73 return commandList; 74 } 75 public void setCommandList(Collection commandList) 76 { 77 this.commandList = commandList; 78 } 79 80 public Map getCommandMap() 81 { 82 return commandMap; 83 } 84 public void setCommandMap(Map commandMap) 85 { 86 this.commandMap = commandMap; 87 } 88 89 public int getMaxTrailLength() { return maxTrailLength; } 90 public void setMaxTrailLength(int length) { this.maxTrailLength = length; } 91 92 public int getTraceLevel() { return traceLevel; } 93 public void setTraceLevel(int traceLevel) { this.traceLevel = traceLevel; } 94 95 public String getTraceFile() { return traceFile; } 96 public void setTraceFile(String traceFile) { this.traceFile = traceFile; } 97 98 public String getInlineTagResolver() { return inlineTagResolver; } 99 public void setInlineTagResolver(String resolver) { inlineTagResolver = resolver; } 100 101 private static InlineTagResolver _resolver = null; 102 private static ConfigInfo _cInfo = null; 103 public static InlineTagResolver getResolver() 104 { 105 if (_resolver == null) 106 { 107 try 108 { 109 _cInfo = new ConfigInfo().load(); 110 } 111 catch (Exception ex) 112 { 113 System.err.println("Failed to load config info"); 114 System.err.println(ex.getMessage()); 115 System.exit(0); 116 } 117 118 try 119 { 120 Class resolverClass = Class.forName(_cInfo.getInlineTagResolver()); 121 _resolver = (InlineTagResolver) resolverClass.newInstance(); 122 } 123 catch (ClassNotFoundException ex) 124 { 125 System.err.println("Failed to instantiate inline tag resolver class"); 126 System.err.println("ClassNotFoundException: " + ex.getMessage()); 127 System.exit(0); 128 } 129 catch (IllegalAccessException ex) 130 { 131 System.err.println("Failed to instantiate inline tag resolver class"); 132 System.err.println("IllegalAccessException: " + ex.getMessage()); 133 System.exit(0); 134 } 135 catch (InstantiationException ex) 136 { 137 System.err.println("Failed to instantiate inline tag resolver class"); 138 System.err.println("InstantiationException: " + ex.getMessage()); 139 System.exit(0); 140 } 141 } 142 return _resolver; 143 } 144 145 public static void main(String args[]) throws Exception 146 { 147 (new ConfigInfo()).load(); 148 } 149 } 150 151 | Popular Tags |