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("."));
@SuppressWarnings("deprecation") private Options getOptions(SchemaCompiler schemaCompiler) throws ToolException { return schemaCompiler.getOptions(); }
try { schemaCompiler = options.getSchemaCompiler(); schemaCompiler.resetSchema(); if(options.entityResolver != null) { schemaCompiler.setEntityResolver(options.entityResolver); schemaCompiler.setClassNameAllocator(_classNameAllocator); schemaCompiler.setErrorListener(errReceiver); int schemaElementCount = 1; String systemId = location + "#types?schema" + schemaElementCount++; if(forest.isMexMetadata) schemaCompiler.parseSchema(systemId,element); else new DOMForestScanner(forest).scan(element,schemaCompiler.getParserHandler(systemId)); if(externalBindings != null){ for(InputSource jaxbBinding : externalBindings){ schemaCompiler.parseSchema(jaxbBinding);
public SchemaCompiler getSchemaCompiler() { schemaCompiler.setTargetVersion(SpecVersion.parse(target.getVersion())); if(entityResolver != null) { //set if its not null so as not to override catalog option specified via xjc args schemaCompiler.setEntityResolver(entityResolver); } return schemaCompiler; }
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.setErrorListener(er); schemaCompiler.setEntityResolver(new RelativeEntityResolver(schema .getDefinition().getDocumentBaseURI())); schemaCompiler.parseSchema(systemId, schema.getSchemaElement()); InputSource source = new InputSource(e.getValue()); source.setSystemId(e.getKey()); schemaCompiler.parseSchema(source); model = schemaCompiler.bind();
s2j.setDefaultPackageName(parameters.pkg); s2j.setErrorListener(errorListener); InputSource input = new InputSource(incl.toURL().openStream()); input.setSystemId(incl.toString()); s2j.parseSchema(input); applyXjcArguments(s2j.getOptions()); s2jModel = s2j.bind(); if (s2jModel != null) { codeModel = s2jModel.generateCode(null, errorListener);
schemaCompiler.setClassNameAllocator(allocator); schemaCompiler.setErrorListener(this); schemaCompilerGenCode.setClassNameAllocator(allocator); schemaCompilerGenCode.setErrorListener(this); schemaCompiler.parseSchema(systemid, schemaElement); if (env.isExcludeNamespaceEnabled() && !skipGenCode) { schemaCompilerGenCode.parseSchema(systemid, schemaElement); schemaCompiler.parseSchema(bindingFile); if (env.isExcludeNamespaceEnabled()) { schemaCompilerGenCode.parseSchema(bindingFile); rawJaxbModel = schemaCompiler.bind(); if (env.isExcludeNamespaceEnabled()) { rawJaxbModelGenCode = schemaCompilerGenCode.bind(); } else { rawJaxbModelGenCode = rawJaxbModel;
public SchemaMetadata(DynamicClassLoader dynamicClassLoader, Map<String, Object> properties, Node node, EntityResolver resolver) throws JAXBException { this(dynamicClassLoader, properties); Element element; if (node.getNodeType() == Node.DOCUMENT_NODE) { element = ((Document) node).getDocumentElement(); } else if (node.getNodeType() == Node.ELEMENT_NODE) { element = (Element) node; } else { throw new JAXBException(org.eclipse.persistence.exceptions.JAXBException.cannotInitializeFromNode()); } // Use XJC API to parse the schema and generate its JCodeModel schemaCompiler = XJC.createSchemaCompiler(); schemaCompiler.setEntityResolver(resolver); schemaCompiler.setErrorListener(new XJCErrorListener()); schemaCompiler.parseSchema(DEFAULT_SYSTEM_ID, element); }
c.optionSet(ToolConstants.CFG_AUTORESOLVE)); schemaCompiler.setClassNameAllocator(allocator); schemaCompiler.setErrorListener(listener); parseSchemas(schemaCompiler); rawJaxbModelGenCode = schemaCompiler.bind();
sc.forcePackageName("com.xyz.schema"); sc.parseSchema(is); S2JJAXBModel model = sc.bind(); JCodeModel jCodeModel = model.generateCode(null, null); jCodeModel.build(new File(outputDirectory));
public void processSchema(String uri, Element node) { s2j.parseSchema(uri, node); } },
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();
protected void buildJAXBModel(WSDLDocument wsdlDocument) { JAXBModelBuilder tempJaxbModelBuilder = new JAXBModelBuilder(options, classNameCollector, forest, errReceiver); //set the java package where wsdl artifacts will be generated //if user provided package name using -p switch (or package property on wsimport ant task) //ignore the package customization in the wsdl and schema bidnings //formce the -p option only in the first pass if (explicitDefaultPackage != null) { tempJaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(options.defaultPackage); } else { options.defaultPackage = getJavaPackage(); } //create pseudo schema for async operations(if any) response bean List<InputSource> schemas = PseudoSchemaBuilder.build(this, options, errReceiver); for (InputSource schema : schemas) { tempJaxbModelBuilder.getJAXBSchemaCompiler().parseSchema(schema); } tempJaxbModelBuilder.bind(); this.jaxbModelBuilder = tempJaxbModelBuilder; }
private void parseSchemas(SchemaCompiler schemaCompiler) { for (String ns : context.getNamespacePackageMap().keySet()) { File file = JAXBUtils.getPackageMappingSchemaBindingFile(ns, context.mapPackageName(ns)); try { InputSource ins = new InputSource(file.toURI().toString()); schemaCompiler.parseSchema(ins); } finally { FileUtils.delete(file); } } if (context.getPackageName() != null) { schemaCompiler.setDefaultPackageName(context.getPackageName()); } }
InputSource inputSoruce = new InputSource(new FileInputStream(bindingFileName)); inputSoruce.setSystemId(new File(bindingFileName).toURI().toString()); sc.getOptions().addBindFile(inputSoruce); sc.setEntityResolver(resolver); sc.setErrorListener(new ErrorListener(){ public void error(SAXParseException saxParseException) { log.error(saxParseException.getMessage()); sc.parseSchema((InputSource) schemaToInputSourceMap.get(key)); sc.getOptions().addGrammar((InputSource) schemaToInputSourceMap.get(key)); args = new String[]{"-" + propertyName}; sc.getOptions().parseArguments(args); S2JJAXBModel jaxbModel = sc.bind();
public SchemaMetadata(DynamicClassLoader dynamicClassLoader, Map<String, Object> properties, Source metadataSource, EntityResolver resolver) throws JAXBException { this(dynamicClassLoader, properties); try { InputSource schemaInputSource = createInputSourceFromSource(metadataSource); if (schemaInputSource.getSystemId() == null) { schemaInputSource.setSystemId(DEFAULT_SYSTEM_ID); } // Use XJC API to parse the schema and generate its JCodeModel schemaCompiler = XJC.createSchemaCompiler(); schemaCompiler.setEntityResolver(resolver); schemaCompiler.setErrorListener(new XJCErrorListener()); if (externalBindings != null) { for (InputSource xjbSource : externalBindings) { schemaCompiler.parseSchema(xjbSource); } } schemaCompiler.parseSchema(schemaInputSource); } catch (XMLPlatformException xpe) { // This will occur when trying to refreshMetadata from a closed stream (non-XML Node metadata) if (xpe.getCause() instanceof TransformerException) { TransformerException te = (TransformerException) xpe.getCause(); if (te.getCause() instanceof IOException) { throw org.eclipse.persistence.exceptions.JAXBException.cannotRefreshMetadata(); } } } catch (Exception e) { throw new JAXBException(org.eclipse.persistence.exceptions.JAXBException.errorCreatingDynamicJAXBContext(e)); } }
sc.parseSchema(new InputSource(xsdFile.toURI().toString())); S2JJAXBModel model = sc.bind();
c.optionSet(ToolConstants.CFG_AUTORESOLVE)); schemaCompiler.setClassNameAllocator(allocator); schemaCompiler.setErrorListener(listener); parseSchemas(schemaCompiler); rawJaxbModelGenCode = schemaCompiler.bind();
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);