FileDocCategorySizeDatePackage
ServiceChannelWSDLGenerator.javaAPI DocExample5905Fri Jul 06 12:07:48 BST 2007com.sun.xml.ws.transport.tcp.servicechannel

ServiceChannelWSDLGenerator

public final class ServiceChannelWSDLGenerator extends Object

Fields Summary
private static final String
TCP_ENDPOINT_ADDRESS_STUB
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    
            
        final QName serviceName = WSEndpoint.getDefaultServiceName(ServiceChannelWSImpl.class);
        final QName portName = WSEndpoint.getDefaultPortName(serviceName, ServiceChannelWSImpl.class);
        final BindingID bindingId = BindingID.parse(ServiceChannelWSImpl.class);
        final WSBinding binding = bindingId.createBinding();
        final Collection<SDDocumentSource> docs = new ArrayList<SDDocumentSource>(0);
        
        final WSEndpoint<?> endpoint = WSEndpoint.create(
                ServiceChannelWSImpl.class, true,
                null,
                serviceName, portName, null, binding,
                null, docs, (URL) null
                );
        
        final DocumentAddressResolver resolver = new DocumentAddressResolver() {
            public String getRelativeAddressFor(SDDocument current, SDDocument referenced) {
                if (current.isWSDL() && referenced.isSchema() && referenced.getURL().getProtocol().equals("file")) {
                    return referenced.getURL().getFile().substring(1);
                }
                
                return referenced.getURL().toExternalForm();
            }
        };
        
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();

        /* seems now transformer doesnt support "pretty-output",
        but may be for future using it will make sense */
        final TransformerFactory tFactory =
                TransformerFactory.newInstance();
        final Transformer transformer = tFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT,"yes");
        
        for(final Iterator<SDDocument> it = endpoint.getServiceDefinition().iterator(); it.hasNext();) {
            final SDDocument document = it.next();
            baos.reset();
            
            document.writeTo(new PortAddressResolver() {
                public @Nullable String getAddressFor(QName serviceName, @NotNull String portName) {
                    return TCP_ENDPOINT_ADDRESS_STUB;
                }
            }, resolver, baos);
            final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            
            final FileOutputStream fos = new FileOutputStream("./etc/" + document.getURL().getFile());
            final Source source = new StreamSource(bais);
            final StreamResult result = new StreamResult(fos);
            transformer.transform(source, result);
            fos.close();
            bais.close();
        }
        
        baos.close();