public void processSchema(String uri, Element node) { s2j.parseSchema(uri, node); } },
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("."));
s2j.parseSchema(input);
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("."));
sc.parseSchema(ins); file.delete();
private static void registerNamespace(SchemaCompiler sc, String namespace, String pkgName) throws Exception { Document doc = XMLUtils.newDocument(); Element rootElement = doc.createElement("schema"); rootElement.setAttribute("xmlns", "http://www.w3.org/2001/XMLSchema"); rootElement.setAttribute("xmlns:jaxb", "http://java.sun.com/xml/ns/jaxb"); rootElement.setAttribute("jaxb:version", "2.0"); rootElement.setAttribute("targetNamespace", namespace); Element annoElement = doc.createElement("annotation"); Element appInfo = doc.createElement("appinfo"); Element schemaBindings = doc.createElement("jaxb:schemaBindings"); Element pkgElement = doc.createElement("jaxb:package"); pkgElement.setAttribute("name", pkgName); annoElement.appendChild(appInfo); appInfo.appendChild(schemaBindings); schemaBindings.appendChild(pkgElement); rootElement.appendChild(annoElement); MemoryBlob blob = Blobs.createMemoryBlob(); OutputStream stream = blob.getOutputStream(); Result result = new StreamResult(stream); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(new DOMSource(rootElement), result); stream.close(); InputSource ins = new InputSource(blob.getInputStream()); ins.setSystemId("urn:" + UUID.randomUUID()); sc.parseSchema(ins); }
sc.parseSchema(is); S2JJAXBModel model = sc.bind(); JCodeModel jCodeModel = model.generateCode(null, null);
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()); } }
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()); } }
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); }
try { XMLStreamReader reader = createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)); schemaCompiler.parseSchema(key, reader); } catch (XMLStreamException e) { throw new RuntimeException(e);
try { XMLStreamReader reader = createNoCDATAReader(StaxUtils.createXMLStreamReader(ele, key)); schemaCompiler.parseSchema(key, reader); } catch (XMLStreamException e) { throw new RuntimeException(e);
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)); } }
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);
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);
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);
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; }
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; }
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; }
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; }