KickJava   Java API By Example, From Geeks To Geeks.

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


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.Result;
26 import com.sun.enterprise.tools.verifier.Context;
27 import com.sun.enterprise.tools.verifier.TagLibDescriptor;
28 import com.sun.enterprise.tools.verifier.web.*;
29 import com.sun.enterprise.tools.verifier.web.TagDescriptor;
30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32
33 /**
34  * Tag class implements javax.servlet.jsp.tagext.JspTag for JSP version 2.0,
35  * javax.servlet.jsp.tagext.Tag for earlier versions of JSP specification.
36  *
37  * @author sg133765
38  */

39
40 public class TagClassExtendsValidInterface extends WebTest implements WebCheck {
41     public Result check(WebBundleDescriptor descriptor) {
42
43         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
44         Context context = getVerifierContext();
45         Result result = loadWarFile(descriptor);
46         TagLibDescriptor tlds[] = context.getTagLibDescriptors();
47         boolean failed=false;
48         boolean oneFailed = false;
49
50         if (tlds == null) {
51             addGoodDetails(result, compName);
52             result.passed(smh.getLocalString
53                     (getClass().getName() + ".passed",
54                             "No tag lib files are specified"));
55             return result;
56
57         }
58         for(TagLibDescriptor tld : tlds) {
59             TagDescriptor[] tagDesc = tld.getTagDescriptors();
60             for(TagDescriptor td : tagDesc) {
61                 String JavaDoc tagclass = td.getTagClass();
62                 Class JavaDoc c = loadClass(result, tagclass);
63                 if (c!=null) {
64                     if (tld.getSpecVersion().trim().equalsIgnoreCase("2.0")) {
65                         failed = !javax.servlet.jsp.tagext.JspTag JavaDoc.class.isAssignableFrom(c);
66                     } else {
67                         failed = !javax.servlet.jsp.tagext.Tag JavaDoc.class.isAssignableFrom(c);
68                     }
69                     if(failed) {
70                         oneFailed = true;
71                         addErrorDetails(result, compName);
72                         result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed",
73                                 "Error: tag class [ {0} ] in [ {1} ] does not implements valid interface",
74                                 new Object JavaDoc[] {c.getName(), tld.getUri()}));
75                     } else {
76                         addGoodDetails(result, compName);
77                         result.addGoodDetails(smh.getLocalString
78                                 (getClass().getName() + ".passed1",
79                                         "tag class [ {0} ] in [ {1} ] implements valid interface",
80                                         new Object JavaDoc[] {c.getName(), tld.getUri()}));
81                     }
82                 }
83             }//for
84
}
85         if(oneFailed)
86             result.setStatus(Result.FAILED);
87         else
88             result.setStatus(Result.PASSED);
89
90         return result;
91     }
92 }
93
Popular Tags