KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.tools.verifier.tests.web.WebTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 /**
32  * The load-on-startup element contains an integer indicating the order
33  * in which the servlet should be loaded.
34  */

35 public class ServletLoadOnStartup extends WebTest implements WebCheck {
36
37       
38     /**
39      * The load-on-startup element contains an integer indicating the order
40      * in which the servlet should be loaded.
41      *
42      * @param descriptor the Web deployment descriptor
43      *
44      * @return <code>Result</code> the results for this assertion
45      */

46     public Result check(WebBundleDescriptor descriptor) {
47
48     Result result = getInitializedResult();
49 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
50   
51
52     boolean oneFailed = false;
53     if (!descriptor.getServletDescriptors().isEmpty()) {
54         for (Iterator itr = descriptor.getServletDescriptors().iterator();
55          itr.hasNext();) {
56
57         WebComponentDescriptor nextServletDescriptor = (WebComponentDescriptor) itr.next();
58         // DOL only allows int's to be stored, test will always pass as written, so need to check against -1 placeholder
59
Integer JavaDoc loadOnStartUp = new Integer JavaDoc(nextServletDescriptor.getLoadOnStartUp());
60         if (loadOnStartUp.intValue() >= 0) {
61             // DOL needs to store string value representing load-on-startup value
62
result.addGoodDetails
63             (smh.getLocalString
64              (getClass().getName() + ".passed",
65               "load-on-startup [ {0} ] value found in [ {1} ]",
66               new Object JavaDoc[] {loadOnStartUp,nextServletDescriptor.getName()}));
67         } else {
68                     if (!oneFailed) {
69                     oneFailed = true;
70                     }
71             result.addErrorDetails
72             (smh.getLocalString
73              (getClass().getName() + ".failed",
74               "Error: load-on-startup [ {0} ] invalid value found in [ {1} ]",
75               new Object JavaDoc[] {loadOnStartUp,nextServletDescriptor.getName()}));
76         }
77         }
78         if (oneFailed) {
79             result.setStatus(Result.FAILED);
80             } else {
81             result.setStatus(Result.PASSED);
82         }
83     } else {
84         result.notApplicable(smh.getLocalString
85                  (getClass().getName() + ".notApplicable",
86                   "There are no servlets within this web archive [ {0} ]",
87                   new Object JavaDoc[] {descriptor.getName()}));
88     }
89
90     return result;
91     }
92 }
93
Popular Tags