00001
00026 package org.objectweb.jonas_ws.deployment.api;
00027
00028 import java.io.File;
00029 import java.io.InputStream;
00030 import java.net.MalformedURLException;
00031 import java.net.URL;
00032 import java.util.HashMap;
00033 import java.util.Hashtable;
00034 import java.util.Iterator;
00035 import java.util.List;
00036 import java.util.Map;
00037 import java.util.Set;
00038 import java.util.Vector;
00039
00040 import org.objectweb.jonas_lib.I18n;
00041
00042 import org.objectweb.jonas_ws.deployment.lib.MappingFileManager;
00043 import org.objectweb.jonas_ws.deployment.lib.wrapper.MappingFileManagerWrapper;
00044 import org.objectweb.jonas_ws.deployment.xml.JonasPortComponent;
00045 import org.objectweb.jonas_ws.deployment.xml.JonasWebserviceDescription;
00046 import org.objectweb.jonas_ws.deployment.xml.PortComponent;
00047 import org.objectweb.jonas_ws.deployment.xml.WebserviceDescription;
00048
00049 import org.objectweb.jonas.common.Log;
00050
00051 import org.objectweb.util.monolog.api.BasicLevel;
00052 import org.objectweb.util.monolog.api.Logger;
00053
00062 public class ServiceDesc {
00063
00067 private static I18n i18n = I18n.getInstance(ServiceDesc.class);
00068
00072 private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX);
00073
00077 private String name;
00078
00082 private Hashtable namePCDescBindings = new Hashtable();
00083
00087 private WSDLFile wsdl = null;
00088
00092 private MappingFile mapping = null;
00093
00097 private String endpointURI = null;
00098
00102 private File publicationDirectory = null;
00103
00107 private URL mappingFileURL;
00108
00112 private URL localWSDLURL;
00113
00121 public ServiceDesc(ClassLoader jarCL, WebserviceDescription wsd, JonasWebserviceDescription jwsd) throws WSDeploymentDescException {
00122
00123
00124 name = wsd.getWebserviceDescriptionName();
00125 if ("".equals(name)) {
00126 throw new WSDeploymentDescException(getI18n().getMessage("ServiceDesc.noServiceName"));
00127 }
00128
00129 if (jwsd != null) {
00130
00131 String uri = jwsd.getDefaultEndpointURI();
00132 if (uri != null && !"".equals(uri)) {
00133 endpointURI = uri;
00134 }
00135
00136
00137 String wsdlPubDir = jwsd.getWsdlPublishDirectory();
00138 if (wsdlPubDir != null) {
00139 URL pub;
00140 try {
00141 pub = new URL(wsdlPubDir);
00142 } catch (MalformedURLException e) {
00143 throw new WSDeploymentDescException("Cannot create URL : " + wsdlPubDir, e);
00144 }
00145 publicationDirectory = new File(pub.getPath());
00146 }
00147 }
00148
00149
00150
00151 String wsdlFileName = wsd.getWsdlFile();
00152
00153
00154 if ("".equals(wsdlFileName)) {
00155 String err = getI18n().getMessage("ServiceDesc.noWSDL", name);
00156 throw new WSDeploymentDescException(err);
00157 }
00158
00159
00160 wsdl = new WSDLFile(jarCL, wsdlFileName);
00161 localWSDLURL = jarCL.getResource(wsdlFileName);
00162
00163
00164 String mappingFileName = wsd.getJaxrpcMappingFile();
00165
00166
00167 if (mappingFileName.equals("")) {
00168 String err = getI18n().getMessage("ServiceDesc.noJAXRPCMapping", name);
00169 throw new WSDeploymentDescException(err);
00170 }
00171
00172 InputStream isMapping = jarCL.getResourceAsStream(mappingFileName);
00173
00174
00175 if (isMapping == null) {
00176 String err = getI18n().getMessage("ServiceDesc.MappingNotFound", mappingFileName, name);
00177 throw new WSDeploymentDescException(err);
00178 }
00179
00180 mappingFileURL = jarCL.getResource(mappingFileName);
00181
00182
00183 if (isRunningInClientContainer()) {
00184
00185 mapping = MappingFileManager.getInstance(isMapping, mappingFileName);
00186 } else {
00187
00188 mapping = MappingFileManagerWrapper.getMappingFile(isMapping, mappingFileName);
00189 }
00190
00191
00192 Map links = associatePCAndJPC(wsd, jwsd);
00193
00194
00195 List pcl = wsd.getPortComponentList();
00196
00197 for (int i = 0; i < pcl.size(); i++) {
00198
00199 PortComponent pc = (PortComponent) pcl.get(i);
00200 JonasPortComponent jpc = (JonasPortComponent) links.get(pc.getPortComponentName());
00201
00202 PortComponentDesc pcd = PortComponentDescFactory.newInstance(jarCL, pc, jpc, this);
00203
00204 if (!wsdl.hasPort(pcd.getQName())) {
00205 throw new WSDeploymentDescException(getI18n().getMessage(
00206 "ServiceDesc.unknownWSDLPort", pcd.getName(), pcd.getQName()));
00207 }
00208
00209 if (namePCDescBindings.put(pcd.getName(), pcd) != null) {
00210 throw new WSDeploymentDescException(getI18n().getMessage(
00211 "ServiceDesc.portNameAlreadyUsed", pcd.getName()));
00212 }
00213 }
00214
00215
00216 List ports = getPortComponents();
00217
00218
00219 for (int i = 0; i < ports.size(); i++) {
00220 if (ports.get(i) != null) {
00221 PortComponentDesc pcd = (PortComponentDesc) ports.get(i);
00222
00223 if (!wsdl.hasSOAPBinding(pcd.getQName())) {
00224 throw new WSDeploymentDescException(getI18n().getMessage(
00225 "ServiceDesc.noSOAPBinding", pcd.getName(), pcd.getQName()));
00226 }
00227 }
00228 }
00229 }
00230
00235 private boolean isRunningInClientContainer() {
00236 return (System.getProperty("jonas.base") == null);
00237 }
00238
00244 private Map associatePCAndJPC(WebserviceDescription wsd, JonasWebserviceDescription jwsd) {
00245 Map res = new HashMap();
00246
00247 for (Iterator i = wsd.getPortComponentList().iterator(); i.hasNext();) {
00248 PortComponent pc = (PortComponent) i.next();
00249 res.put(pc.getPortComponentName(), null);
00250 }
00251
00252 if (jwsd != null) {
00253
00254
00255 Set keys = res.keySet();
00256
00257
00258 for (Iterator i = jwsd.getJonasPortComponentList().iterator(); i.hasNext();) {
00259 JonasPortComponent jpc = (JonasPortComponent) i.next();
00260 String pcName = jpc.getPortComponentName();
00261
00262 if (keys.contains(pcName)) {
00263
00264 res.put(pcName, jpc);
00265 } else {
00266 String err = "jonas-port-component '" + pcName + "' is not linked to any port-component. It will be ignored.";
00267 logger.log(BasicLevel.WARN, err);
00268 }
00269 }
00270 }
00271 return res;
00272 }
00273
00278 public String getName() {
00279 return name;
00280 }
00281
00286 public MappingFile getMapping() {
00287 return mapping;
00288 }
00289
00294 public WSDLFile getWSDL() {
00295 return wsdl;
00296 }
00297
00301 public String getEndpointURI() {
00302 return endpointURI;
00303 }
00304
00309 public List getPortComponents() {
00310 return new Vector(namePCDescBindings.values());
00311 }
00312
00320 public PortComponentDesc getPortComponent(String pcName) {
00321 return (PortComponentDesc) namePCDescBindings.get(pcName);
00322 }
00323
00327 public String toString() {
00328 StringBuffer sb = new StringBuffer();
00329
00330 sb.append("\n" + getClass().getName());
00331 sb.append("\ngetName()=" + getName());
00332 sb.append("\ngetMapping()=" + getMapping());
00333 sb.append("\ngetWSDL()=" + getWSDL());
00334
00335 for (Iterator i = getPortComponents().iterator(); i.hasNext();) {
00336 sb.append("\ngetPortComponents()=" + ((PortComponentDesc) i.next()).toString());
00337 }
00338
00339 return sb.toString();
00340 }
00341
00345 protected static I18n getI18n() {
00346 return i18n;
00347 }
00348
00352 public File getPublicationDirectory() {
00353 return publicationDirectory;
00354 }
00355
00359 public URL getMappingFileURL() {
00360 return mappingFileURL;
00361 }
00362
00366 public URL getLocalWSDLURL() {
00367 return localWSDLURL;
00368 }
00369 }