1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.enterprise.diagnostics.Defaults; 26 import com.sun.enterprise.diagnostics.Data; 27 import com.sun.enterprise.diagnostics.Constants; 28 import com.sun.enterprise.diagnostics.DiagnosticException; 29 30 import java.io.BufferedOutputStream ; 31 import java.io.FileNotFoundException ; 32 import java.io.File ; 33 import java.lang.reflect.*; 34 import java.io.PrintStream ; 35 import java.io.FileOutputStream ; 36 37 40 41 42 46 public class DomainXMLVerificationCollector implements Collector { 47 private String xmlFile; 48 private String destFolder; 49 54 public DomainXMLVerificationCollector(String repository, 55 String destFolder) { 56 this.destFolder = destFolder; 57 this.xmlFile = repository + Constants.DOMAIN_XML; 58 } 59 60 64 public Data capture() throws DiagnosticException { 65 if(destFolder != null) { 66 File destFolderObj = new File (destFolder); 67 String destFile = destFolder + 68 Defaults.DOMAIN_XML_VERIFICATION_OUTPUT; 69 PrintStream out = System.out; 70 71 if(!destFolderObj.exists()) { 72 destFolderObj.mkdirs(); 73 } 74 75 try { 76 out = new PrintStream ( 77 new BufferedOutputStream (new FileOutputStream (destFile)), true); 78 } catch(FileNotFoundException fnfe) { 79 System.out.println(" File Not Found Exception "); 80 fnfe.printStackTrace(); 82 } 83 84 try { 85 String className = "com.sun.enterprise.config.serverbeans.validation.DomainXmlVerifier"; 86 Class classObj = Class.forName(className); 87 88 Constructor[] constructors = classObj.getDeclaredConstructors(); 89 constructors = classObj.getConstructors(); 90 Constructor constructor = 91 classObj.getConstructor( 92 new Class []{String .class, PrintStream .class}); 93 94 Object obj = constructor.newInstance(new Object []{xmlFile,out}); 95 Method method = classObj.getMethod("invokeConfigValidator",(java.lang.Class []) null); 96 method.invoke(obj, (java.lang.Object [] ) null); 97 return new FileData(new File (destFile).getName(), 98 DataType.DOMAIN_VALIDATION_DETAILS); 99 100 } catch (Exception ce) { 101 Throwable cause = ce.getCause(); 102 while(cause!=null && !(cause instanceof org.xml.sax.SAXParseException )) 103 cause = cause.getCause(); 104 if(cause!=null) 105 out.println("XML: "+cause.getMessage()); 106 else 107 ce.printStackTrace(); 108 throw new DiagnosticException(ce.getMessage()); 109 }finally { 110 out.flush(); 111 out.close(); 112 } 113 } 114 return null; 115 } 116 } 117 | Popular Tags |