这是该
#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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)