use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaContainer method generateTypes.
public void generateTypes() throws ToolException {
DataBindingProfile dataBindingProfile = context.get(DataBindingProfile.class);
if (dataBindingProfile == null) {
Message msg = new Message("FOUND_NO_DATABINDING", LOG);
throw new ToolException(msg);
}
dataBindingProfile.initialize(context);
if (passthrough()) {
return;
}
dataBindingProfile.generate(context);
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class AbstractGenerator method parseOutputName.
protected Writer parseOutputName(String packageName, String filename, String ext) throws ToolException {
FileWriterUtil fw = null;
Writer writer = null;
if (wantToKeep() && isCollision(packageName, filename, ext)) {
Message msg = new Message("SKIP_GEN", LOG, packageName + "." + filename + ext);
LOG.log(Level.INFO, msg.toString());
return null;
}
fw = new FileWriterUtil(getOutputDir(), env.get(OutputStreamCreator.class));
try {
if (".java".equals(ext)) {
writer = fw.getWriter(packageName, filename + ext, (String) getEnvironment().get(ToolConstants.CFG_ENCODING));
} else {
writer = fw.getWriter(packageName, filename + ext);
}
} catch (IOException ioe) {
Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, packageName + "." + filename + ext);
throw new ToolException(msg, ioe);
}
return writer;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class PluginLoader method loadPlugin.
public void loadPlugin(String resource) {
try {
LOG.log(Level.FINE, "PLUGIN_LOADING", resource);
loadPlugin(getPlugin(resource));
} catch (JAXBException e) {
Message msg = new Message("PLUGIN_LOAD_FAIL", LOG, resource);
LOG.log(Level.SEVERE, msg.toString());
throw new ToolException(msg, e);
} catch (FileNotFoundException fe) {
Message msg = new Message("PLUGIN_FILE_NOT_FOUND", LOG, resource);
LOG.log(Level.SEVERE, msg.toString());
throw new ToolException(msg, fe);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class PluginLoader method loadFrontEndProfile.
private FrontEndProfile loadFrontEndProfile(String fullClzName) {
FrontEndProfile profile = null;
try {
Class<?> clz = ClassLoaderUtils.loadClass(fullClzName, this.getClass());
profile = (FrontEndProfile) clz.newInstance();
} catch (Exception e) {
Message msg = new Message("FRONTEND_PROFILE_LOAD_FAIL", LOG, fullClzName);
LOG.log(Level.SEVERE, msg.toString());
throw new ToolException(msg, e);
}
return profile;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXBDataBinding method addSchemas.
private void addSchemas(Options opts, SchemaCompiler schemaCompiler, SchemaCollection schemaCollection) {
Set<String> ids = new HashSet<>();
@SuppressWarnings("unchecked") List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
for (ServiceInfo si : serviceList) {
for (SchemaInfo sci : si.getSchemas()) {
String key = sci.getSystemId();
if (ids.contains(key)) {
continue;
}
ids.add(key);
}
}
Bus bus = context.get(Bus.class);
OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
if (ids.contains(key)) {
continue;
}
if (!key.startsWith("file:") && !key.startsWith("jar:")) {
XmlSchemaSerializer xser = new XmlSchemaSerializer();
xser.setExtReg(schemaCollection.getExtReg());
Document[] docs;
try {
docs = xser.serializeSchema(schema, false);
} catch (XmlSchemaSerializerException e) {
throw new RuntimeException(e);
}
Element ele = docs[0].getDocumentElement();
if (context.fullValidateWSDL()) {
String uri = null;
try {
uri = docs[0].getDocumentURI();
} catch (Throwable ex) {
// ignore - DOM level 3
}
validateSchema(ele, uri, catalog, schemaCollection);
}
ele = removeImportElement(ele, key, catalog);
try {
docs[0].setDocumentURI(key);
} catch (Throwable t) {
// ignore - DOM level 3
}
InputSource is = new InputSource((InputStream) null);
// key = key.replaceFirst("#types[0-9]+$", "");
is.setSystemId(key);
is.setPublicId(key);
opts.addGrammar(is);
try {
schemaCompiler.parseSchema(key, createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)));
} catch (XMLStreamException e) {
throw new ToolException(e);
}
}
}
for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
String key = schema.getSourceURI();
String tns = schema.getTargetNamespace();
String ltns = schema.getLogicalTargetNamespace();
// accepting also a null tns (e.g., reported by apache.ws.xmlschema for no-namespace)
if (ids.contains(key) || (tns == null && !StringUtils.isEmpty(ltns))) {
continue;
}
if (key.startsWith("file:") || key.startsWith("jar:")) {
InputStream in = null;
try {
if (key.startsWith("file:")) {
in = Files.newInputStream(new File(new URI(key)).toPath());
} else {
in = new URL(key).openStream();
}
XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
reader = createNoCDATAReader(new LocationFilterReader(reader, catalog));
InputSource is = new InputSource(key);
opts.addGrammar(is);
schemaCompiler.parseSchema(key, reader);
reader.close();
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
addSchemasForServiceInfos(catalog, serviceList, opts, schemaCompiler, schemaCollection);
}
Aggregations