Java Code Examples for org.apache.cxf.service.model.ServiceInfo#getXmlSchemaCollection()

The following examples show how to use org.apache.cxf.service.model.ServiceInfo#getXmlSchemaCollection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
    testUtilities.setBus(getBean(Bus.class, "cxf"));

    testUtilities.initializeRhino();
    testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");

    clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
    client = clientProxyFactory.getClientFactoryBean().create();
    serviceInfos = client.getEndpoint().getService().getServiceInfos();
    // there can only be one.
    assertEquals(1, serviceInfos.size());
    ServiceInfo serviceInfo = serviceInfos.get(0);
    schemata = serviceInfo.getSchemas();
    nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixAccumulator =
        new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixAccumulator, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
        testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
    }
}
 
Example 2
Source File: SourceDataBinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void initialize(Service service) {
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
        if (schemaCollection.getXmlSchemas().length > 1) {
            // Schemas are already populated.
            continue;
        }
        new ServiceModelVisitor(serviceInfo) {
            public void begin(MessagePartInfo part) {
                if (part.getTypeQName() != null || part.getElementQName() != null) {
                    return;
                }
                part.setTypeQName(Constants.XSD_ANYTYPE);
            }
        } .walk();
    }
}
 
Example 3
Source File: StaxDataBinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void initialize(Service service) {
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
        if (schemaCollection.getXmlSchemas().length > 1) {
            // Schemas are already populated.
            continue;
        }
        new ServiceModelVisitor(serviceInfo) {
            public void begin(MessagePartInfo part) {
                if (part.getTypeQName() != null || part.getElementQName() != null) {
                    return;
                }
                part.setTypeQName(Constants.XSD_ANYTYPE);
            }
        } .walk();
    }
}
 
Example 4
Source File: AttributeTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setupClientAndRhino(String clientProxyFactoryBeanId) throws IOException {
    testUtilities.setBus(getBean(Bus.class, "cxf"));

    testUtilities.initializeRhino();
    testUtilities.readResourceIntoRhino("/org/apache/cxf/javascript/cxf-utils.js");

    clientProxyFactory = getBean(JaxWsProxyFactoryBean.class, clientProxyFactoryBeanId);
    client = clientProxyFactory.getClientFactoryBean().create();
    serviceInfos = client.getEndpoint().getService().getServiceInfos();
    // there can only be one.
    assertEquals(1, serviceInfos.size());
    ServiceInfo serviceInfo = serviceInfos.get(0);
    schemata = serviceInfo.getSchemas();
    nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixAccumulator =
        new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixAccumulator, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
        testUtilities.readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
    }
}
 
Example 5
Source File: JavascriptTestUtilities.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void loadJavascriptForService(ServiceInfo serviceInfo) {
    Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
        .getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixManager, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        readStringIntoRhino(allThatJavascript, schema.toString() + ".js");
    }

    ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
                                                                           prefixManager, nameManager);
    serviceBuilder.walk();
    String serviceJavascript = serviceBuilder.getCode();
    readStringIntoRhino(serviceJavascript, serviceInfo.getName() + ".js");
}
 
Example 6
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static boolean isSchemaFormQualified(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = schemaCol.getSchemaForElement(partElement);
    if (schema != null) {
        return schema.getElementFormDefault() == XmlSchemaForm.QUALIFIED;
    }
    return false;

}
 
Example 7
Source File: CorbaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static XmlSchemaType getXmlSchemaType(ServiceInfo serviceInfo, QName name) {
    XmlSchemaType result = null;
    if ((name != null) && (serviceInfo != null)) {
        SchemaCollection col = serviceInfo.getXmlSchemaCollection();
        result = col.getTypeByQName(name);
        if (result == null) {
            //check the name, if it is an element
            XmlSchemaElement el = col.getElementByQName(name);
            if (el != null) {
                result = el.getSchemaType();
            }
        }
    }
    return result;
}
 
Example 8
Source File: SoapBindingFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void addMessageFromBinding(ExtensibilityElement ext, BindingOperationInfo bop,
                                     boolean isInput) {
    SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);

    ServiceInfo serviceInfo = bop.getBinding().getService();

    if (header != null && header.getMessage() == null) {
        throw new RuntimeException("Problem with WSDL: soap:header element"
            + " for operation " + bop.getName() + " under binding " + bop.getBinding().getName()
            + " does not contain a valid message attribute.");
    }

    if (header != null && serviceInfo.getMessage(header.getMessage()) == null) {
        Definition def = (Definition)serviceInfo.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
        SchemaCollection schemas = serviceInfo.getXmlSchemaCollection();

        if (def != null && schemas != null) {
            QName qn = header.getMessage();

            javax.wsdl.Message msg = findMessage(qn, def);
            if (msg != null) {
                addOutOfBandParts(bop, msg, schemas, isInput, header.getPart());
                serviceInfo.refresh();
            } else {
                throw new RuntimeException("Problem with WSDL: soap:header element"
                    + " for operation " + bop.getName()
                    + " is referring to an undefined wsdl:message element: " + qn);
            }
        }
    }
}
 
