File outputdir = createOutputDir(file);
Definition def = null;
try {
Writer os = new FileWriterUtil(file.getParent(),
getOutputStreamCreator()).getWriter(file, "UTF-8");
WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(getBus(), getServiceModel());
builder.setUseSchemaImports(this.allowImports());
String name = file.getName();
if (name.endsWith(".wsdl")) {
name = name.substring(0, name.lastIndexOf(".wsdl"));
}
builder.setBaseFileName(name);
Map<String, SchemaInfo> imports = new HashMap<String, SchemaInfo>();
def = builder.build(imports);
wsdlWriter.writeWSDL(def, os);
os.close();
if (def.getImports().size() > 0) {
for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
Definition wsdlDef = wsdlImport.getDefinition();
File wsdlFile = null;
if (!StringUtils.isEmpty(wsdlImport.getLocationURI())) {
wsdlFile = new File(outputdir, wsdlImport.getLocationURI());
} else {
wsdlFile = new File(outputdir, wsdlDef.getQName().getLocalPart() + ".wsdl");
}
OutputStream wsdlOs = null;
try {
wsdlOs = new BufferedOutputStream(new FileOutputStream(wsdlFile));
wsdlWriter.writeWSDL(wsdlDef, wsdlOs);
} finally {
if (wsdlOs != null) {
wsdlOs.close();
}
}