KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > util > ModuleContentLinker


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
24 package com.sun.enterprise.deployment.util;
25
26 import java.util.logging.Level JavaDoc;
27
28 import java.io.File JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 import java.net.URL JavaDoc;
34 import java.net.URLConnection JavaDoc;
35 import java.net.MalformedURLException JavaDoc;
36
37 import com.sun.enterprise.deployment.Application;
38 import com.sun.enterprise.deployment.archivist.Archivist;
39 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
40 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
41 import com.sun.enterprise.deployment.util.DOLUtils;
42 import com.sun.enterprise.deployment.util.ModuleDescriptor;
43 import com.sun.enterprise.deployment.WebService;
44 import com.sun.enterprise.util.FileUtil;
45
46 /**
47  *
48  * @author Kenneth Saks
49  */

50 public class ModuleContentLinker extends DefaultDOLVisitor {
51
52     // For standalone modules, this is either a directory or a jar file.
53
// For .ears, this is the directory used by the j2ee classloader.
54
protected FileArchive rootLocation_;
55
56     public ModuleContentLinker(FileArchive rootLocation) {
57         rootLocation_ = rootLocation;
58     }
59     
60     protected ModuleContentLinker() {
61     }
62
63     private File JavaDoc getModuleLocation(ModuleDescriptor module) throws IOException JavaDoc {
64         File JavaDoc moduleLocation = new File JavaDoc(rootLocation_.getArchiveUri());
65         if( !module.isStandalone() ) {
66             // If this is an ear, get module jar by adding the module path
67
// to the root directory.
68
String JavaDoc archiveUri = module.getArchiveUri();
69             moduleLocation = new File JavaDoc(rootLocation_.getEmbeddedArchive(archiveUri).getArchiveUri());
70         }
71         return moduleLocation;
72     }
73
74     private URL JavaDoc internalGetUrl(ModuleDescriptor module, String JavaDoc uri)
75         throws Exception JavaDoc {
76         File JavaDoc moduleLocation = getModuleLocation(module);
77         URL JavaDoc url = FileUtil.getEntryAsUrl(moduleLocation, uri);
78         return url;
79     }
80
81     public void accept(ServiceReferenceDescriptor serviceRef) {
82         try {
83             ModuleDescriptor moduleDesc =
84                 serviceRef.getBundleDescriptor().getModuleDescriptor();
85
86             if( serviceRef.hasWsdlFile() ) {
87                 
88                 String JavaDoc wsdlFileUri = serviceRef.getWsdlFileUri();
89                 File JavaDoc tmpFile = new File JavaDoc(wsdlFileUri);
90                 if(tmpFile.isAbsolute()) {
91                     // This takes care of the case when we set wsdlFileUri from generated @WebClient
92
// and the uri is an absolute path
93
serviceRef.setWsdlFileUrl(tmpFile.toURI().toURL());
94                 } else {
95                     // If the given WSDL is an http URL, create a URL directly from this
96
if(wsdlFileUri.startsWith("http")) {
97                         serviceRef.setWsdlFileUrl(new URL JavaDoc(wsdlFileUri));
98                     } else {
99                         // Given WSDL location is a relative path - append this to the module dir
100
File JavaDoc wsdlFile = new File JavaDoc(getModuleLocation(moduleDesc), wsdlFileUri);
101                         URL JavaDoc wsdlFileUrl = internalGetUrl(moduleDesc, wsdlFileUri);
102                         serviceRef.setWsdlFileUrl(wsdlFile.toURI().toURL());
103                     }
104                 }
105             }
106             if( serviceRef.hasMappingFile() ) {
107                 String JavaDoc mappingFileUri = serviceRef.getMappingFileUri();
108                 File JavaDoc mappingFile = new File JavaDoc(getModuleLocation(moduleDesc), mappingFileUri);
109                 serviceRef.setMappingFile(mappingFile);
110
111             }
112         } catch (java.net.MalformedURLException JavaDoc mex) {
113             DOLUtils.getDefaultLogger().log
114                 (Level.SEVERE, "enterprise.deployment.backend.invalidWsdlURL",
115                 new Object JavaDoc[] {serviceRef.getWsdlFileUri()});
116         } catch(Exception JavaDoc e) {
117             DOLUtils.getDefaultLogger().log
118                 (Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
119                 new Object JavaDoc[] {serviceRef.getName() , rootLocation_});
120         }
121     }
122
123     public void accept(WebService webService) {
124         try {
125             ModuleDescriptor moduleDesc =
126                 webService.getBundleDescriptor().getModuleDescriptor();
127
128             if( webService.hasWsdlFile() && webService.getWsdlFileUrl()==null) {
129                 String JavaDoc wsdlFileUri = webService.getWsdlFileUri();
130                 URL JavaDoc wsdlFileURL=null;
131                 try {
132                     URL JavaDoc url = new URL JavaDoc(wsdlFileUri);
133                     if (url.getProtocol()!=null && !url.getProtocol().equalsIgnoreCase("file")) {
134                         wsdlFileURL=url;
135                     }
136                 } catch(java.net.MalformedURLException JavaDoc e) {
137                     // ignore, it could just be a relate URI
138
}
139                 if (wsdlFileURL==null) {
140                     File JavaDoc wsdlFile = new File JavaDoc(getModuleLocation(moduleDesc), wsdlFileUri);
141                     wsdlFileURL = wsdlFile.toURI().toURL();
142                 }
143                 webService.setWsdlFileUrl(wsdlFileURL);
144             }
145             if( webService.hasMappingFile() ) {
146                 String JavaDoc mappingFileUri = webService.getMappingFileUri();
147                 File JavaDoc mappingFile = new File JavaDoc(getModuleLocation(moduleDesc), mappingFileUri);
148                 webService.setMappingFile(mappingFile);
149             }
150         } catch(Exception JavaDoc e) {
151             DOLUtils.getDefaultLogger().log
152                 (Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
153                 new Object JavaDoc[] {webService.getName() , rootLocation_});
154         }
155     }
156
157 }
158
Popular Tags