codegenbean.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 520 行 · 第 1/2 页
JAVA
520 行
}
return baseUri;
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
/**
* Reads the WSDL Object Model from the given location.
*
* @param wsdlURI the filesystem location (full path) of the WSDL file to read in.
* @return the WSDLDescription object containing the WSDL Object Model of the given WSDL file
* @throws IOException on errors reading the WSDL file
*/
public AxisService getAxisService(String wsdlURI) throws Exception {
URL url;
if (wsdlURI.indexOf("://") == -1) {
url = new URL("file", "", wsdlURI);
} else {
url = new URL(wsdlURI);
}
WSDL11ToAxisServiceBuilder builder =
new WSDL11ToAxisServiceBuilder(url.openConnection().getInputStream());
builder.setBaseUri(getBaseUri(wsdlURI));
builder.setCodegen(true);
return builder.populateService();
}
/**
* Converts a single String into a String Array
*
* @param value a single string
* @return an array containing only one element
*/
private String[] getStringArray(String value) {
String[] values = new String[1];
values[0] = value;
return values;
}
public String getWSDLFileName() {
return WSDLFileName;
}
public void setWSDLFileName(String WSDLFileName) {
this.WSDLFileName = WSDLFileName;
}
public boolean isSyncOnly() {
return syncOnly;
}
public void setSyncOnly(boolean syncOnly) {
this.syncOnly = syncOnly;
}
public boolean isAsyncOnly() {
return asyncOnly;
}
public void setAsyncOnly(boolean asyncOnly) {
this.asyncOnly = asyncOnly;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
public boolean isServerSide() {
return serverSide;
}
public void setServerSide(boolean serverSide) {
this.serverSide = serverSide;
}
public boolean isTestcase() {
return testcase;
}
public void setTestcase(boolean testcase) {
this.testcase = testcase;
}
public void generate() throws Exception {
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
try {
if (!"xmlbeans".equals(getDatabindingName())) {
Thread.currentThread().setContextClassLoader(Class.class.getClassLoader());
}
CodeGenConfiguration codegenConfig = new CodeGenConfiguration(fillOptionMap());
codegenConfig.addAxisService(getAxisService(WSDLFileName));
codegenConfig.setWsdlDefinition(wsdlDefinition);
//set the baseURI
codegenConfig.setBaseURI(getBaseUri(WSDLFileName));
new CodeGenerationEngine(codegenConfig).generate();
} catch (Throwable e) {
try {
CodeGenConfiguration codegenConfig = new CodeGenConfiguration(fillOptionMap());
codegenConfig.addAxisService(getAxisService(WSDLFileName));
codegenConfig.setWsdlDefinition(wsdlDefinition);
//set the baseURI
codegenConfig.setBaseURI(getBaseUri(WSDLFileName));
new CodeGenerationEngine(codegenConfig).generate();
} catch (Throwable e1) {
throw new Exception("Code generation failed due to " + e.getLocalizedMessage());
}
} finally {
if (!"xmlbeans".equals(getDatabindingName())) {
Thread.currentThread().setContextClassLoader(tcl);
}
}
}
public void readWSDL() throws WSDLException {
WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
wsdlDefinition = reader.readWSDL(WSDLFileName) ;
}
//get the default package derived by the targetNamespace
public String packageFromTargetNamespace() {
return URLProcessor.makePackageName(wsdlDefinition.getTargetNamespace());
}
/**
* Returns a list of service names
* the names are QNames
*/
public List getServiceList() {
List returnList = new ArrayList();
Service service = null;
Map serviceMap = wsdlDefinition.getServices();
if (serviceMap != null && !serviceMap.isEmpty()) {
Iterator serviceIterator = serviceMap.values().iterator();
while (serviceIterator.hasNext()) {
service = (Service) serviceIterator.next();
returnList.add(service.getQName());
}
}
return returnList;
}
/**
* Returns a list of ports for a particular service
* the names are QNames
*/
public List getPortNameList(QName serviceName) {
List returnList = new ArrayList();
Service service = wsdlDefinition.getService(serviceName);
Port port = null;
if (service != null) {
Map portMap = service.getPorts();
if (portMap != null && !portMap.isEmpty()) {
Iterator portIterator = portMap.values().iterator();
while (portIterator.hasNext()) {
port = (Port) portIterator.next();
returnList.add(port.getName());
}
}
}
return returnList;
}
public Project getActiveProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public File getTemp() {
String time = Calendar.getInstance().getTime().toString().replace(':', '-');
return new File( getOutput() + File.separator + "temp-" + time);
}
public Module[] getModules() {
Project project = getActiveProject();
if (project != null) {
return ModuleManager.getInstance(project).getModules();
}
return null;
}
public String[] getModuleSrc(String name) {
Project project = getActiveProject();
if (project != null) {
Module module = ModuleManager.getInstance(project).findModuleByName(name);
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
VirtualFile virtualFiles[] = moduleRootManager.getSourceRoots();
String src[] = new String[virtualFiles.length];
for (int count = 0; count < src.length; count++) {
src[count] = virtualFiles[count].getPresentableUrl();
}
return src;
}
return null;
}
/*
* Returns the namespace map from definition
* @return
*/
public Collection getDefinitionNamespaceMap(){
Map namespaces = wsdlDefinition.getNamespaces();
return namespaces.values() ;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?