FileDocCategorySizeDatePackage
PortComponentLinkValidCheck.javaAPI DocGlassfish v2 API8651Fri May 04 22:34:18 BST 2007com.sun.enterprise.tools.verifier.tests.wsclients

PortComponentLinkValidCheck

public class PortComponentLinkValidCheck extends WSClientTest implements WSClientCheck

Fields Summary
com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(ServiceReferenceDescriptor descriptor)

param
descriptor the WebServices descriptor
return
Result the results for this assertion


	Result result = getInitializedResult();
        compName = getVerifierContext().getComponentNameConstructor();

        boolean pass = true;

        Collection ports = descriptor.getPortsInfo();

        for (Iterator it=ports.iterator(); it.hasNext();) {
            ServiceRefPortInfo ref = (ServiceRefPortInfo)it.next();

            // check if this test is applicable first
            if (!ref.hasPortComponentLinkName()) { 
              //result.notapplicable, since port-comp-link does not exist in port-comp-ref
              result.addNaDetails(smh.getLocalString
                     ("tests.componentNameConstructor", "For [ {0} ]",
                      new Object[] {compName.toString()}));
              result.notApplicable(smh.getLocalString
                 ( getClass().getName() + ".notapp",
                 "Not applicable since port-comp-link does not exist in port-comp-ref [{0}].",
                  new Object[] {ref.getName()}));
               } 

               else if (ref.getPortComponentLink() != null) {
               pass = true; 
               } 
               else if (!isLinkValid(ref)) {
                     //result.fail ref.getName(), ref.getPortComponentLinkName()
                       result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
                       "For [ {0} ]", new Object[] {compName.toString()}));
                       result.failed(smh.getLocalString (getClass().getName() + ".failed",
                       "Invalid port-component-link [{0}] in WebService client [{1}].",
                        new Object[] {ref.getPortComponentLinkName(),compName.toString()}));
                        pass = false;
                }  
              
        }
        if (pass) {
              //result.pass
              result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
                                   "For [ {0} ]", new Object[] {compName.toString()}));
              result.passed(smh.getLocalString (getClass().getName() + ".passed",
             "All port-component-link(s) in this service reference are valid."));
        }
        return result;
    
private booleanisLinkValid(ServiceRefPortInfo ref)

   boolean pass = true;

   WebServiceEndpoint port = null;

      String linkName = ref.getPortComponentLinkName();
// == get the application
     Application application =
                 ref.getServiceReference().getBundleDescriptor().getApplication();

      if(  (linkName != null) && (linkName.length() > 0) && (application != null) )    { 
         int hashIndex = linkName.indexOf('#");
//         boolean absoluteLink = (hashIndex != -1);
         // Resolve <module>#<port-component-name> style link
         String relativeModuleUri = linkName.substring(0, hashIndex);
         String portName = linkName.substring(hashIndex + 1);
// == get bundle(s)
         Set webBundles = application.getWebBundleDescriptors();
         Set ejbBundles = application.getEjbBundleDescriptors();
// ==
         // iterate through the ejb jars in this J2EE Application
         Iterator ejbBundlesIterator = ejbBundles.iterator();
         EjbBundleDescriptor ejbBundle = null;
// == while...
         while (ejbBundlesIterator.hasNext()) {
         ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next();
//         if (Verifier.getEarFile() != null){
           try {
              String archiveuri = ejbBundle.getModuleDescriptor().getArchiveUri();
              if ( relativeModuleUri.equals(archiveuri) ) {
              LinkedList<EjbBundleDescriptor> bundles = new LinkedList<EjbBundleDescriptor>();
                 bundles.addFirst(ejbBundle);
                 for(Iterator iter = bundles.iterator(); iter.hasNext();) {
                    BundleDescriptor next = (BundleDescriptor) iter.next();
                    port = next.getWebServiceEndpointByName(portName);
                    if( port != null ) {
                       pass = true;     
                       break;
                    }
                 }
              }
            }catch(Exception e) {}
//          }
          } // while block

         // iterate through the wars in this J2EE Application
         Iterator webBundlesIterator = webBundles.iterator();
         WebBundleDescriptor webBundle = null;
// == while...
         while (webBundlesIterator.hasNext()) {
         webBundle = (WebBundleDescriptor)webBundlesIterator.next();
//         if (Verifier.getEarFile() != null){
           try {
              String archiveuri = webBundle.getModuleDescriptor().getArchiveUri();
              if ( relativeModuleUri.equals(archiveuri) ) {
              LinkedList<WebBundleDescriptor> bundles = new LinkedList<WebBundleDescriptor>();
                 bundles.addFirst(webBundle);
                 for(Iterator iter = bundles.iterator(); iter.hasNext();) {
                    BundleDescriptor next = (BundleDescriptor) iter.next();
                    port = next.getWebServiceEndpointByName(portName);
                    if( port != null ) {
                       pass = true;    
                       break;
                    }
                 }
              }
            }catch(Exception e) {}
//          }
          } // while block
       } // 
       if ( port == null)
          pass = false;
     return pass;