Example 9
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<WrapperElement> getWrappedElement(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schema = serviceInfo.getXmlSchemaCollection();

    XmlSchemaElement elementByName = schema.getElementByQName(partElement);

    XmlSchemaComplexType type = (XmlSchemaComplexType)elementByName.getSchemaType();

    XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();

    List<WrapperElement> qnames = createWrappedElements(seq);

    //If it's extension
    if (seq == null && type.getContentModel() != null) {
        Object configuredMaxStackDepth = context.get(ToolConstants.CFG_MAX_EXTENSION_STACK_DEPTH);
        Integer maxStackDepth = Integer.valueOf(5);
        if (configuredMaxStackDepth instanceof Integer) {
            maxStackDepth = (Integer)configuredMaxStackDepth;
        } else if (configuredMaxStackDepth instanceof String) {
            maxStackDepth = Integer.valueOf((String)configuredMaxStackDepth);
        }
        qnames.addAll(createWrappedElementsFromExtension(schema, type, maxStackDepth));

    }

    return qnames;
}
 
Example 10
Source File: ValidatorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static SchemaCollection getSchema(final Definition def) {
    ServiceInfo serviceInfo = new ServiceInfo();
    new SchemaUtil(BusFactory.getThreadDefaultBus(),
                   new HashMap<String, Element>()).getSchemas(def,
                                                              serviceInfo);
    return serviceInfo.getXmlSchemaCollection();
}
 
Example 11
Source File: GenericAegisTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateJavascript() throws Exception {
 // Create our service implementation
    GenericGenericClass<String> impl = new GenericGenericClass<>();

    // Create our Server
    ServerFactoryBean svrFactory = new ServerFactoryBean();
    // we sure can't get a .class for the interface, can we?
    svrFactory.setServiceClass(impl.getClass());
    svrFactory.setAddress("http://localhost:" + PORT + "/aegisgeneric");
    svrFactory.setServiceBean(impl);
    Server server = svrFactory.create();
    ServiceInfo serviceInfo = ((EndpointImpl)server.getEndpoint()).getEndpointInfo().getService();
    Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
        .getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixManager, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
    }

    ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
                                                                           prefixManager, nameManager);
    serviceBuilder.walk();
    String serviceJavascript = serviceBuilder.getCode();
    assertNotNull(serviceJavascript);

}
 
Example 12
Source File: JavascriptGetInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void writeResponse(URI uri, Map<String, String> map, OutputStream os, Endpoint serverEndpoint) {
    OutputStreamWriter writer = new OutputStreamWriter(os, UTF_8);
    if (!map.containsKey(NO_UTILS_QUERY_KEY)) {
        writeUtilsToResponseStream(JavascriptGetInterceptor.class, os);
    }
    if (map.containsKey(CODE_QUERY_KEY)) {
        ServiceInfo serviceInfo = serverEndpoint.getService().getServiceInfos().get(0);
        Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
        // we need to move this to the bus.
        BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, serverEndpoint);
        NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
            .getXmlSchemaCollection());
        try {
            for (SchemaInfo schema : schemata) {
                SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
                    .getXmlSchemaCollection(), prefixManager, nameManager);
                String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
                writer.append(allThatJavascript);
            }

            ServiceJavascriptBuilder serviceBuilder
                = new ServiceJavascriptBuilder(serviceInfo,
                                               serverEndpoint.getEndpointInfo().getAddress(),
                                               prefixManager,
                                               nameManager);
            serviceBuilder.walk();
            String serviceJavascript = serviceBuilder.getCode();
            writer.append(serviceJavascript);
            writer.flush();
        } catch (IOException e) {
            throw new UncheckedException(e);
        }
    } else {
        throw new RuntimeException("Invalid query " + uri.toString());
    }
}
 
Example 13
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Code elsewhere in this function will fill in the name of the type of an
 * element but not the reference to the type. This function fills in the
 * type references. This does not set the type reference for elements that
 * are declared as refs to other elements. It is a giant pain to find them,
 * since they are not (generally) root elements and the code would have to
 * traverse all the types to find all of them. Users should look them up
 * through the collection, that's what it is for.
 */
