codegenbean.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 520 行 · 第 1/2 页
JAVA
520 行
/*
* 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.axis2.tools.bean;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
import org.apache.axis2.util.URLProcessor;
import org.apache.axis2.util.CommandLineOptionConstants;
import org.apache.axis2.util.CommandLineOption;
import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
import org.apache.axis2.wsdl.codegen.CodeGenerationEngine;
import javax.wsdl.Definition;
import javax.wsdl.Port;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
public class CodegenBean {
private String WSDLFileName =null ;
private String output = ".";
private String packageName = URLProcessor.DEFAULT_PACKAGE;
private String language = "java";
private boolean asyncOnly = false;
private boolean syncOnly = false;
private boolean serverSide = false;
private boolean testcase = true;
private boolean isServerXML;
private boolean isGenerateAll;
private boolean isTestCase;
private String serviceName;
private String portName;
private String databindingName;
private String namespace2packageList;
private Definition wsdlDefinition = null;
private boolean defaultClient = true;
private Project project;
private boolean isServerSideInterface = true;
public void setNamespace2packageList(String namespace2packageList) {
this.namespace2packageList = namespace2packageList;
}
public boolean isServerSideInterface() {
return isServerSideInterface;
}
public void setServerSideInterface(boolean serverSideInterface) {
isServerSideInterface = serverSideInterface;
}
public boolean isDefaultClient() {
return defaultClient;
}
public void setDefaultClient(boolean defaultClient) {
this.defaultClient = defaultClient;
}
public boolean isServerXML() {
return isServerXML;
}
public void setServerXML(boolean serverXML) {
isServerXML = serverXML;
}
public boolean isGenerateAll() {
return isGenerateAll;
}
public void setGenerateAll(boolean generateAll) {
isGenerateAll = generateAll;
}
public boolean isTestCase() {
return isTestCase;
}
public void setTestCase(boolean testCase) {
isTestCase = testCase;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getPortName() {
return portName;
}
public void setPortName(String portName) {
this.portName = portName;
}
public String getDatabindingName() {
return databindingName;
}
public void setDatabindingName(String databindingName) {
this.databindingName = databindingName;
}
/**
* Maps a string containing the name of a language to a constant defined in CommandLineOptionConstants.LanguageNames
*
* @param UILangValue a string containg a language, e.g. "java", "cs", "cpp" or "vb"
* @return a normalized string constant
*/
private String mapLanguagesWithCombo(String UILangValue) {
return UILangValue;
}
/**
* Creates a list of parameters for the code generator based on the decisions made by the user on the OptionsPage
* (page2). For each setting, there is a Command-Line option for the Axis2 code generator.
*
* @return a Map with keys from CommandLineOptionConstants with the values entered by the user on the Options Page.
*/
public Map fillOptionMap() {
Map optionMap = new HashMap();
//WSDL file name
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.WSDL_LOCATION_URI_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.WSDL_LOCATION_URI_OPTION, getStringArray(WSDLFileName)));
//Async only
if (asyncOnly) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.CODEGEN_ASYNC_ONLY_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.CODEGEN_ASYNC_ONLY_OPTION, new String[0]));
}
//sync only
if (syncOnly) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.CODEGEN_SYNC_ONLY_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.CODEGEN_SYNC_ONLY_OPTION, new String[0]));
}
//serverside
if (serverSide) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION, new String[0]));
//server xml
if (isServerXML) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_SERVICE_DESCRIPTION_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_SERVICE_DESCRIPTION_OPTION, new String[0]));
}
if (isGenerateAll) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_ALL_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_ALL_OPTION, new String[0]));
}
if (isServerSideInterface ) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION, new String[0]));
}
}
//test case
if (isTestCase) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION, new String[0]));
}
//package name
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.PACKAGE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.PACKAGE_OPTION, getStringArray(packageName)));
//selected language
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.STUB_LANGUAGE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.STUB_LANGUAGE_OPTION, getStringArray(mapLanguagesWithCombo(language))));
//output location
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.OUTPUT_LOCATION_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.OUTPUT_LOCATION_OPTION, getStringArray(output)));
//databinding
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.DATA_BINDING_TYPE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.DATA_BINDING_TYPE_OPTION, getStringArray(databindingName)));
//port name
if (portName != null) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION, getStringArray(portName)));
}
//service name
if (serviceName != null) {
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION, getStringArray(serviceName)));
}
//server side interface mapping
if (isServerSideInterface){
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION, new String[0]));
}
//ns2pkg mapping
if (namespace2packageList!= null){
optionMap.put(CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION, new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION, getStringArray(namespace2packageList)));
}
return optionMap;
}
public String getBaseUri(String wsdlURI) {
try {
URL url;
if (wsdlURI.indexOf("://") == -1) {
url = new URL("file", "", wsdlURI);
} else {
url = new URL(wsdlURI);
}
String baseUri;
if ("file".equals(url.getProtocol())) {
baseUri = new File(url.getFile()).getParentFile().toURL().toExternalForm();
} else {
baseUri = url.toExternalForm().substring(0,
url.toExternalForm().lastIndexOf("/")
);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?