KickJava   Java API By Example, From Geeks To Geeks.

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


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_44;
38  * @test_Strategy:
39  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
40  * @testDescription: A session EJB must only be linked to by a single port-component.
41  */

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

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