| 1 19 package org.netbeans.modules.j2ee.sun.share.configbean.services; 20 21 import java.beans.PropertyVetoException ; 22 import java.io.File ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException; 26 27 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageSecurityBinding; 28 import org.netbeans.modules.j2ee.sun.dd.api.common.PortInfo; 29 import org.netbeans.modules.j2ee.sun.dd.api.common.WebserviceEndpoint; 30 import org.netbeans.modules.j2ee.sun.dd.api.common.WsdlPort; 31 import org.netbeans.modules.j2ee.sun.dd.api.services.MessageSecurityProvider; 32 import org.netbeans.modules.j2ee.sun.share.configbean.ServiceRef; 33 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration; 34 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 35 import org.netbeans.modules.j2ee.sun.share.configbean.WebServiceDescriptor; 36 import org.netbeans.modules.j2ee.sun.share.configbean.WebServices; 37 import org.openide.ErrorManager; 38 39 40 44 public class MessageSecurityProviderImpl implements MessageSecurityProvider { 45 46 public MessageSecurityProviderImpl() { 47 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "MessageSecurityProvider implementation created."); 48 } 49 50 55 public MessageSecurityBinding getEndpointBinding(File sunDD, String endpointName, String portName) { 56 MessageSecurityBinding result = null; 57 58 validateEndpointParams(endpointName, portName); 60 61 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 63 64 WebServices wsRoot = config.getWebServicesRoot(); 66 if(wsRoot != null) { 67 WebServiceDescriptor wsBean = wsRoot.getWebServiceDescriptor(endpointName); 68 if(wsBean != null) { 69 WebserviceEndpoint endpoint = wsBean.getWebServiceEndpoint(portName); 71 if(endpoint != null) { 72 MessageSecurityBinding binding; 73 try { 74 binding = endpoint.getMessageSecurityBinding(); 75 if(binding != null) { 76 result = (MessageSecurityBinding) binding.clone(); 79 } 80 } catch (VersionNotSupportedException ex) { 81 } 83 } 84 } 85 } 86 87 return result; 88 } 89 90 92 public boolean setEndpointBinding(File sunDD, String endpointName, String portName, MessageSecurityBinding binding) { 93 boolean result = false; 94 95 validateEndpointParams(endpointName, portName); 97 98 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 100 101 WebServices wsRoot = config.getWebServicesRoot(); 103 if(wsRoot != null) { 104 WebServiceDescriptor wsBean = wsRoot.getWebServiceDescriptor(endpointName); 105 if(wsBean != null) { 106 try { 107 wsBean.setMessageSecurityBinding(portName, binding); 109 result = true; 110 } catch (VersionNotSupportedException ex) { 111 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 113 } catch (PropertyVetoException ex) { 114 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 116 } 117 } 118 } 119 120 return result; 121 } 122 123 133 public MessageSecurityBinding getServiceRefBinding(File sunDD, String serviceRefName) { 134 MessageSecurityBinding result = null; 135 136 validateServiceRefParams(serviceRefName); 138 139 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 141 142 ServiceRef serviceRef = Utils.findServiceRef(config, serviceRefName); 144 if(serviceRef != null) { 145 List portInfoList = serviceRef.getPortInfos(); 149 if(portInfoList.size() > 0) { 150 PortInfo portInfo = (PortInfo) portInfoList.get(0); 151 MessageSecurityBinding binding; 152 try { 153 binding = portInfo.getMessageSecurityBinding(); 154 if(binding != null) { 155 result = binding; 156 } 157 } catch (VersionNotSupportedException ex) { 158 } 160 } 161 } 162 163 return result; 164 } 165 166 169 public MessageSecurityBinding getServiceRefBinding(File sunDD, String serviceRefName, 170 String namespaceURI, String localpart) { 171 MessageSecurityBinding result = null; 172 173 validateServiceRefParams(serviceRefName, namespaceURI, localpart); 175 176 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 178 179 ServiceRef serviceRef = Utils.findServiceRef(config, serviceRefName); 181 if(serviceRef != null) { 182 List portInfoList = serviceRef.getPortInfos(); 183 Iterator iter = portInfoList.iterator(); 184 while(iter.hasNext()) { 185 PortInfo portInfo = (PortInfo) iter.next(); 186 WsdlPort port = portInfo.getWsdlPort(); 187 if(port != null && namespaceURI.equals(port.getNamespaceURI()) && localpart.equals(port.getLocalpart())) { 188 MessageSecurityBinding binding; 189 try { 190 binding = portInfo.getMessageSecurityBinding(); 191 if(binding != null) { 192 result = binding; 193 } 194 } catch (VersionNotSupportedException ex) { 195 } 197 break; 198 } 199 } 200 } 201 202 return result; 203 } 204 205 216 public boolean setServiceRefBinding(File sunDD, String serviceRefName, MessageSecurityBinding binding) { 217 boolean result = false; 218 219 validateServiceRefParams(serviceRefName); 221 222 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 224 225 ServiceRef serviceRef = Utils.findServiceRef(config, serviceRefName); 227 if(serviceRef != null) { 228 try { 229 serviceRef.setMessageSecurityBinding(binding); 232 result = true; 233 } catch (VersionNotSupportedException ex) { 234 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 236 } catch (PropertyVetoException ex) { 237 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 239 } 240 } 241 242 return result; 243 } 244 245 253 public boolean setServiceRefBinding(File sunDD, String serviceRefName, String namespaceURI, 254 String localpart, MessageSecurityBinding binding) { 255 boolean result = false; 256 257 validateServiceRefParams(serviceRefName, namespaceURI, localpart); 259 260 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 262 263 ServiceRef serviceRef = Utils.findServiceRef(config, serviceRefName); 265 if(serviceRef != null) { 266 try { 267 serviceRef.setMessageSecurityBinding(namespaceURI, localpart, binding); 268 result = true; 269 } catch (VersionNotSupportedException ex) { 270 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 272 } catch (PropertyVetoException ex) { 273 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 275 } 276 } 277 278 return result; 279 } 280 281 283 public MessageSecurityBinding newMessageSecurityBinding(File sunDD) { 284 SunONEDeploymentConfiguration config = getConfiguration(sunDD); 285 return config.getStorageFactory().createMessageSecurityBinding(); 286 } 287 288 290 322 324 private SunONEDeploymentConfiguration getConfiguration(File sunDD) { 325 SunONEDeploymentConfiguration cachedDC = SunONEDeploymentConfiguration.getConfiguration(sunDD); 326 327 if(sunDD == null) { 328 throw new IllegalArgumentException ("Deployment descriptor file reference cannot be null."); } 330 331 if(cachedDC == null) { 333 throw new IllegalStateException ("No Sun deployment configuration found for descriptor " + sunDD.getPath()); } 335 336 return cachedDC; 337 } 338 339 private void validateEndpointParams(String endpointName, String portName) { 340 if(!Utils.notEmpty(endpointName)) { 341 throw new IllegalArgumentException ("Web service description name cannot be empty or null."); } 343 if(!Utils.notEmpty(portName)) { 344 throw new IllegalArgumentException ("Web service port name cannot be empty or null."); } 346 } 347 348 private void validateServiceRefParams(String serviceRefName) { 349 if(!Utils.notEmpty(serviceRefName)) { 350 throw new IllegalArgumentException ("Web service reference name cannot be empty or null."); } 352 } 353 354 private void validateServiceRefParams(String serviceRefName, String namespaceURI, String localpart) { 355 if(!Utils.notEmpty(serviceRefName)) { 356 throw new IllegalArgumentException ("Web service reference name cannot be empty or null."); } 358 if(!Utils.notEmpty(namespaceURI)) { 359 throw new IllegalArgumentException ("Wsdl-port namespaceURI for service-ref cannot be empty or null."); } 361 if(!Utils.notEmpty(localpart)) { 362 throw new IllegalArgumentException ("Wsdl-port localpart for service-ref cannot be empty or null."); } 364 } 365 366 private WebserviceEndpoint getEndpoint(SunONEDeploymentConfiguration config, String endpointName, String portName) { 367 WebserviceEndpoint endpoint = null; 368 369 WebServices wsRoot = config.getWebServicesRoot(); 370 if(wsRoot != null) { 371 WebServiceDescriptor wsBean = wsRoot.getWebServiceDescriptor(endpointName); 372 if(wsBean != null) { 373 endpoint = wsBean.getWebServiceEndpoint(portName); 375 } 376 } 377 378 return endpoint; 379 } 380 381 } 382 | Popular Tags |