1 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 ; 30 import java.util.Iterator ; 31 import java.util.LinkedList ; 32 import java.util.Set ; 33 34 37 38 49 50 public class PortComponentLinkValidCheck extends WSClientTest implements WSClientCheck { 51 ComponentNameConstructor compName; 52 53 57 public Result check (ServiceReferenceDescriptor descriptor) { 58 59 Result result = getInitializedResult(); 60 compName = getVerifierContext().getComponentNameConstructor(); 61 62 boolean pass = true; 63 64 Collection ports = descriptor.getPortsInfo(); 65 66 for (Iterator it=ports.iterator(); it.hasNext();) { 67 ServiceRefPortInfo ref = (ServiceRefPortInfo)it.next(); 68 69 if (!ref.hasPortComponentLinkName()) { 71 result.addNaDetails(smh.getLocalString 73 ("tests.componentNameConstructor", "For [ {0} ]", 74 new Object [] {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 [] {ref.getName()})); 79 } 80 81 else if (ref.getPortComponentLink() != null) { 82 pass = true; 83 } 84 else if (!isLinkValid(ref)) { 85 result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor", 87 "For [ {0} ]", new Object [] {compName.toString()})); 88 result.failed(smh.getLocalString (getClass().getName() + ".failed", 89 "Invalid port-component-link [{0}] in WebService client [{1}].", 90 new Object [] {ref.getPortComponentLinkName(),compName.toString()})); 91 pass = false; 92 } 93 94 } 95 if (pass) { 96 result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor", 98 "For [ {0} ]", new Object [] {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 linkName = ref.getPortComponentLinkName(); 111 Application application = 113 ref.getServiceReference().getBundleDescriptor().getApplication(); 114 115 if( (linkName != null) && (linkName.length() > 0) && (application != null) ) { 116 int hashIndex = linkName.indexOf('#'); 117 String relativeModuleUri = linkName.substring(0, hashIndex); 120 String portName = linkName.substring(hashIndex + 1); 121 Set webBundles = application.getWebBundleDescriptors(); 123 Set ejbBundles = application.getEjbBundleDescriptors(); 124 Iterator ejbBundlesIterator = ejbBundles.iterator(); 127 EjbBundleDescriptor ejbBundle = null; 128 while (ejbBundlesIterator.hasNext()) { 130 ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next(); 131 try { 133 String archiveuri = ejbBundle.getModuleDescriptor().getArchiveUri(); 134 if ( relativeModuleUri.equals(archiveuri) ) { 135 LinkedList <EjbBundleDescriptor> bundles = new LinkedList <EjbBundleDescriptor>(); 136 bundles.addFirst(ejbBundle); 137 for(Iterator 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 e) {} 147 } 150 Iterator webBundlesIterator = webBundles.iterator(); 152 WebBundleDescriptor webBundle = null; 153 while (webBundlesIterator.hasNext()) { 155 webBundle = (WebBundleDescriptor)webBundlesIterator.next(); 156 try { 158 String archiveuri = webBundle.getModuleDescriptor().getArchiveUri(); 159 if ( relativeModuleUri.equals(archiveuri) ) { 160 LinkedList <WebBundleDescriptor> bundles = new LinkedList <WebBundleDescriptor>(); 161 bundles.addFirst(webBundle); 162 for(Iterator 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 e) {} 172 } } if ( port == null) 176 pass = false; 177 return pass; 178 179 } 181 } 182 | Popular Tags |