KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29
30 public abstract class URLPatternUnique extends WebTest implements WebCheck {
31     /**
32      * the url-pattern should be unique. Refer to bug#4903615
33      * This test serves as a base class for three classes.
34      * It has a pure virtual function which has to be implemented in concrete subclasses.
35      * Note: This right now reports WARNING, as it is not clear from spec
36      * if it should report a failure.
37      * @param descriptor the Web deployment descriptor
38      *
39      * @return <code>Result</code> the results for this assertion
40      */

41     public Result check(WebBundleDescriptor descriptor) {
42         boolean na=true, warning=false;
43         Result result = getInitializedResult();
44         ComponentNameConstructor compName =
45                 getVerifierContext().getComponentNameConstructor();
46         //this warning will be displayed depending on the final status.
47
result.addWarningDetails(smh.getLocalString
48                                                    ("tests.componentNameConstructor",
49                                                         "For [ {0} ]",
50                                                         new Object JavaDoc[] {compName.toString()}));
51
52         //Assumes that DOL gives us the list of url-patterns including duplicates
53
Set<String JavaDoc> urlPatterns=new HashSet<String JavaDoc>();
54         for(Iterator iter=getUrlPatterns(descriptor).iterator();iter.hasNext();){
55             na=false;
56             String JavaDoc urlPattern=(String JavaDoc)iter.next();
57             if(!urlPatterns.add(urlPattern)){
58                     warning=true;
59                     result.setStatus(Result.WARNING);
60                     result.addWarningDetails(smh.getLocalString
61                                                      (getClass().getName() + ".warning",
62                                                       "url-pattern [ {0} ] already exists in web archive [ {1} ]",
63                                                       new Object JavaDoc[] {urlPattern, descriptor.getName()}));
64             }
65         }
66
67         if(na){
68             result.setStatus(Result.NOT_APPLICABLE);
69             result.addNaDetails(smh.getLocalString
70                                                ("tests.componentNameConstructor",
71                                                     "For [ {0} ]",
72                                                     new Object JavaDoc[] {compName.toString()}));
73             result.addNaDetails(smh.getLocalString
74                                                      (getClass().getName() + ".notApplicable",
75                                                     "There is no url-pattern element within the web archive [ {0} ]",
76                                                     new Object JavaDoc[] {descriptor.getName()}));
77         }else if(!warning) {
78             result.passed(smh.getLocalString
79                                                ("tests.componentNameConstructor",
80                                                     "For [ {0} ]",
81                                                     new Object JavaDoc[] {compName.toString()}));
82             result.addGoodDetails(smh.getLocalString
83                                                      (getClass().getName() + ".passed",
84                                                     "All the url-patterns are unique within the web archive [ {0} ]",
85                                                     new Object JavaDoc[] {descriptor.getName()}));
86         }
87         return result;
88     }
89     protected abstract Collection getUrlPatterns(WebBundleDescriptor descriptor);
90 }
91
Popular Tags