|
Apache CXF example source code file (JavaToJSProcessor.java)
The Apache CXF JavaToJSProcessor.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.tools.java2js.processor; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.ws.BindingType; import javax.xml.ws.soap.SOAPBinding; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.common.WSDLConstants; import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.javascript.BasicNameManager; import org.apache.cxf.javascript.JavascriptQueryHandler; import org.apache.cxf.javascript.NamespacePrefixAccumulator; import org.apache.cxf.javascript.service.ServiceJavascriptBuilder; import org.apache.cxf.javascript.types.SchemaJavascriptBuilder; import org.apache.cxf.service.ServiceBuilder; import org.apache.cxf.service.model.SchemaInfo; import org.apache.cxf.service.model.ServiceInfo; import org.apache.cxf.tools.common.Processor; import org.apache.cxf.tools.common.ToolConstants; import org.apache.cxf.tools.common.ToolContext; import org.apache.cxf.tools.common.ToolException; import org.apache.cxf.tools.java2wsdl.processor.internal.ServiceBuilderFactory; import org.apache.cxf.tools.util.AnnotationUtil; public class JavaToJSProcessor implements Processor { private static final Logger LOG = LogUtils.getL7dLogger(JavaToJSProcessor.class); private static final String JAVA_CLASS_PATH = "java.class.path"; private static final Charset UTF8 = Charset.forName("utf-8"); private ToolContext context; 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 { FileOutputStream fileOutputStream = new FileOutputStream(jsFile); if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) { JavascriptQueryHandler.writeUtilsToResponseStream(JavaToJSProcessor.class, fileOutputStream); } OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, UTF8); 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); writer.close(); } catch (FileNotFoundException e) { throw new ToolException(e); } catch (IOException e) { throw new ToolException(e); } System.setProperty(JAVA_CLASS_PATH, oldClassPath); LOG.log(Level.INFO, "RESUME_CP", oldClassPath); } @SuppressWarnings("unchecked") public ServiceBuilder getServiceBuilder() throws ToolException { Object beanFilesParameter = context.get(ToolConstants.CFG_BEAN_CONFIG); List<String> beanDefinitions = new ArrayList Other Apache CXF examples (source code examples)Here is a short list of links related to this Apache CXF JavaToJSProcessor.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.