栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在运行时以编程方式添加xjc插件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在运行时以编程方式添加xjc插件?

这是该

#generateCode()
方法的实际实现在2.2.11版中的样子

// com.sun.tools.xjc.api.impl.s2j.JAXBModelImpl.javapublic JCodeModel generateCode(Plugin[] extensions,ErrorListener errorListener) {    // we no longer do any pre generation    return outline.getCodeModel();}

如您所见,参数只是被吞没了。

要添加插件,您要访问中

Options
找到的插件,然后在其中
SchemaCompiler
添加插件。另请注意,
parseArgument()
调用应在选项而不是插件上进行。

这是完成此操作的方法:

SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();schemaCompiler.forcePackageName(packageRoot);// JAXB Plugin used to get the proper @Size annotations on all fields.JaxbValidationsPlugins jaxbValidationPlugin = new JaxbValidationsPlugins();// Build up list of options for the plugin.// First option must be the name of the plugin itself.// Options must be prefixed with dashesString[] args = new String[] { "-" + JaxbValidationsPlugins.PLUGIN_OPTION_NAME };// Get the options for the schema compiler, this is where we add plugins.Options schemaCompilerOptions = ((SchemaCompilerImpl) schemaCompiler).getOptions();schemaCompilerOptions.getAllPlugins().add(jaxbValidationPlugin);// Call the parseArgument method on the options, not the plugin// Passing in zero because we want to parse the first argument in the arraytry {    schemaCompilerOptions.parseArgument(args, 0);} catch (BadCommandLineException e1) {    e1.printStackTrace();}InputSource inputSource = new InputSource(schemaFile.toURI().toString());schemaCompiler.parseSchema(inputSource);S2JJAXBModel model = schemaCompiler.bind();JCodeModel jCodeModel = model.generateCode(null, null);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/463807.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号