KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > collect > DomainXMLVerificationCollector


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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 JavaDoc;
31 import java.io.FileNotFoundException JavaDoc;
32 import java.io.File JavaDoc;
33 import java.lang.reflect.*;
34 import java.io.PrintStream JavaDoc;
35 import java.io.FileOutputStream JavaDoc;
36
37 //import com.sun.enterprise.config.serverbeans.validation.DomainXmlVerifier;
38
//import com.sun.enterprise.config.serverbeans.validation
39

40
41
42 /**
43  * Captures output of verify-domain-xml command.
44  * @author mu125243
45  */

46 public class DomainXMLVerificationCollector implements Collector {
47     private String JavaDoc xmlFile;
48     private String JavaDoc destFolder;
49     /**
50      * Creates a new instance of DomainXMLVerificationCollector
51      * @param destFolder destination folder in which outpur of verify-domain-xml
52      * command
53      */

54     public DomainXMLVerificationCollector(String JavaDoc repository,
55             String JavaDoc destFolder) {
56         this.destFolder = destFolder;
57         this.xmlFile = repository + Constants.DOMAIN_XML;
58     }
59     
60     /**
61      * Captures output
62      * @throw DiagnosticException
63      */

64     public Data capture() throws DiagnosticException {
65         if(destFolder != null) {
66             File JavaDoc destFolderObj = new File JavaDoc(destFolder);
67             String JavaDoc destFile = destFolder +
68                     Defaults.DOMAIN_XML_VERIFICATION_OUTPUT;
69             PrintStream JavaDoc out = System.out;
70
71             if(!destFolderObj.exists()) {
72                 destFolderObj.mkdirs();
73             }
74             
75             try {
76                 out = new PrintStream JavaDoc(
77                     new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(destFile)), true);
78             } catch(FileNotFoundException JavaDoc fnfe) {
79                 System.out.println(" File Not Found Exception ");
80                 //ignore as output stream is set to System.out
81
fnfe.printStackTrace();
82             }
83
84             try {
85                 String JavaDoc className = "com.sun.enterprise.config.serverbeans.validation.DomainXmlVerifier";
86                 Class JavaDoc classObj = Class.forName(className);
87                 
88                 Constructor[] constructors = classObj.getDeclaredConstructors();
89                 constructors = classObj.getConstructors();
90                 Constructor constructor =
91                         classObj.getConstructor(
92                         new Class JavaDoc[]{String JavaDoc.class, PrintStream JavaDoc.class});
93                         
94                 Object JavaDoc obj = constructor.newInstance(new Object JavaDoc[]{xmlFile,out});
95                 Method method = classObj.getMethod("invokeConfigValidator",(java.lang.Class JavaDoc[]) null);
96                 method.invoke(obj, (java.lang.Object JavaDoc[] ) null);
97                 return new FileData(new File JavaDoc(destFile).getName(),
98                         DataType.DOMAIN_VALIDATION_DETAILS);
99               
100             } catch (Exception JavaDoc ce) {
101                 Throwable JavaDoc cause = ce.getCause();
102                 while(cause!=null && !(cause instanceof org.xml.sax.SAXParseException JavaDoc))
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