codegenwizard.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 591 行 · 第 1/2 页
JAVA
591 行
/*
* 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.tool.codegen.eclipse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import javax.wsdl.Definition;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
import org.apache.axis2.tool.codegen.WSDL2JavaGenerator;
import org.apache.axis2.tool.codegen.eclipse.plugin.CodegenWizardPlugin;
import org.apache.axis2.tool.codegen.eclipse.ui.AbstractWizardPage;
import org.apache.axis2.tool.codegen.eclipse.ui.JavaSourceSelectionPage;
import org.apache.axis2.tool.codegen.eclipse.ui.JavaWSDLOptionsPage;
import org.apache.axis2.tool.codegen.eclipse.ui.JavaWSDLOutputLocationPage;
import org.apache.axis2.tool.codegen.eclipse.ui.OptionsPage;
import org.apache.axis2.tool.codegen.eclipse.ui.OutputPage;
import org.apache.axis2.tool.codegen.eclipse.ui.ToolSelectionPage;
import org.apache.axis2.tool.codegen.eclipse.ui.WSDLFileSelectionPage;
import org.apache.axis2.tool.codegen.eclipse.util.SettingsConstants;
import org.apache.axis2.tool.codegen.eclipse.util.UIConstants;
import org.apache.axis2.tool.codegen.eclipse.util.WSDLPropertyReader;
import org.apache.axis2.tool.core.JarFileWriter;
import org.apache.axis2.tool.core.SrcCompiler;
import org.apache.axis2.util.CommandLineOptionConstants;
import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
import org.apache.axis2.wsdl.codegen.CodeGenerationEngine;
import org.apache.ws.java2wsdl.Java2WSDLCodegenEngine;
import org.apache.ws.java2wsdl.utils.Java2WSDLCommandLineOption;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
/**
* The main wizard for the codegen wizard
*/
public class CodeGenWizard extends Wizard implements INewWizard, Java2WSDLConstants {
private ToolSelectionPage toolSelectionPage;
private WSDLFileSelectionPage wsdlSelectionPage;
private OptionsPage optionsPage;
private OutputPage outputPage;
private JavaWSDLOptionsPage java2wsdlOptionsPage;
private JavaSourceSelectionPage javaSourceSelectionPage;
private JavaWSDLOutputLocationPage java2wsdlOutputLocationPage;
private int selectedWizardType = SettingsConstants.WSDL_2_JAVA_TYPE;//TODO change this
private int selectedCodegenOptionType = SettingsConstants.CODEGEN_DEFAULT_TYPE;//TODO change this
/**
* Constructor for CodeGenWizard.
*/
public CodeGenWizard() {
super();
setNeedsProgressMonitor(true);
this
.setWindowTitle(org.apache.axis2.tool.codegen.eclipse.plugin.CodegenWizardPlugin
.getResourceString("general.name"));
}
/**
* Adding the page to the wizard.
*/
public void addPages() {
toolSelectionPage = new ToolSelectionPage();
addPage(toolSelectionPage);
//add the wsdl2java wizard pages
wsdlSelectionPage = new WSDLFileSelectionPage();
addPage(wsdlSelectionPage);
optionsPage = new OptionsPage();
addPage(optionsPage);
outputPage = new OutputPage();
addPage(outputPage);
//add java2wsdl wizard pages
javaSourceSelectionPage = new JavaSourceSelectionPage();
addPage(javaSourceSelectionPage);
java2wsdlOptionsPage = new JavaWSDLOptionsPage();
addPage(java2wsdlOptionsPage);
java2wsdlOutputLocationPage = new JavaWSDLOutputLocationPage();
addPage(java2wsdlOutputLocationPage);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.wizard.IWizard#canFinish()
*/
public boolean canFinish() {
IWizardPage[] pages = getPages();
AbstractWizardPage wizardPage = null;
for (int i = 0; i < pages.length; i++) {
wizardPage = (AbstractWizardPage) pages[i];
if (wizardPage.getPageType() == this.selectedWizardType) {
if (!(wizardPage.isPageComplete()))
return false;
}
}
return true;
}
public IWizardPage getNextPage(IWizardPage page) {
AbstractWizardPage currentPage = (AbstractWizardPage) page;
AbstractWizardPage pageout = (AbstractWizardPage) super
.getNextPage(page);
while (pageout != null && selectedWizardType != pageout.getPageType()) {
AbstractWizardPage temp = pageout;
pageout = (AbstractWizardPage) super.getNextPage(currentPage);
currentPage = temp;
}
return pageout;
}
/**
* This method is called when 'Finish' button is pressed in the wizard. We
* will create an operation and run it using wizard as execution context.
*/
public boolean performFinish() {
try {
switch (selectedWizardType) {
case SettingsConstants.WSDL_2_JAVA_TYPE:
doFinishWSDL2Java();
break;
case SettingsConstants.JAVA_2_WSDL_TYPE:
doFinishJava2WSDL();
break;
case SettingsConstants.UNSPECIFIED_TYPE:
break; //Do nothing
default:
throw new RuntimeException(CodegenWizardPlugin.
getResourceString("general.invalid.state"));
}
} catch (Exception e) {
MessageDialog.openError(getShell(),
CodegenWizardPlugin.getResourceString("general.Error"),
CodegenWizardPlugin.getResourceString("general.Error.prefix") +
e.getMessage());
return false;
}
MessageDialog.openInformation(this.getShell(),
CodegenWizardPlugin
.getResourceString("general.name"), CodegenWizardPlugin
.getResourceString("wizard.success"));
return true;
}
/**
* The worker method, generates the code itself.
*/
private void doFinishWSDL2Java() {
WorkspaceModifyOperation op = new WorkspaceModifyOperation()
{
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException, InterruptedException{
if (monitor == null)
monitor = new NullProgressMonitor();
/*
* "3" is the total amount of steps, see below monitor.worked(amount)
*/
monitor.beginTask(CodegenWizardPlugin.getResourceString("generator.generating"), 3);
try
{
/*
* TODO: Introduce a progress monitor interface for CodeGenerationEngine.
* Since this monitor here doesn't make much sense, we
* should either remove the progress monitor from the CodeGenWizard,
* or give a (custom) progress monitor to the generate() method, so
* we will be informed by Axis2 about the progress of code generation.
*/
WSDL2JavaGenerator generator = new WSDL2JavaGenerator();
monitor.subTask(CodegenWizardPlugin.getResourceString("generator.readingWOM"));
AxisService service = generator.getAxisService(wsdlSelectionPage.getFileName());
monitor.worked(1);
//The generate all fix (Axis2-1862)
boolean isServerside,isServiceXML,isGenerateServerSideInterface = false;
if (optionsPage.getGenerateAll()){
isServerside = true;
isServiceXML = true;
isGenerateServerSideInterface = true;
}else{
isServerside = optionsPage.isServerside();
isServiceXML =optionsPage.isServerXML();
isGenerateServerSideInterface = optionsPage.getGenerateServerSideInterface();
}
Map optionsMap = generator.fillOptionMap(optionsPage.isAsyncOnlyOn(),
optionsPage.isSyncOnlyOn(),
isServerside,
isServiceXML,
optionsPage.isGenerateTestCase(),
optionsPage.getGenerateAll(),
optionsPage.getServiceName(),
optionsPage.getPortName(),
optionsPage.getDatabinderName(),
wsdlSelectionPage.getFileName(),
optionsPage.getPackageName(),
optionsPage.getSelectedLanguage(),
outputPage.getOutputLocation(),
optionsPage.getNs2PkgMapping(),
isGenerateServerSideInterface);
//Fix for the CodeGenConfiguration Contructor Change
//CodeGenConfiguration codegenConfig = new CodeGenConfiguration(service, optionsMap);
CodeGenConfiguration codegenConfig = new CodeGenConfiguration(optionsMap);
codegenConfig.addAxisService(service);
//set the wsdl definision for codegen config for skeleton generarion.
WSDLPropertyReader reader = new WSDLPropertyReader();
reader.readWSDL(wsdlSelectionPage.getFileName());
Definition wsdlDefinition = reader.getWsdlDefinition();
codegenConfig.setWsdlDefinition(wsdlDefinition);
//set the baseURI
codegenConfig.setBaseURI(generator.getBaseUri(wsdlSelectionPage.getFileName()));
monitor.worked(1);
monitor.subTask(CodegenWizardPlugin.getResourceString("generator.generating"));
new CodeGenerationEngine(codegenConfig).generate();
//TODO refresh the eclipse project space to show the generated files
//Add the codegen libs that are coming with the plugin to the project lib that has been created
if (outputPage.getAxis2PluginLibCopyCheckBoxSelection()){
String eclipseHome = System.getProperty("user.dir");
String pluginLibLocation = eclipseHome+File.separator+UIConstants.PLUGINS+
File.separator+UIConstants.AXIS_CODEGEN_PLUGIN_FOLDER+
File.separator+UIConstants.LIB;
addLibsToProjectLib(pluginLibLocation, outputPage.getOutputLocation());
}
//Also another requirement arises
//If the codegen project was newly buided project or else the eclipse
//project intended to save this generated code does not have the required libs
//to compile the generated code. We need to add the relevent libs to a lib directory
//of the <code>outputPage.getOutputLocation()</code>
//Add the libraries on the plugin lib directory to the created project lib
if (outputPage.getAxisLibCopyCheckBoxSelection() && outputPage.oktoLoadLibs()){
// String libDirectory = outputPage.getAxisHomeLocation()+File.separator+
// UIConstants.TARGET+File.separator+UIConstants.LIB;
String libDirectory = outputPage.getAxisJarsLocation();
addLibsToProjectLib(libDirectory, outputPage.getOutputLocation());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?