private void fillInSchemaCrossreferences() {
    Service service = getService();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();

        // First pass, fill in any types for which we have a name but no
        // type.
        for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
            Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements();
            for (XmlSchemaElement element : elementsTable.values()) {
                if (element.getSchemaType() == null) {
                    QName typeName = element.getSchemaTypeName();
                    if (typeName != null) {
                        XmlSchemaType type = schemaCollection.getTypeByQName(typeName);
                        if (type == null) {
                            Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element
                                .getQName(), typeName, service.getName());
                            LOG.severe(message.toString());
                        } else {
                            element.setSchemaType(type);
                        }
                    }
                }
            }

        }
    }
}
 
Example 14
Source File: WSDLToJavaScriptProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void process() throws ToolException {
    super.process();

    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    File jsFile = getOutputFile(serviceInfo.getName().getLocalPart() + ".js");

    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
                                                                              .getXmlSchemaCollection());

    Map<String, String> nsPrefixMap =
        CastUtils.cast(
                       context.get(ToolConstants.CFG_JSPREFIXMAP, Map.class),
                       String.class, String.class);

    if (nsPrefixMap != null) {
        for (Map.Entry<String, String> prefixEntry : nsPrefixMap.entrySet()) {
            prefixManager.collect(prefixEntry.getValue(), prefixEntry.getKey());
        }
    }

    try {
        OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
        if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
            JavascriptGetInterceptor.writeUtilsToResponseStream(WSDLToJavaScriptProcessor.class,
                                                                outputStream);
        }

        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF_8);
        try (BufferedWriter writer = new BufferedWriter(outputStreamWriter)) {

            XmlSchemaCollection collection = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection();
            SchemaJavascriptBuilder jsBuilder =
                new SchemaJavascriptBuilder(serviceInfo
                .getXmlSchemaCollection(), prefixManager, nameManager);
            String jsForSchemas = jsBuilder.generateCodeForSchemaCollection(collection);
            writer.append(jsForSchemas);

            ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo,
                                                                                   null,
                                                                                   prefixManager,
                                                                                   nameManager);
            serviceBuilder.walk();
            String serviceJavascript = serviceBuilder.getCode();
            writer.append(serviceJavascript);
        }
    } catch (IOException e) {
        throw new ToolException(e);
    }
}
 
Example 15
Source File: ServiceModelSchemaValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ServiceModelSchemaValidator(ServiceInfo serviceInfo) {
    super(serviceInfo);
    schemaCollection = serviceInfo.getXmlSchemaCollection();
    complaints = new StringBuilder();
}
 
Example 16
Source File: SchemaUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void getSchemas(final Definition def, final ServiceInfo serviceInfo) {
    SchemaCollection schemaCol = serviceInfo.getXmlSchemaCollection();
    getSchemas(def, schemaCol, serviceInfo);
}
 
Example 17
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null
        && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG,
                                                           getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;

    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }

    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());

    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());

    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();

    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());

    sendEvent(Event.SERVICE_SET, getService());

    createInterface(serviceInfo);


    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();

    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }

    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method)opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }

        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }

        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName)fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
 
Example 18
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo, String namespaceURI, boolean qualified) {
    for (SchemaInfo s : serviceInfo.getSchemas()) {
        if (s.getNamespaceURI().equals(namespaceURI)) {
            return s;
        }
    }

    SchemaInfo schemaInfo = new SchemaInfo(namespaceURI);
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    XmlSchema schema = col.getSchemaByTargetNamespace(namespaceURI);

    if (schema != null) {
        schemaInfo.setSchema(schema);
        serviceInfo.addSchema(schemaInfo);
        return schemaInfo;
    }

    schema = col.newXmlSchemaInCollection(namespaceURI);
    if (qualified) {
        schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
    }
    schemaInfo.setSchema(schema);

    Map<String, String> explicitNamespaceMappings = this.getDataBinding().getDeclaredNamespaceMappings();
    if (explicitNamespaceMappings == null) {
        explicitNamespaceMappings = Collections.emptyMap();
    }
    NamespaceMap nsMap = new NamespaceMap();
    for (Map.Entry<String, String> mapping : explicitNamespaceMappings.entrySet()) {
        nsMap.add(mapping.getValue(), mapping.getKey());
    }

    if (!explicitNamespaceMappings.containsKey(WSDLConstants.NS_SCHEMA_XSD)) {
        nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    }
    if (!explicitNamespaceMappings.containsKey(serviceInfo.getTargetNamespace())) {
        nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX, serviceInfo.getTargetNamespace());
    }
    schema.setNamespaceContext(nsMap);
    serviceInfo.addSchema(schemaInfo);
    return schemaInfo;
}
 
