FileDocCategorySizeDatePackage
ModuleContentLinker.javaAPI DocGlassfish v2 API8538Fri Jul 27 04:50:12 BST 2007com.sun.enterprise.deployment.util

ModuleContentLinker

public class ModuleContentLinker extends DefaultDOLVisitor
author
Kenneth Saks

Fields Summary
protected com.sun.enterprise.deployment.deploy.shared.FileArchive
rootLocation_
private boolean
forceWSDLURLs
Constructors Summary
public ModuleContentLinker(com.sun.enterprise.deployment.deploy.shared.FileArchive rootLocation, boolean forceWSDLURLs)

        rootLocation_ = rootLocation;
        this.forceWSDLURLs = forceWSDLURLs;
    
public ModuleContentLinker(com.sun.enterprise.deployment.deploy.shared.FileArchive rootLocation)

        this(rootLocation, false);
    
protected ModuleContentLinker()

    
Methods Summary
public voidaccept(com.sun.enterprise.deployment.ServiceReferenceDescriptor serviceRef)

        try {
            ModuleDescriptor moduleDesc = 
                serviceRef.getBundleDescriptor().getModuleDescriptor();

            if( serviceRef.hasWsdlFile() ) {
                
                String wsdlFileUri = serviceRef.getWsdlFileUri();
                File tmpFile = new File(wsdlFileUri);
                if(tmpFile.isAbsolute()) {
                    // This takes care of the case when we set wsdlFileUri from generated @WebClient
                    // and the uri is an absolute path
                    serviceRef.setWsdlFileUrl(tmpFile.toURI().toURL());
                } else {
                    // If the given WSDL is an http URL, create a URL directly from this
                    if(wsdlFileUri.startsWith("http")) {
                        serviceRef.setWsdlFileUrl(new URL(wsdlFileUri));
                    } else {
                        // Given WSDL location is a relative path - append this to the module dir
                        File wsdlFile = new File(getModuleLocation(moduleDesc), wsdlFileUri);                
                        URL wsdlFileUrl = internalGetUrl(moduleDesc, wsdlFileUri);
                        serviceRef.setWsdlFileUrl(wsdlFile.toURI().toURL());
                    }
                }
            } else {
            //Incase wsdl file is missing we can obtain it from the @WebServiceClient annotation
                  ClassLoader classloader = Thread.currentThread().getContextClassLoader();
                  Class serviceInterfaceClass = classloader.loadClass(serviceRef.getServiceInterface());
                  WebServiceClient wsc = (WebServiceClient)serviceInterfaceClass.getAnnotation(javax.xml.ws.WebServiceClient.class);
                  if (wsc != null) {
                      serviceRef.setWsdlFileUri(wsc.wsdlLocation());
                      //we set the service QName too from the @WebServiceClient annotation
                      serviceRef.setServiceName(new QName(wsc.targetNamespace(),wsc.name()) );
                  }

            }
            if( serviceRef.hasMappingFile() ) {
                String mappingFileUri = serviceRef.getMappingFileUri();
                File mappingFile = new File(getModuleLocation(moduleDesc), mappingFileUri);
                serviceRef.setMappingFile(mappingFile);

            } 
        } catch (java.net.MalformedURLException mex) {
            DOLUtils.getDefaultLogger().log
                (Level.SEVERE, "enterprise.deployment.backend.invalidWsdlURL",
                new Object[] {serviceRef.getWsdlFileUri()});            
        } catch(Exception e) {
            DOLUtils.getDefaultLogger().log
                (Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
                new Object[] {serviceRef.getName() , rootLocation_});
        }
    
public voidaccept(com.sun.enterprise.deployment.WebService webService)

        try {
            ModuleDescriptor moduleDesc = 
                webService.getBundleDescriptor().getModuleDescriptor();
            // If the web service has a WSDL file, assign its URL if it is not
            // already assigned or if URLs are forced to be assigned.  
            if( webService.hasWsdlFile() && (webService.getWsdlFileUrl()==null || forceWSDLURLs) ) {
                String wsdlFileUri = webService.getWsdlFileUri();
                URL wsdlFileURL=null;
                try {
                    URL url = new URL(wsdlFileUri);
                    if (url.getProtocol()!=null && !url.getProtocol().equalsIgnoreCase("file")) {
                        wsdlFileURL=url;
                    } 
                } catch(java.net.MalformedURLException e) {
                    // ignore, it could just be a relate URI
                }
                if (wsdlFileURL==null) {
                    File wsdlFile = new File(getModuleLocation(moduleDesc), wsdlFileUri);                        
                    wsdlFileURL = wsdlFile.toURI().toURL();
                }
                webService.setWsdlFileUrl(wsdlFileURL);
            }
            if( webService.hasMappingFile() ) {
                String mappingFileUri = webService.getMappingFileUri();
                File mappingFile = new File(getModuleLocation(moduleDesc), mappingFileUri);
                webService.setMappingFile(mappingFile);
            } 
        } catch(Exception e) {
            DOLUtils.getDefaultLogger().log
                (Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
                new Object[] {webService.getName() , rootLocation_});
        } 
    
private java.io.FilegetModuleLocation(ModuleDescriptor module)

        File moduleLocation = new File(rootLocation_.getArchiveUri());
        if( !module.isStandalone() ) {
            // If this is an ear, get module jar by adding the module path
            // to the root directory.
            String archiveUri = module.getArchiveUri();
            moduleLocation = new File(rootLocation_.getEmbeddedArchive(archiveUri).getArchiveUri());
        }
        return moduleLocation;
    
private java.net.URLinternalGetUrl(ModuleDescriptor module, java.lang.String uri)

        File moduleLocation = getModuleLocation(module);
        URL url = FileUtil.getEntryAsUrl(moduleLocation, uri);
        return url;