KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 package com.sun.enterprise.tools.verifier.tests.web.ias;
26
27
28 import com.sun.enterprise.tools.verifier.tests.web.elements.*;
29 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
30 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
31 import java.util.*;
32 import com.sun.enterprise.deployment.*;
33 import com.sun.enterprise.deployment.web.*;
34 import com.sun.enterprise.tools.verifier.*;
35 import com.sun.enterprise.tools.verifier.tests.*;
36 import com.sun.enterprise.tools.common.dd.webapp.*;
37
38 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
39
/* Changed the result messages to reflect consistency between the result messages generated
40  * for the EJB test cases for SunONE specific deployment descriptors*/

41 //</addition>
42

43 public class ASServlet extends WebTest implements WebCheck {
44
45
46
47     public Result check(WebBundleDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
51         Servlet[] servlets = descriptor.getIasWebApp().getServlet();//######
52
//String[] servlets=null;//######
53
String JavaDoc servletName;
54         String JavaDoc prinName;
55     boolean oneFailed = false;
56         //System.out.println(" servlet[]" + servlets + " length "+ servlets.length);
57
if (servlets !=null && servlets.length > 0) {
58         for (int rep=0; rep<servlets.length; rep++ ) {
59                 servletName=servlets[rep].getServletName();//######
60
// <addition> srini@sun.com Bug : 4699658
61
//prinName=servlets[rep].getPrincipalName();//######
62
prinName=servlets[rep].getPrincipalName().trim();//######
63
// </addition> Bug : 4699658
64

65                       if(validServletName(servletName,descriptor)){
66
67                       result.passed(smh.getLocalString
68                       (getClass().getName() + ".passed",
69                        "PASSED [AS-WEB servlet] servlet-name [ {0} ] properly defined in the war file.",
70                        new Object JavaDoc[] {servletName}));
71
72                       }else{
73
74                 result.failed(smh.getLocalString
75                        (getClass().getName() + ".failed",
76                         "FAILED [AS-WEB servlet] servlet-name [ {0} ] is not a valid, either empty or not defined in web.xml.",
77                         new Object JavaDoc[] {servletName}));
78                 oneFailed = true;
79
80                       }
81
82                       if(prinName !=null && ! "".equals(prinName)){
83
84                       result.passed(smh.getLocalString
85                       (getClass().getName() + ".passed1",
86                        "PASSED [AS-WEB servlet] principal-name [ {0} ] properly defined in the war file.",
87                        new Object JavaDoc[] {prinName}));
88                       }else{
89
90                 result.failed(smh.getLocalString
91                        (getClass().getName() + ".failed1",
92                         "FAILED [AS-WEB servlet ] principal-name [ {0} ] cannot be an empty string.",
93                         new Object JavaDoc[] {prinName}));
94                 oneFailed = true;
95
96                       }
97
98         }
99     } else {
100         result.notApplicable(smh.getLocalString
101                  (getClass().getName() + ".notApplicable",
102                   "NOT APPLICABLE [AS-WEB sun-web-app] servlet element(s) not defined in the web archive [ {0} ].",
103                   new Object JavaDoc[] {descriptor.getName()}));
104         return result;
105     }
106
107     if (oneFailed)
108         {
109         result.setStatus(Result.FAILED);
110         } else {
111         result.passed
112             (smh.getLocalString
113              (getClass().getName() + ".passed2",
114               "PASSED [AS-WEB sun-web-app] servlet element(s) are valid within the web archive [ {0} ] .",
115                             new Object JavaDoc[] {descriptor.getName()} ));
116         }
117     return result;
118     }
119
120     boolean validServletName(String JavaDoc servletName, WebBundleDescriptor descriptor){
121           boolean valid=false;
122           if (servletName != null && servletName.length() != 0) {
123               Set servlets = descriptor.getServletDescriptors();
124                     Iterator itr = servlets.iterator();
125                     // test the servlets in this .war
126
while (itr.hasNext()) {
127                         ServletDescriptor servlet = (ServletDescriptor) itr.next();
128                         String JavaDoc thisServletName = servlet.getCanonicalName();
129             if (servletName.equals(thisServletName)) {
130                             valid = true;
131                             break;
132                         }
133                     }
134
135           }
136           return valid;
137     }
138 }
139
140
Popular Tags