Example 19
Source File: JavaScriptContainer.java    From cxf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void execute() throws ToolException {
    if (hasInfoOption()) {
        return;
    }
    buildToolContext();
    validate(context);

    WSDLConstants.WSDLVersion version = getWSDLVersion();

    String wsdlURL = (String)context.get(ToolConstants.CFG_WSDLURL);
    List<ServiceInfo> serviceList = (List<ServiceInfo>)context.get(ToolConstants.SERVICE_LIST);
    if (serviceList == null) {
        serviceList = new ArrayList<>();

        PluginLoader pluginLoader = PluginLoader.newInstance();
        // for JavaScript generation, we always use JAX-WS.
        FrontEndProfile frontend = pluginLoader.getFrontEndProfile("jaxws");

        // Build the ServiceModel from the WSDLModel
        if (version == WSDLConstants.WSDLVersion.WSDL11) {
            AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
            builder.setContext(context);
            builder.setBus(getBus());
            context.put(Bus.class, getBus());
            builder.build(URIParserUtil.getAbsoluteURI(wsdlURL));
            builder.customize();
            Definition definition = builder.getWSDLModel();

            context.put(Definition.class, definition);

            builder.validate(definition);

            WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
            String serviceName = (String)context.get(ToolConstants.CFG_SERVICENAME);

            if (serviceName != null) {
                List<ServiceInfo> services = serviceBuilder.buildServices(definition,
                                                                          getServiceQName(definition));
                serviceList.addAll(services);
            } else if (definition.getServices().size() > 0) {
                serviceList = serviceBuilder.buildServices(definition);
            } else {
                serviceList = serviceBuilder.buildMockServices(definition);
            }

        } else {
            // TODO: wsdl2.0 support
            throw new ToolException("Only WSDL 1.1 supported");
        }
    }
    if (serviceList.isEmpty()) {
        throw new ToolException("Did not find any services in WSDL");
    }
    Map<String, InterfaceInfo> interfaces = new LinkedHashMap<>();

    ServiceInfo service0 = serviceList.get(0);
    SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
    context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
    context.put(ToolConstants.PORTTYPE_MAP, interfaces);
    context.put(ClassCollector.class, new ClassCollector());
    WSDLToJavaScriptProcessor processor = new WSDLToJavaScriptProcessor();

    for (ServiceInfo service : serviceList) {

        context.put(ServiceInfo.class, service);

        validate(service);

        processor.setEnvironment(context);
        processor.process();
    }
}
 
Example 20
Source File: JavaToJSProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void process() throws ToolException {
    String oldClassPath = System.getProperty(JAVA_CLASS_PATH);
    LOG.log(Level.INFO, "OLD_CP", oldClassPath);
    if (context.get(ToolConstants.CFG_CLASSPATH) != null) {
        String newCp = (String)context.get(ToolConstants.CFG_CLASSPATH);
        System.setProperty(JAVA_CLASS_PATH, newCp + File.pathSeparator + oldClassPath);
        LOG.log(Level.INFO, "NEW_CP", newCp);
    }

    // check for command line specification of data binding.

    ServiceBuilder builder = getServiceBuilder();
    ServiceInfo serviceInfo = builder.createService();

    File jsFile = getOutputFile(builder.getOutputFile(), serviceInfo.getName().getLocalPart() + ".js");

    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
        .getXmlSchemaCollection());
    Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
    try {
        OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
        if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
            JavascriptGetInterceptor.writeUtilsToResponseStream(JavaToJSProcessor.class, outputStream);
        }

        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF_8);
        try (BufferedWriter writer = new BufferedWriter(outputStreamWriter)) {

            for (SchemaInfo schema : schemata) {
                SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo
                    .getXmlSchemaCollection(), prefixManager, nameManager);
                String allThatJavascript = jsBuilder.generateCodeForSchema(schema.getSchema());
                writer.append(allThatJavascript);
            }

            ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
                                                                                 prefixManager, nameManager);
            serviceBuilder.walk();
            String serviceJavascript = serviceBuilder.getCode();
            writer.append(serviceJavascript);
        }
    } catch (IOException e) {
        throw new ToolException(e);
    }

    System.setProperty(JAVA_CLASS_PATH, oldClassPath);
    LOG.log(Level.INFO, "RESUME_CP", oldClassPath);
}