import com.sun.codemodel.*; import com.sun.tools.xjc.*; import com.sun.tools.xjc.api.*; SchemaCompiler sc = XJC.createSchemaCompiler(); sc.setEntityResolver(new YourEntityResolver()); sc.setErrorListener(new YourErrorListener()); sc.parseSchema(SYSTEM_ID, element); S2JJAXBModel model = sc.bind();
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("."));
S2JJAXBModel model = sc.bind(); JCodeModel jCodeModel = model.generateCode(null, null); jCodeModel.build(new File(outputDirectory));
compiler.setErrorListener(errorListener); compiler.parseSchema(new InputSource(url.toExternalForm())); S2JJAXBModel model = compiler.bind(); if (model == null)
compiler.setErrorListener(errorListener); compiler.parseSchema(new InputSource(url.toExternalForm())); S2JJAXBModel model = compiler.bind(); if (model == null)
public JavaModelInput getJavaModelInput() throws JAXBException { S2JJAXBModel model = schemaCompiler.bind();
SchemaCompiler sc = XJC.createSchemaCompiler(); sc.parseSchema(new InputSource(xsdFile.toURI().toString())); S2JJAXBModel model = sc.bind();
model = schemaCompiler.bind();
SchemaCompiler sc = XJC.createSchemaCompiler(); sc.parseSchema(new InputSource(xsdFile.toURI().toString())); S2JJAXBModel model = sc.bind();
S2JJAXBModel jaxbModel = schemaCompliler.bind(); JCodeModel codeModel = jaxbModel.generateCode(null, null); try {
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()); }
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()); }
parseSchemas(schemaCompiler); rawJaxbModelGenCode = schemaCompiler.bind();
parseSchemas(schemaCompiler); rawJaxbModelGenCode = schemaCompiler.bind();