use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToProcessor method parseWSDL.
public void parseWSDL(String wsdlUrl) {
try {
Bus bus = BusFactory.getThreadDefaultBus();
WSDLManager mgr = bus.getExtension(WSDLManager.class);
wsdlDefinition = mgr.getDefinition(wsdlUrl);
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
builder.buildMockServices(wsdlDefinition);
schemas = mgr.getSchemasForDefinition(wsdlDefinition);
// remove this as we're going to be modifying it
mgr.removeDefinition(wsdlDefinition);
} catch (WSDLException we) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
throw new ToolException(msg, we);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXBDataBinding method initialize.
public void initialize(ToolContext c) throws ToolException {
this.context = c;
checkEncoding(c);
SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
Bus bus = context.get(Bus.class);
OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
Options opts = null;
opts = getOptions(schemaCompiler);
hackInNewInternalizationLogic(schemaCompiler, catalog, opts);
ClassCollector classCollector = context.get(ClassCollector.class);
ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector, c.optionSet(ToolConstants.CFG_AUTORESOLVE));
schemaCompiler.setClassNameAllocator(allocator);
listener = new JAXBBindErrorListener(context.isVerbose(), context.getErrorListener());
schemaCompiler.setErrorListener(listener);
// Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
List<InputSource> jaxbBindings = context.getJaxbBindingFile();
SchemaCollection schemas = (SchemaCollection) context.get(ToolConstants.XML_SCHEMA_COLLECTION);
List<String> args = new ArrayList<>();
if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
// hard code to enable jaxb extensions
args.add("-extension");
String name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml";
if (isJAXB22()) {
name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml";
}
URL bindingFileUrl = getClass().getResource(name);
InputSource ins = new InputSource(bindingFileUrl.toString());
opts.addBindFile(ins);
}
if (context.get(ToolConstants.CFG_XJC_ARGS) != null) {
Object o = context.get(ToolConstants.CFG_XJC_ARGS);
if (o instanceof String) {
o = new String[] { (String) o };
}
String[] xjcArgss = (String[]) o;
for (String xjcArgs : xjcArgss) {
StringTokenizer tokenizer = new StringTokenizer(xjcArgs, ",", false);
while (tokenizer.hasMoreTokens()) {
String arg = tokenizer.nextToken();
args.add(arg);
LOG.log(Level.FINE, "xjc arg:" + arg);
}
}
}
if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null || context.get(ToolConstants.CFG_XJC_ARGS) != null) {
try {
// keep parseArguments happy, supply dummy required command-line
// opts
opts.addGrammar(new InputSource("null"));
opts.parseArguments(args.toArray(new String[args.size()]));
} catch (BadCommandLineException e) {
StringBuilder msg = new StringBuilder("XJC reported 'BadCommandLineException' for -xjc argument:");
for (String arg : args) {
msg.append(arg + " ");
}
LOG.log(Level.FINE, msg.toString(), e);
if (opts != null) {
String pluginUsage = getPluginUsageString(opts);
msg.append(System.getProperty("line.separator"));
if (args.contains("-X")) {
throw new ToolException(pluginUsage, e);
}
msg.append(pluginUsage);
}
throw new ToolException(msg.toString(), e);
}
}
if (context.optionSet(ToolConstants.CFG_MARK_GENERATED)) {
// '-mark-generated' attribute to jaxb xjc.
try {
opts.parseArgument(new String[] { "-mark-generated" }, 0);
} catch (BadCommandLineException e) {
LOG.log(Level.SEVERE, e.getMessage());
throw new ToolException(e);
}
}
addSchemas(opts, schemaCompiler, schemas);
addBindingFiles(opts, jaxbBindings, schemas);
parseSchemas(schemaCompiler);
rawJaxbModelGenCode = schemaCompiler.bind();
addedEnumClassToCollector(schemas, allocator);
if (context.get(ToolConstants.CFG_DEFAULT_VALUES) != null) {
String cname = (String) context.get(ToolConstants.CFG_DEFAULT_VALUES);
if (StringUtils.isEmpty(cname)) {
defaultValues = new RandomValueProvider();
} else {
if (cname.charAt(0) == '=') {
cname = cname.substring(1);
}
try {
defaultValues = (DefaultValueProvider) Class.forName(cname).newInstance();
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage());
throw new ToolException(e);
}
}
}
initialized = true;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXBDataBinding method generate.
public void generate(ToolContext c) throws ToolException {
if (!initialized) {
initialize(c);
}
if (rawJaxbModelGenCode == null) {
return;
}
if (c.getErrorListener().getErrorCount() > 0) {
return;
}
try {
String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), context.getExcludePkgList(), (String) context.get(ToolConstants.CFG_ENCODING), context.get(OutputStreamCreator.class));
S2JJAXBModel schem2JavaJaxbModel = rawJaxbModelGenCode;
ClassCollector classCollector = context.get(ClassCollector.class);
for (JClass cls : schem2JavaJaxbModel.getAllObjectFactories()) {
classCollector.getTypesPackages().add(cls._package().name());
}
JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
if (!isSuppressCodeGen()) {
jcodeModel.build(fileCodeWriter);
}
context.put(JCodeModel.class, jcodeModel);
for (String str : fileCodeWriter.getExcludeFileList()) {
context.getExcludeFileList().add(str);
}
return;
} catch (IOException e) {
Message msg = new Message("FAIL_TO_GENERATE_TYPES", LOG);
throw new ToolException(msg, e);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaScriptProcessor method getOutputFile.
private File getOutputFile(String defaultOutputFile) {
String output = (String) context.get(ToolConstants.CFG_OUTPUTFILE);
String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
if (dir == null) {
dir = "./";
}
File result;
if (output != null) {
result = new File(output);
if (!result.isAbsolute()) {
result = new File(new File(dir), output);
}
} else {
result = new File(new File(dir), defaultOutputFile);
}
// rename the exising js
if (result.exists() && !result.renameTo(new File(result.getParent(), result.getName()))) {
throw new ToolException(new Message("OUTFILE_EXISTS", LOG));
}
return result;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXWSContainer method validate.
public void validate(ToolContext env) throws ToolException {
env.put("service.target", getServiceTarget());
env.put("service.superclass", getServiceSuperclass());
super.validate(env);
if (env.containsKey(ToolConstants.CFG_BINDING)) {
String[] bindings = (String[]) env.get(ToolConstants.CFG_BINDING);
URIResolver resolver = null;
for (int i = 0; i < bindings.length; i++) {
try {
resolver = new URIResolver(bindings[i]);
} catch (IOException ioe) {
throw new ToolException(ioe);
}
if (!resolver.isResolved()) {
Message msg = new Message("FILE_NOT_EXIST", LOG, bindings[i]);
throw new ToolException(msg);
}
}
env.put(ToolConstants.CFG_BINDING, bindings);
}
cleanArrays(env, ToolConstants.CFG_ASYNCMETHODS);
cleanArrays(env, ToolConstants.CFG_BAREMETHODS);
cleanArrays(env, ToolConstants.CFG_MIMEMETHODS);
}
Aggregations