KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > wsclients > PortComponentLinkValidCheck


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.wsclients;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.Result;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28
29 import java.util.Collection JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.Set JavaDoc;
33
34 /*
35  * @class.setup_props: ;
36  */

37
38 /*
39  * @testName: check
40  * @assertion_ids: JSR109_WS_55;
41  * @test_Strategy:
42  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
43  * @testDescription: The port-component-link element links a port-component-ref to a
44  * specific port-component required to be made available by a service reference.
45  * The value of a port-component-link must be the port-component-name of a port-component
46  * in the same module or another module in the same application unit. The syntax for
47  * specification follows the syntax defined for ejb-link in the EJB 2.0 specification.
48  */

49
50 public class PortComponentLinkValidCheck extends WSClientTest implements WSClientCheck {
51     ComponentNameConstructor compName;
52
53     /**
54      * @param descriptor the WebServices descriptor
55      * @return <code>Result</code> the results for this assertion
56      */

57     public Result check (ServiceReferenceDescriptor descriptor) {
58
59     Result result = getInitializedResult();
60         compName = getVerifierContext().getComponentNameConstructor();
61
62         boolean pass = true;
63
64         Collection JavaDoc ports = descriptor.getPortsInfo();
65
66         for (Iterator JavaDoc it=ports.iterator(); it.hasNext();) {
67             ServiceRefPortInfo ref = (ServiceRefPortInfo)it.next();
68
69             // check if this test is applicable first
70
if (!ref.hasPortComponentLinkName()) {
71               //result.notapplicable, since port-comp-link does not exist in port-comp-ref
72
result.addNaDetails(smh.getLocalString
73                      ("tests.componentNameConstructor", "For [ {0} ]",
74                       new Object JavaDoc[] {compName.toString()}));
75               result.notApplicable(smh.getLocalString
76                  ( getClass().getName() + ".notapp",
77                  "Not applicable since port-comp-link does not exist in port-comp-ref [{0}].",
78                   new Object JavaDoc[] {ref.getName()}));
79                }
80
81                else if (ref.getPortComponentLink() != null) {
82                pass = true;
83                }
84                else if (!isLinkValid(ref)) {
85                      //result.fail ref.getName(), ref.getPortComponentLinkName()
86
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
87                        "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
88                        result.failed(smh.getLocalString (getClass().getName() + ".failed",
89                        "Invalid port-component-link [{0}] in WebService client [{1}].",
90                         new Object JavaDoc[] {ref.getPortComponentLinkName(),compName.toString()}));
91                         pass = false;
92                 }
93               
94         }
95         if (pass) {
96               //result.pass
97
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
98                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
99               result.passed(smh.getLocalString (getClass().getName() + ".passed",
100              "All port-component-link(s) in this service reference are valid."));
101         }
102         return result;
103     }
104
105    private boolean isLinkValid(ServiceRefPortInfo ref) {
106    boolean pass = true;
107
108    WebServiceEndpoint port = null;
109
110       String JavaDoc linkName = ref.getPortComponentLinkName();
111 // == get the application
112
Application application =
113                  ref.getServiceReference().getBundleDescriptor().getApplication();
114
115       if( (linkName != null) && (linkName.length() > 0) && (application != null) ) {
116          int hashIndex = linkName.indexOf('#');
117 // boolean absoluteLink = (hashIndex != -1);
118
// Resolve <module>#<port-component-name> style link
119
String JavaDoc relativeModuleUri = linkName.substring(0, hashIndex);
120          String JavaDoc portName = linkName.substring(hashIndex + 1);
121 // == get bundle(s)
122
Set JavaDoc webBundles = application.getWebBundleDescriptors();
123          Set JavaDoc ejbBundles = application.getEjbBundleDescriptors();
124 // ==
125
// iterate through the ejb jars in this J2EE Application
126
Iterator JavaDoc ejbBundlesIterator = ejbBundles.iterator();
127          EjbBundleDescriptor ejbBundle = null;
128 // == while...
129
while (ejbBundlesIterator.hasNext()) {
130          ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
131 // if (Verifier.getEarFile() != null){
132
try {
133               String JavaDoc archiveuri = ejbBundle.getModuleDescriptor().getArchiveUri();
134               if ( relativeModuleUri.equals(archiveuri) ) {
135               LinkedList JavaDoc<EjbBundleDescriptor> bundles = new LinkedList JavaDoc<EjbBundleDescriptor>();
136                  bundles.addFirst(ejbBundle);
137                  for(Iterator JavaDoc iter = bundles.iterator(); iter.hasNext();) {
138                     BundleDescriptor next = (BundleDescriptor) iter.next();
139                     port = next.getWebServiceEndpointByName(portName);
140                     if( port != null ) {
141                        pass = true;
142                        break;
143                     }
144                  }
145               }
146             }catch(Exception JavaDoc e) {}
147 // }
148
} // while block
149

150          // iterate through the wars in this J2EE Application
151
Iterator JavaDoc webBundlesIterator = webBundles.iterator();
152          WebBundleDescriptor webBundle = null;
153 // == while...
154
while (webBundlesIterator.hasNext()) {
155          webBundle = (WebBundleDescriptor)webBundlesIterator.next();
156 // if (Verifier.getEarFile() != null){
157
try {
158               String JavaDoc archiveuri = webBundle.getModuleDescriptor().getArchiveUri();
159               if ( relativeModuleUri.equals(archiveuri) ) {
160               LinkedList JavaDoc<WebBundleDescriptor> bundles = new LinkedList JavaDoc<WebBundleDescriptor>();
161                  bundles.addFirst(webBundle);
162                  for(Iterator JavaDoc iter = bundles.iterator(); iter.hasNext();) {
163                     BundleDescriptor next = (BundleDescriptor) iter.next();
164                     port = next.getWebServiceEndpointByName(portName);
165                     if( port != null ) {
166                        pass = true;
167                        break;
168                     }
169                  }
170               }
171             }catch(Exception JavaDoc e) {}
172 // }
173
} // while block
174
} //
175
if ( port == null)
176           pass = false;
177      return pass;
178
179     } // end of method
180

181  }
182
Popular Tags