KickJava   Java API By Example, From Geeks To Geeks.

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


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.tests.web;
25
26 import com.sun.enterprise.tools.verifier.Result;
27 import com.sun.enterprise.tools.verifier.Context;
28 import com.sun.enterprise.tools.verifier.TagLibDescriptor;
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  * dynamic-attributes element in tag element describes whether this tag supports
35  * additional attributes with dynamic names. If true, the tag-class must
36  * implement the javax.servlet.jsp.tagext.DynamicAttributes interface.
37  * Defaults to false.
38  * @author Sudipto Ghosh
39  *
40  */

41 public class TagClassImplementsValidInterface extends WebTest implements WebCheck {
42     public Result check(WebBundleDescriptor descriptor) {
43
44         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
45         Context context = getVerifierContext();
46         Result result = getInitializedResult();
47         ClassLoader JavaDoc cl = context.getClassLoader();
48         TagLibDescriptor tlds[] = context.getTagLibDescriptors();
49         if (tlds == null) {
50             addGoodDetails(result, compName);
51             result.passed(smh.getLocalString
52                     (getClass().getName() + ".passed",
53                             "No tag lib files are specified"));
54             return result;
55         }
56
57         for (TagLibDescriptor tld : tlds) {
58             if (tld.getSpecVersion().compareTo("2.0")>=0) {
59                 for (TagDescriptor tagdesc : tld.getTagDescriptors()) {
60                     Class JavaDoc c = null;
61                     try {
62                         c = Class.forName(tagdesc.getTagClass(), false, cl);
63                     } catch (ClassNotFoundException JavaDoc e) {
64                        //do nothing
65
}
66                     if (tagdesc.getDynamicAttributes().equalsIgnoreCase("true") &&
67                             !javax.servlet.jsp.tagext.DynamicAttributes JavaDoc.class.
68                             isAssignableFrom(c) ) {
69                         addErrorDetails(result, compName);
70                         result.failed(smh.getLocalString(getClass()
71                                 .getName() +
72                                 ".failed",
73                                 "Error: tag class [ {0} ] in [ {1} ] does not " +
74                                 "implements interface " +
75                                 "javax.servlet.jsp.tagext.DynamicAttributes",
76                                 new Object JavaDoc[]{c.getName(), tld.getUri()}));
77
78                     }
79                 }
80             }
81         }
82
83         if(result.getStatus() != Result.FAILED) {
84             addGoodDetails(result, compName);
85             result.passed(smh.getLocalString(getClass()
86                                     .getName() +
87                     ".passed1", "All tag-class defined in the tag lib descriptor" +
88                     " files implement valid interface"));
89         }
90         return result;
91     }
92 }
93
Popular Tags