import com.sun.codemodel.*; import com.sun.tools.xjc.api.*; import org.xml.sax.InputSource; // Configure sources & output String schemaPath = "path/to/schema.xsd"; String outputDirectory = "schema/output/source/"; // Setup schema compiler SchemaCompiler sc = XJC.createSchemaCompiler(); sc.forcePackageName("com.xyz.schema.generated"); // Setup SAX InputSource File schemaFile = new File(schemaPath); InputSource is = new InputSource(new FileInputStream(schemaFile)); is.setSystemId(schemaFile.getAbsolutePath()); // Parse & build sc.parseSchema(is); S2JJAXBModel model = sc.bind(); JCodeModel jCodeModel = model.generateCode(null, null); jCodeModel.build(new File(outputDirectory));
SchemaCompiler sc = XJC.createSchemaCompiler(); File file = null; file = new File("Item.xsd"); sc.parseSchema(new InputSource(file.toURI().toString())); S2JJAXBModel model = sc.bind(); JCodeModel cm = model.generateCode(null, null); cm.build(new File("."));
SchemaCompiler sc = XJC.createSchemaCompiler(); File file = new File("D:\\my-dir\\my-schema.xsd"); sc.setErrorListener(... ); sc.parseSchema(new InputSource(file.toURI().toString())); S2JJAXBModel model = sc.bind(); JCodeModel cm = model.generateCode(null, null); cm.build(new File("."));
JCodeModel jCodeModel = model.generateCode(null, null); jCodeModel.build(new File(outputDirectory));
System.exit(1); JCodeModel codeModel = model.generateCode(null, errorListener); codeModel.build(dir);
System.exit(1); JCodeModel codeModel = model.generateCode(null, errorListener); codeModel.build(dir);
private void generateTypes() throws ToolException { if (rawJaxbModelGenCode == null) { return; } try { if (rawJaxbModelGenCode instanceof S2JJAXBModel) { S2JJAXBModel schem2JavaJaxbModel = (S2JJAXBModel)rawJaxbModelGenCode; JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null); String dir = (String)env.get(ToolConstants.CFG_OUTPUTDIR); FileCodeWriter fileCodeWriter = new FileCodeWriter(new File(dir)); jcodeModel.build(fileCodeWriter); } else { return; } } catch (IOException e) { Message msg = new Message("FAIL_TO_GENERATE_TYPES", LOG); throw new ToolException(msg); } }
JCodeModel codeModel = model.generateCode(new Plugin[0], null);
S2JJAXBModel model = sc.bind(); JCodeModel cm = model.generateCode(null, null); cm.build(new File("."));
throw new GenerationException("Error generating JAXB model."); jaxbModel = model.generateCode(null, er);
S2JJAXBModel model = sc.bind(); JCodeModel cm = model.generateCode(null, null); cm.build(new File("."));
schemaCompliler.parseSchema(inputSource); S2JJAXBModel jaxbModel = schemaCompliler.bind(); JCodeModel codeModel = jaxbModel.generateCode(null, null); try { codeModel.build(new FileCodeWriter(outputDir));
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 dashes String[] 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 array try { 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);
protected void bind(){ S2JJAXBModel rawJaxbModel = schemaCompiler.bind(); if(rawJaxbModel == null) throw new AbortException(); options.setCodeModel(rawJaxbModel.generateCode(null, errReceiver)); jaxbModel = new JAXBModel(rawJaxbModel); jaxbModel.setGeneratedClassNames(_classNameAllocator.getJaxbGeneratedClasses()); }
protected void bind(){ S2JJAXBModel rawJaxbModel = schemaCompiler.bind(); if(rawJaxbModel == null) throw new AbortException(); options.setCodeModel(rawJaxbModel.generateCode(null, errReceiver)); jaxbModel = new JAXBModel(rawJaxbModel); jaxbModel.setGeneratedClassNames(_classNameAllocator.getJaxbGeneratedClasses()); }
protected void bind(){ S2JJAXBModel rawJaxbModel = schemaCompiler.bind(); if(rawJaxbModel == null) throw new AbortException(); options.setCodeModel(rawJaxbModel.generateCode(null, errReceiver)); jaxbModel = new JAXBModel(rawJaxbModel); jaxbModel.setGeneratedClassNames(_classNameAllocator.getJaxbGeneratedClasses()); }
protected void bind(){ S2JJAXBModel rawJaxbModel = schemaCompiler.bind(); if(rawJaxbModel == null) throw new AbortException(); options.setCodeModel(rawJaxbModel.generateCode(null, errReceiver)); jaxbModel = new JAXBModel(rawJaxbModel); jaxbModel.setGeneratedClassNames(_classNameAllocator.getJaxbGeneratedClasses()); }
s2jModel = s2j.bind(); if (s2jModel != null) { codeModel = s2jModel.generateCode(null, errorListener); Iterator<JPackage> packages = codeModel.packages(); StringBuilder buf = new StringBuilder();
JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);