1 23 24 28 29 package com.sun.enterprise.admin.verifier; 30 31 import java.util.*; 32 import java.io.*; 33 34 import java.io.File ; 35 36 import com.sun.enterprise.util.LocalStringManager; 37 import com.sun.enterprise.util.LocalStringManagerImpl; 38 import com.sun.enterprise.tools.verifier.StringManagerHelper; 39 import com.sun.enterprise.config.ConfigBeansFactory; 43 import com.sun.enterprise.config.ConfigFactory; 44 import com.sun.enterprise.config.ConfigContext; 45 import com.sun.enterprise.config.ConfigException; 46 47 import java.util.logging.Logger ; 49 import java.util.logging.Level ; 50 import com.sun.logging.LogDomains; 51 52 53 55 56 public class ServerXMLVerifier { 57 58 static Logger _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER); 60 61 public boolean debug = false; 62 public String outputFileStr = null; 63 public final static int FAIL = 0; 64 public final static int WARN = 1; 65 public final static int ALL = 2; 66 67 private static int reportLevel = ALL; 68 69 72 public String xmlFileName; 73 public ConfigContext configContext = null; 74 75 public com.sun.enterprise.util.LocalStringManagerImpl smh; 76 public static ServerMgr serverMgr; 77 78 public ServerXMLVerifier() { 79 try { 80 StringManagerHelper.setLocalStringsManager(Class.forName(getClass().getName())); 83 smh = StringManagerHelper.getLocalStringsManager(); 84 } 85 catch (ClassNotFoundException e) { 86 _logger.log(Level.FINE, "serverxmlverifier.error_getting_localstringsmanager", e); 88 } 89 init(); 90 } 91 92 102 103 137 138 140 141 public void init() { 142 File testNames = new File ("lib/TestNamesMBean.xml"); 143 if(testNames.exists()) 144 _logger.log(Level.INFO, "serverxmlverifier.looking_file", testNames.getAbsolutePath()); 146 } 147 148 151 152 public static void main(String args[]) { 153 ServerXMLVerifier serverVerifier = new ServerXMLVerifier(); 154 serverVerifier.parseArgs(args); 155 } 156 157 protected void parseArgs(String args[]) { 158 if (args.length < 1) 159 usage(); 160 else { 161 for (int i = 0; i < args.length; i++) { 163 String arg = args[i]; 164 if (arg.startsWith("-")) { 165 try { 166 switch (arg.charAt(1)) { 167 case 'v': debug = true; 169 debug(smh.getLocalString(getClass().getName() + ".verboseFlag", 170 "Setting verbose flag to TRUE.")); 171 break; 172 case 'h': debug 174 (smh.getLocalString(getClass().getName() + ".helpMessage", 175 "Displaying help message.")); 176 usage(); 177 break; 178 case 'o': debug 180 (smh.getLocalString(getClass().getName() + ".outputFileName", 181 "Retrieving results output filename.")); 182 char vhstr[] = new char[arg.length()-2]; 183 arg.getChars(2, arg.length(), vhstr, 0); 184 outputFileStr = new String (vhstr); 185 debug("Using this output file = " + outputFileStr); 186 ServerMgr.setFile(outputFileStr); 187 break; 189 default: 190 usage(); 191 } 192 } catch (StringIndexOutOfBoundsException e) { 193 debug(e); 194 usage(); 195 } 196 } 197 else 198 { 199 if (xmlFileName == null){ 200 xmlFileName = (new File (arg)).getAbsolutePath(); 201 debug(smh.getLocalString(getClass().getName() + ".xmlFileName", 202 "XML filename: {0}", 203 new Object [] 204 {xmlFileName})); 205 } else { 206 debug(smh.getLocalString(getClass().getName() + "invalidArg", 207 "invalid argument \"{0}\"", 208 new Object [] 209 {arg})); 210 usage(); 211 return; 212 } 213 } 214 } 215 if(xmlFileName == null ){ 216 usage(); 217 return; 218 } 219 } 221 } 222 223 226 public void usage() { 227 System.err.println 228 ("\n" + 229 (smh.getLocalString(getClass().getName() + ".usageLine1", 230 "usage: server-verifier [optional_params] <server-xml-filename>")) 231 + "\n\n" + 232 (smh.getLocalString(getClass().getName() + ".usageLine2", 233 "where :")) 234 + "\n\n" + 235 (smh.getLocalString(getClass().getName() + ".usageLine3", 236 " [optional_params]: Must be: ")) 237 + "\n\n" + 238 (smh.getLocalString(getClass().getName() + ".usageLine4", 239 " -v : verbose debug turned on ")) 240 + "\n\n" + 241 (smh.getLocalString(getClass().getName() + ".usageLine5", 242 " -o<output file> : test results written to this file (.xml file preferred)")) 243 + "\n" + 244 (smh.getLocalString(getClass().getName() + ".usageLine6", 245 " (Overrides default file - Results.xml)")) 246 + "\n" + 247 (smh.getLocalString(getClass().getName() + ".usageLine6a", 248 " which is created in system defined <tmp> directory")) 249 + "\n" + 250 (smh.getLocalString(getClass().getName() + ".usageLine17", 251 "<server-xml-filename>: Jar file to perform static verification on ")) 252 + "\n\n" ); 253 } 254 255 256 public void debug(String s) { 257 if(debug) 258 _logger.log(Level.INFO, s); 260 } 261 262 public void debug(Exception e) { 263 if(debug) 264 _logger.log(Level.INFO, "serverxmlverifier.error_check", e); 266 } 267 } 268 | Popular Tags |