Index: src/main/java/org/ow2/petals/component/framework/su/AbstractServiceUnitManager.java =================================================================== --- src/main/java/org/ow2/petals/component/framework/su/AbstractServiceUnitManager.java (revision 30668) +++ src/main/java/org/ow2/petals/component/framework/su/AbstractServiceUnitManager.java (working copy) @@ -875,6 +875,8 @@ final Provides provides) throws CDKJBIDescriptorException, WSDLException, IOException, JBIException { + boolean bSaveJBI = false; + boolean bSaveWsdl = false; final URL wsdlLocation = getWsdlLocation(handler.getInstallRoot(), provides); final Description wsdlDescription = getWsdlDescription(wsdlLocation, provides); @@ -883,17 +885,8 @@ endpointName = EndpointUtil.generateEndpointName(); // update the provides object to set the real endpoint provides.setEndpointName(endpointName); - final File jbiXmlFile = new File(handler.getInstallRoot(), Constants.Component.META_INF - + File.separator + Constants.Component.JBI_XML); - // update the descriptor of the SU to set the real endpoint - // then, if the SU is restarted, the real endpoint is used - final OutputStream jbiOutputStream = new FileOutputStream(jbiXmlFile); - try { - JBIDescriptorBuilder - .buildXmlJBIdescriptor(handler.getDescriptor(), jbiOutputStream); - } finally { - jbiOutputStream.close(); - } + bSaveJBI = true; + // change arbitrary all the endpoint named 'autogenerate' found to // the given auto-generated value final Service service = wsdlDescription.getService(provides.getServiceName()); @@ -903,21 +896,34 @@ if (autogeneratedEndpoint != null) { autogeneratedEndpoint.setName(endpointName); } + bSaveWsdl = true; } else { throw new JBIException("Failed to find provided service '" + provides.getServiceName() + "' in the WSDL description"); } - // save the endpoint name generated into the original wsdl from the - // su - if (wsdlLocation != null) { - wsdlDescription.deleteImportedDocumentsInWsdl(); - - UtilFactory.getWSDLUtil().convertDescriptionToFile(wsdlDescription, new File( - wsdlLocation.getFile())); - - wsdlDescription.addImportedDocumentsInWsdl(); - } } + + // Update dynamically the service name of the WSDL + final QName originalServiceName = provides.getServiceName(); + final QName newServiceName = this.getServiceName(originalServiceName); + if (newServiceName != null) { + // Update the JBI descriptor with the new service name + provides.setServiceName(newServiceName); + bSaveJBI = true; + + // Update the WSDL with the new service name + final Service wsdlService = wsdlDescription.getService(originalServiceName); + wsdlService.setQName(newServiceName); + bSaveWsdl = true; + } + + // Save changes of JBI descriptor and WSDL + if (bSaveJBI) { + AbstractServiceUnitManager.saveJBI(handler); + } + if (bSaveWsdl) { + AbstractServiceUnitManager.saveWsdl(wsdlLocation, wsdlDescription); + } final Document wsdlDocument = UtilFactory.getWSDLUtil().convertDescriptionToDocument( wsdlDescription); @@ -942,8 +948,41 @@ return ep; } + + private static void saveJBI(final ServiceUnitDataHandler handler) throws CDKJBIDescriptorException, IOException { + final File jbiXmlFile = new File(handler.getInstallRoot(), Constants.Component.META_INF + + File.separator + Constants.Component.JBI_XML); + final OutputStream jbiOutputStream = new FileOutputStream(jbiXmlFile); + try { + JBIDescriptorBuilder + .buildXmlJBIdescriptor(handler.getDescriptor(), jbiOutputStream); + } finally { + jbiOutputStream.close(); + } + } + + private static void saveWsdl(final URL wsdlLocation, final Description wsdlDescription) throws WSDLException { + if (wsdlLocation != null) { + wsdlDescription.deleteImportedDocumentsInWsdl(); + UtilFactory.getWSDLUtil().convertDescriptionToFile(wsdlDescription, new File( + wsdlLocation.getFile())); + + wsdlDescription.addImportedDocumentsInWsdl(); + } + } + /** + * Extension point to update the service name according to the component needs. + * + * @param originalServiceName The service name read from the SU archive + * @return The service name to use, or null if the original service name must be kept. + */ + protected QName getServiceName(final QName originalServiceName) { + return null; + } + + /** * Process the Provides elements. * * @param handler