Search in sources :

Example 1 with SchemaJavascriptBuilder

use of org.apache.cxf.javascript.types.SchemaJavascriptBuilder in project cxf by apache.

the class JavascriptTestUtilities method loadJavascriptForService.

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");
}
Also used : ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder)

Example 2 with SchemaJavascriptBuilder

use of org.apache.cxf.javascript.types.SchemaJavascriptBuilder in project cxf by apache.

the class JavascriptGetInterceptor method writeResponse.

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());
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder)

Example 3 with SchemaJavascriptBuilder

use of org.apache.cxf.javascript.types.SchemaJavascriptBuilder in project cxf by apache.

the class WSDLToJavaScriptProcessor method process.

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);
    }
}
Also used : ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) OutputStream(java.io.OutputStream) IOException(java.io.IOException) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) BufferedWriter(java.io.BufferedWriter) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BasicNameManager(org.apache.cxf.javascript.BasicNameManager) OutputStreamWriter(java.io.OutputStreamWriter) ToolException(org.apache.cxf.tools.common.ToolException) NamespacePrefixAccumulator(org.apache.cxf.javascript.NamespacePrefixAccumulator) File(java.io.File) Map(java.util.Map)

Example 4 with SchemaJavascriptBuilder

use of org.apache.cxf.javascript.types.SchemaJavascriptBuilder in project cxf by apache.

the class GenericAegisTest method testGenerateJavascript.

// the claim is that code generation makes this go boom.
@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);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) Server(org.apache.cxf.endpoint.Server) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) GenericGenericClass(org.apache.cxf.javascript.fortest.GenericGenericClass) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder) Test(org.junit.Test)

Example 5 with SchemaJavascriptBuilder

use of org.apache.cxf.javascript.types.SchemaJavascriptBuilder in project cxf by apache.

the class JavaToJSProcessor method process.

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);
}
Also used : ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ServiceBuilder(org.apache.cxf.service.ServiceBuilder) BufferedWriter(java.io.BufferedWriter) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BasicNameManager(org.apache.cxf.javascript.BasicNameManager) OutputStreamWriter(java.io.OutputStreamWriter) ToolException(org.apache.cxf.tools.common.ToolException) NamespacePrefixAccumulator(org.apache.cxf.javascript.NamespacePrefixAccumulator) File(java.io.File) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Aggregations

ServiceJavascriptBuilder (org.apache.cxf.javascript.service.ServiceJavascriptBuilder)5 SchemaJavascriptBuilder (org.apache.cxf.javascript.types.SchemaJavascriptBuilder)5 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)4 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 IOException (java.io.IOException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 OutputStream (java.io.OutputStream)2 BasicNameManager (org.apache.cxf.javascript.BasicNameManager)2 NamespacePrefixAccumulator (org.apache.cxf.javascript.NamespacePrefixAccumulator)2 ToolException (org.apache.cxf.tools.common.ToolException)2 Map (java.util.Map)1 UncheckedException (org.apache.cxf.common.i18n.UncheckedException)1 Server (org.apache.cxf.endpoint.Server)1 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)1 GenericGenericClass (org.apache.cxf.javascript.fortest.GenericGenericClass)1 ServiceBuilder (org.apache.cxf.service.ServiceBuilder)1 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)1 Test (org.junit.Test)1