KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > VerifierResultsImpl


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
24 package com.sun.enterprise.tools.verifier;
25
26 import java.lang.reflect.Method JavaDoc;
27 import java.lang.reflect.InvocationTargetException JavaDoc;
28 import com.sun.enterprise.util.LocalStringManagerImpl;
29 import java.util.logging.*;
30 import com.sun.logging.*;
31
32 /**
33  * Results of a Verifier Invocation from Backend
34  * @author
35  */

36 public class VerifierResultsImpl implements VerifierResults {
37
38   static Logger _logger=LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
39
40   private static LocalStringManagerImpl localStrings =
41         new LocalStringManagerImpl(VerifierResultsImpl.class);
42
43   private static Class JavaDoc resultsReportClass=null;
44   private static Method JavaDoc failedCountMethod=null;
45   private static Method JavaDoc errorCountMethod=null;
46   private static Method JavaDoc warningCountMethod=null;
47
48   private Object JavaDoc resultObj;
49
50   public VerifierResultsImpl(Object JavaDoc result) {
51      resultObj = result;
52   }
53
54  /** return number of failures in verification */
55  public int getFailedCount() {
56
57     init();
58     if ((failedCountMethod == null) || (resultObj == null)) {
59        return -1;
60     }
61     String JavaDoc name = resultsReportClass.getName();
62
63     try {
64         Object JavaDoc result = failedCountMethod.invoke(resultObj,null);
65         return ((Integer JavaDoc)result).intValue();
66      } catch (IllegalAccessException JavaDoc e) {
67         _logger.log(Level.SEVERE,"verification.class.access.error", new Object JavaDoc[] {name});
68      } catch (InvocationTargetException JavaDoc e) {
69         _logger.log(Level.SEVERE,"verification.method.error", new Object JavaDoc[] {"verifyEar",
70                                 e.getMessage()});
71      }
72   
73   return -1;
74  }
75
76  /** return number of warnings in verification */
77  public int getWarningCount() {
78     init();
79     if ((warningCountMethod == null) || (resultObj == null)) {
80        return -1;
81     }
82     String JavaDoc name = resultsReportClass.getName();
83
84     try {
85         Object JavaDoc result = warningCountMethod.invoke(resultObj,null);
86         return ((Integer JavaDoc)result).intValue();
87      } catch (IllegalAccessException JavaDoc e) {
88         _logger.log(Level.SEVERE,"verification.class.access.error", new Object JavaDoc[] {name});
89      } catch (InvocationTargetException JavaDoc e) {
90         _logger.log(Level.SEVERE,"verification.method.error", new Object JavaDoc[] {"verifyEar",
91                                 e.getMessage()});
92      }
93   
94   return -1;
95  }
96
97  /** return number of errors in verification */
98  public int getErrorCount() {
99     init();
100     if ((errorCountMethod == null) || (resultObj == null)) {
101        return -1;
102     }
103
104     String JavaDoc name = resultsReportClass.getName();
105
106     try {
107         Object JavaDoc result = errorCountMethod.invoke(resultObj,null);
108         return ((Integer JavaDoc)result).intValue();
109      } catch (IllegalAccessException JavaDoc e) {
110         _logger.log(Level.SEVERE,"verification.class.access.error", new Object JavaDoc[] {name});
111      } catch (InvocationTargetException JavaDoc e) {
112         _logger.log(Level.SEVERE,"verification.method.error", new Object JavaDoc[] {"verifyEar",
113                                 e.getMessage()});
114      }
115   
116   return -1;
117  }
118
119  private void init() {
120
121     if (resultsReportClass != null) {
122            return;
123     }
124     String JavaDoc name = null;
125     try {
126          name = System.getProperty("j2ee.verifier.ResultsReport",
127          "com.sun.enterprise.tools.verifier.ResultsReport");
128          resultsReportClass = Class.forName(name);
129          warningCountMethod = resultsReportClass.getDeclaredMethod("getWarningCount",null);
130          failedCountMethod = resultsReportClass.getDeclaredMethod("getFailedCount",null);
131          errorCountMethod = resultsReportClass.getDeclaredMethod("getErrorCount",null);
132
133      } catch (ClassNotFoundException JavaDoc e) {
134         _logger.log(Level.SEVERE,"verification.class.notfound", new Object JavaDoc[] {name});
135      }
136     catch (NoSuchMethodException JavaDoc e) {
137       _logger.log(Level.SEVERE,"verification.method.notfound", new Object JavaDoc[] {e.getMessage() , name});
138      }
139  }
140
141 }
142
143
Popular Tags