KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > ListenerClass


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.tools.verifier.tests.web;
24
25 import java.util.Enumeration JavaDoc;
26 import com.sun.enterprise.deployment.WebBundleDescriptor;
27 import com.sun.enterprise.deployment.web.AppListenerDescriptor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.tools.verifier.Verifier;
30 import com.sun.enterprise.tools.verifier.tests.*;
31 /**
32  * Super class for all Listener tests.
33  *
34  * @author Jerome Dochez
35  * @version 1.0
36  */

37 public abstract class ListenerClass extends WebTest implements WebCheck {
38     
39     /**
40      * <p>
41      * Run the verifier test against a declared individual listener class
42      * </p>
43      *
44      * @param result is used to put the test results in
45      * @param listenerClass is the individual listener class object to test
46      * @return true if the test pass
47      */

48     abstract protected boolean runIndividualListenerTest(Result result, Class JavaDoc listenerClass);
49     
50     /**
51      * Listener class must implement a no arg constructor.
52      *
53      * @param descriptor the Web deployment descriptor
54      *
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check(WebBundleDescriptor descriptor) {
58         
59         AppListenerDescriptor listener = null;
60         Enumeration JavaDoc listenerEnum;
61         Result result;
62         boolean oneFailed = false;
63         Class JavaDoc listenerClass = null;
64     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
65     
66     listenerEnum = descriptor.getAppListenerDescriptors().elements();
67     if (listenerEnum.hasMoreElements()) {
68             result = loadWarFile(descriptor);
69             while (listenerEnum.hasMoreElements()) {
70         listener = (AppListenerDescriptor)listenerEnum.nextElement();
71
72                 if (listener.getListener().equals(smh.getLocalString("JAXRPCContextListener","com.sun.xml.rpc.server.http.JAXRPCContextListener"))) {
73                 result.addGoodDetails(smh.getLocalString
74                 ("tests.componentNameConstructor",
75                  "For [ {0} ]",
76                  new Object JavaDoc[] {compName.toString()}));
77                     result.passed(smh.getLocalString (getClass().getName() + ".passed1",
78                     "Listener Class Name is [ {0} ], make sure it is available in classpath at runtime.",
79                new Object JavaDoc[] {listener.getListener()}));
80                   continue;
81                 }
82
83                 if ("".equals(listener.getListener())) {
84               result.addErrorDetails(smh.getLocalString
85                 ("tests.componentNameConstructor",
86                  "For [ {0} ]",
87                  new Object JavaDoc[] {compName.toString()}));
88                   result.failed(smh.getLocalString (getClass().getName() + ".failed",
89                     "Empty or Null String specified for Listener Class Name in [ {0} ].",
90                new Object JavaDoc[] {compName.toString()}));
91                   oneFailed = true;
92                   continue;
93                 }
94
95                 listenerClass = loadClass(result, listener.getListener());
96                 if (!runIndividualListenerTest(result, listenerClass))
97                     oneFailed=true;
98         }
99         if (oneFailed) {
100         result.setStatus(Result.FAILED);
101         } else {
102         result.setStatus(Result.PASSED);
103         }
104     } else {
105             result = getInitializedResult();
106             result.setStatus(Result.NOT_APPLICABLE);
107         result.addNaDetails(smh.getLocalString
108                 ("tests.componentNameConstructor",
109                  "For [ {0} ]",
110                  new Object JavaDoc[] {compName.toString()}));
111         result.notApplicable(smh.getLocalString
112                 ("com.sun.enterprise.tools.verifier.tests.web.ListenerClass" + ".notApplicable",
113          "There are no listener components within the web archive [ {0} ]",
114          new Object JavaDoc[] {descriptor.getName()}));
115     }
116
117     return result;
118     }
119 }
120
Popular Tags