KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > app > AppWebContextUnique


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.app;
24
25 import com.sun.enterprise.tools.verifier.tests.app.ApplicationTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29
30 /**
31  * All web modules in the application must have unique context-root.
32  */

33
34 public class AppWebContextUnique extends ApplicationTest implements AppCheck {
35
36
37     /**
38      * All web modules in the application must have unique context-root.
39      * Applicable for j2ee 1.3 or below. For 1.4 and above xml schema takes care of this.
40      * @param descriptor the Application deployment descriptor
41      *
42      * @return <code>Result</code> the results for this assertion
43      */

44     public Result check(Application descriptor) {
45
46     Result result = getInitializedResult();
47         Set webs=descriptor.getWebBundleDescriptors();
48         if(webs.size()<=1){
49             result.notApplicable(smh.getLocalString
50                  (getClass().getName() + ".notApplicable",
51                   "There is one or less web component in application [ {0} ]",
52                   new Object JavaDoc[] {descriptor.getName()}));
53             return result;
54         }
55         Set<String JavaDoc> contexts=new HashSet<String JavaDoc>();
56         Iterator itr=webs.iterator();
57         boolean oneFailed=false;
58     while (itr.hasNext()) {
59             WebBundleDescriptor wbd = (WebBundleDescriptor) itr.next();
60             String JavaDoc ctx=wbd.getContextRoot();
61             if(!contexts.add(ctx)){
62                 oneFailed=true;
63                 result.failed(
64                     (smh.getLocalString
65                      (getClass().getName() + ".failed",
66                       "Error: There is already a web module with context-root [ {0} ] within application [ {1} ]",
67                       new Object JavaDoc[] {ctx, descriptor.getName()})));
68             }
69         }
70     if(!oneFailed){
71             result.passed(
72                 (smh.getLocalString
73                  (getClass().getName() + ".passed",
74                   "All the context-root values are unique within application [ {0} ]",
75                   new Object JavaDoc[] {descriptor.getName()})));
76         }
77     return result;
78     }
79 }
80
Popular Tags