use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLGeneratorFactory method newGenerator.
public AbstractGenerator<?> newGenerator() {
AbstractGenerator<?> generator = null;
String clzName = getGeneratorClassName();
try {
generator = (AbstractGenerator<?>) Class.forName(clzName).newInstance();
} catch (Exception e) {
throw new ToolException("Can not find the Generator for: " + clzName, e);
}
return generator;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDL11Generator method generate.
public Definition generate(final File dir) {
File file = getOutputBase();
if (file == null && dir != null) {
if (dir.isDirectory()) {
file = new File(dir, getServiceModel().getName().getLocalPart() + ".wsdl");
} else {
file = dir;
}
} else if (dir == null) {
file = new File(getServiceModel().getName().getLocalPart() + ".wsdl");
}
File outputdir = createOutputDir(file);
Definition def = null;
try {
Writer os = new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, StandardCharsets.UTF_8.name());
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<>();
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");
}
try (OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()))) {
wsdlWriter.writeWSDL(wsdlDef, wsdlOs);
}
}
}
for (Map.Entry<String, SchemaInfo> imp : imports.entrySet()) {
File impfile = new File(file.getParentFile(), imp.getKey());
Element el = imp.getValue().getElement();
updateImports(el, imports);
FileWriterUtil fileWriterUtil = new FileWriterUtil(impfile.getParent(), getToolContext().get(OutputStreamCreator.class));
os = fileWriterUtil.getWriter(impfile, StandardCharsets.UTF_8.name());
StaxUtils.writeTo(el, os, 2);
os.close();
}
customizing(outputdir, name, imports.keySet());
} catch (WSDLException wex) {
wex.printStackTrace();
} catch (FileNotFoundException fnfe) {
throw new ToolException("Output file " + file + " not found", fnfe);
} catch (IOException e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
return def;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JavaMethod method addParameter.
public void addParameter(JavaParameter param) {
if (hasParameter(param.getName())) {
JavaParameter paramInList = getParameter(param.getName());
if (isEquiv(paramInList.getClassName(), param.getClassName()) && paramInList.isIN() || paramInList.isINOUT()) {
// removeParameter(paramInList);
replaceParameter(paramInList, param);
return;
}
Message message = new Message("PARAMETER_ALREADY_EXIST", LOG, param.getName(), getName(), paramInList.getType(), param.getType());
throw new ToolException(message);
}
if (param.getType() == null && param.getClassName() == null) {
Message msg = new Message("FAIL_TO_CREATE_JAVA_PARAMETER", LOG, param.name, this.getName());
throw new ToolException(msg);
}
param.setMethod(this);
parameters.add(param);
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class AbstractToolContainer method init.
public void init() throws ToolException {
// initialize
if (toolspec == null) {
Message message = new Message("TOOLSPEC_NOT_INITIALIZED", LOG);
LOG.log(Level.SEVERE, message.toString());
throw new ToolException(message);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class AbstractToolContainer method getBus.
public Bus getBus() {
Bus bus = BusFactory.getDefaultBus();
OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);
String catalogLocation = getCatalogURL();
if (!StringUtils.isEmpty(catalogLocation)) {
try {
catalogManager.loadCatalog(new URI(catalogLocation).toURL());
} catch (Exception e) {
e.printStackTrace(err);
throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG, catalogLocation));
}
}
return bus;
}
Aggregations