KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > webservices > ServletLinkedToOnePortCompCheck


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.webservices;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.*;
27 import java.util.*;
28 import com.sun.enterprise.tools.verifier.tests.*;
29 import java.lang.reflect.*;
30
31 /*
32  * @class.setup_props: ;
33  */

34
35 /*
36  * @testName: check
37  * @assertion_ids: JSR109_WS_43;
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription: A servlet must only be linked to by a single port-component.
41  */

42
43 public class ServletLinkedToOnePortCompCheck extends WSTest implements WSCheck {
44
45     /**
46      * @param descriptor the WebServices descriptor
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check (WebServiceEndpoint descriptor) {
50
51     Result result = getInitializedResult();
52         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54         if (descriptor.implementedByEjbComponent()) {
55            result.addNaDetails(smh.getLocalString
56                      ("tests.componentNameConstructor", "For [ {0} ]",
57                       new Object JavaDoc[] {compName.toString()}));
58            result.notApplicable(smh.getLocalString
59                  (getClass().getName() + ".notapp",
60                  "This is an EJB Service Endpoint"));
61            return result;
62         }
63
64     
65         if (isLinkedToSinglePortComp(getAllEndPointsInApp(descriptor),descriptor.getLinkName())) {
66            // result.pass
67
result.addGoodDetails(smh.getLocalString
68                                   ("tests.componentNameConstructor",
69                                    "For [ {0} ]",
70                                    new Object JavaDoc[] {compName.toString()}));
71            result.passed(smh.getLocalString
72                    (getClass().getName() + ".passed",
73            "The Servlet associated with this end-point is linked to by a single port-component."));
74
75         }
76         else {
77           // result.fail
78
result.addErrorDetails(smh.getLocalString
79                                   ("tests.componentNameConstructor",
80                                    "For [ {0} ]",
81                                    new Object JavaDoc[] {compName.toString()}));
82           result.failed(smh.getLocalString
83                 (getClass().getName() + ".failed",
84                 "The Servlet associated with this end-point is linked to by multiple port-components."));
85
86         }
87
88         return result;
89     }
90
91     Collection getAllEndPointsInApp(WebServiceEndpoint desc) {
92        Collection allWebServices = desc.getWebService().getWebServicesDescriptor().getWebServices();
93        Collection ret = new Vector();
94        for (Iterator it = allWebServices.iterator(); it.hasNext();) {
95            ret.addAll(((WebService)it.next()).getEndpoints());
96        }
97
98      return ret;
99     }
100
101     // the compLink here is either an ejb-link or a servlet-link
102
boolean isLinkedToSinglePortComp(Collection endPoints, String JavaDoc compLink) {
103        boolean single = true;
104        boolean linkAlreadySeen = false;
105        for (Iterator it = endPoints.iterator(); it.hasNext();) {
106            String JavaDoc myCompLink = ((WebServiceEndpoint)it.next()).getLinkName();
107
108            if (myCompLink.equals(compLink)) {
109               if (!linkAlreadySeen) {
110                  linkAlreadySeen = true;
111               }
112               else {
113                  single = false;
114                  break;
115               }
116            }
117        }
118      return single;
119     }
120  }
121
122
Popular Tags