Java Code Examples for org.apache.ws.commons.schema.XmlSchemaCollection#read()
The following examples show how to use
org.apache.ws.commons.schema.XmlSchemaCollection#read() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXmlSchemaExtractorTest.java From syndesis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupClass() throws XmlSchemaSerializer.XmlSchemaSerializerException { if (sourceSchemas == null) { final InputSource inputSource = new InputSource(AbstractXmlSchemaExtractorTest.class .getResourceAsStream(TEST_SCHEMA)); final XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); schemaCollection.read(inputSource); sourceSchemas = new SchemaCollection(schemaCollection); sourceSchemaNodes = new HashMap<>(); for (XmlSchema schema : sourceSchemas.getXmlSchemas()) { final NodeList childNodes = schema.getSchemaDocument().getDocumentElement().getChildNodes(); List<Element> elements = new ArrayList<>(); for (int i = 0; i < childNodes.getLength(); i++) { final Node node = childNodes.item(i); if (node instanceof Element) { elements.add((Element) node); } } sourceSchemaNodes.put(schema.getTargetNamespace(), elements); } } }
Example 2
Source File: Xsd2CobolTypesModelBuilderTest.java From legstar-core2 with GNU Affero General Public License v3.0 | 5 votes |
private String build(String schemaName) throws Exception { File xsdFile = new File(TEST_XSD_FOLDER, schemaName + ".xsd"); Reader reader = new InputStreamReader(new FileInputStream(xsdFile), LEGSTAR_XSD_FILE_ENCODING); XmlSchemaCollection schemaCol = new XmlSchemaCollection(); XmlSchema xsd = schemaCol.read(new StreamSource(reader)); Xsd2CobolTypesModelBuilder builder = new Xsd2CobolTypesModelBuilder(); Map < String, Xsd2CobolTypesModelBuilder.RootCompositeType > model = builder.build(xsd); assertEquals(1, model.size()); return model.toString(); }
Example 3
Source File: ServiceWSDLBuilderTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testSchemas() throws Exception { setupWSDL(WSDL_PATH); Types types = newDef.getTypes(); assertNotNull(types); Collection<ExtensibilityElement> schemas = CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class); assertEquals(1, schemas.size()); XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); Element schemaElem = ((Schema)schemas.iterator().next()).getElement(); XmlSchema newSchema = schemaCollection.read(schemaElem); assertEquals("http://apache.org/hello_world_soap_http/types", newSchema.getTargetNamespace() ); }
Example 4
Source File: Stax2ValidationUtilsTest.java From cxf with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { XmlSchemaCollection schemaCol = new XmlSchemaCollection(); InputStream io = getClass().getClassLoader().getResourceAsStream(schemaPath); String sysId = getClass().getClassLoader().getResource(schemaPath).toString(); schemaCol.setBaseUri(getTestBaseURI()); schemaCol.read(new StreamSource(io, sysId)); serviceInfo.addSchema(schemaInfo); schemaInfo.setSchema(schemaCol.getXmlSchema(sysId)[0]); expect(endpoint.get(anyObject())).andReturn(null); expect(endpoint.containsKey(anyObject())).andReturn(false); expect(endpoint.put(anyString(), anyObject())).andReturn(null); replay(endpoint); }
Example 5
Source File: SchemaInfoBuilderTest.java From tomee with Apache License 2.0 | 5 votes |
private XmlSchemaInfo loadSchemaInfo(String fileName) throws Exception { InputStream in = getClass().getClassLoader().getResourceAsStream(fileName); XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection(); xmlSchemaCollection.read(new InputStreamReader(in), null); CommonsSchemaInfoBuilder schemaInfoBuilder = new CommonsSchemaInfoBuilder(xmlSchemaCollection); XmlSchemaInfo schemaInfo = schemaInfoBuilder.createSchemaInfo(); return schemaInfo; }
Example 6
Source File: DidSchemaParser.java From secure-data-service with Apache License 2.0 | 5 votes |
private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) { try { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); schemaCollection.setSchemaResolver(new URIResolver() { @Override public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { if (resourceLoader != null) { Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation); if (resource.exists()) { try { return new InputSource(resource.getInputStream()); } catch (IOException e) { throw new RuntimeException("Exception occurred", e); } } } return new InputSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream(baseXsdPath + "/" + schemaLocation)); } }); return schemaCollection.read(new InputSource(is), null); } catch (Exception exception) { throw new RuntimeException(exception); } finally { try { is.close(); } catch (IOException ioException) { LOG.error("ioExecption in closing input file ", ioException); } } }
Example 7
Source File: XsdToNeutralSchemaRepo.java From secure-data-service with Apache License 2.0 | 5 votes |
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally") // seems necessary to report issue while closing input stream private XmlSchema parseXmlSchema(final InputStream is) { try { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); schemaCollection.setSchemaResolver(new URIResolver() { @Override public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { if (resourceLoader != null) { Resource resource = resourceLoader.getResource(getXsdPath() + "/" + schemaLocation); if (resource.exists()) { try { return new InputSource(resource.getInputStream()); } catch (IOException e) { throw new RuntimeException("Exception occurred", e); } } } return new InputSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream(getXsdPath() + "/" + schemaLocation)); } }); return schemaCollection.read(new InputSource(is), null); } catch (Exception exception) { throw new RuntimeException(exception); } finally { try { is.close(); } catch (IOException ioException) { throw new RuntimeException(ioException); } } }
Example 8
Source File: SmooksGenerator.java From secure-data-service with Apache License 2.0 | 5 votes |
@SuppressWarnings("PMD.DoNotThrowExceptionInFinally") // smooks support soon to be removed private XmlSchema parseXmlSchema(final InputStream is, final String baseXsdPath) { try { XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); // schemaCollection.setBaseUri(baseUri); schemaCollection.setSchemaResolver(new URIResolver() { @Override public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { if (resourceLoader != null) { Resource resource = resourceLoader.getResource(baseXsdPath + "/" + schemaLocation); if (resource.exists()) { try { return new InputSource(resource.getInputStream()); } catch (IOException e) { throw new RuntimeException("Exception occurred", e); } } } return new InputSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream(baseXsdPath + "/" + schemaLocation)); } }); return schemaCollection.read(new InputSource(is), null); } catch (Exception exception) { throw new RuntimeException(exception); } finally { try { is.close(); } catch (IOException ioException) { throw new RuntimeException(ioException); } } }
Example 9
Source File: Main.java From clinical_quality_language with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException, JAXBException { OptionParser parser = new OptionParser(); OptionSpec<File> schemaOpt = parser.accepts("schema").withRequiredArg().ofType(File.class).required(); OptionSpec<String> modelOpt = parser.accepts("model").withRequiredArg().ofType(String.class); OptionSpec<File> configOpt = parser.accepts("config").withOptionalArg().ofType(File.class); OptionSpec<File> outputOpt = parser.accepts("output").withRequiredArg().ofType(File.class); OptionSpec<String> normalizePrefixOpt = parser.accepts("normalize-prefix").withRequiredArg().ofType(String.class); OptionSpec<ModelImporterOptions.ChoiceTypePolicy> choiceTypeOpt = parser.accepts("choicetype-policy").withRequiredArg().ofType(ModelImporterOptions.ChoiceTypePolicy.class); OptionSpec<ModelImporterOptions.SimpleTypeRestrictionPolicy> stRestrictionsOpt = parser.accepts("simpletype-restriction-policy").withRequiredArg().ofType(ModelImporterOptions.SimpleTypeRestrictionPolicy.class); OptionSpec<ModelImporterOptions.ElementRedeclarationPolicy> redeclarationsOpt = parser.accepts("element-redeclaration-policy").withRequiredArg().ofType(ModelImporterOptions.ElementRedeclarationPolicy.class); OptionSpec<ModelImporterOptions.VersionPolicy> versionPolicyOpt = parser.accepts("version-policy").withRequiredArg().ofType(ModelImporterOptions.VersionPolicy.class); OptionSpec<File> optionsFileOpt = parser.accepts("options-file").withRequiredArg().ofType(File.class); OptionSet options = parser.parse(args); File schemaFile = schemaOpt.value(options); InputStream is = new FileInputStream(schemaFile); XmlSchemaCollection schemaCol = new XmlSchemaCollection(); schemaCol.setBaseUri(schemaFile.getParent()); XmlSchema schema = schemaCol.read(new StreamSource(is)); ModelImporterOptions importerOptions; if (options.has(optionsFileOpt)) { importerOptions = ModelImporterOptions.loadFromProperties(optionsFileOpt.value(options)); } else { importerOptions = new ModelImporterOptions(); } if (options.has(modelOpt)) { importerOptions.setModel(modelOpt.value(options)); } if (options.has(choiceTypeOpt)) { importerOptions.setChoiceTypePolicy(choiceTypeOpt.value(options)); } if (options.has(stRestrictionsOpt)) { importerOptions.setSimpleTypeRestrictionPolicy(stRestrictionsOpt.value(options)); } if (options.has(redeclarationsOpt)) { importerOptions.setElementRedeclarationPolicy(redeclarationsOpt.value(options)); } if (options.has(versionPolicyOpt)) { importerOptions.setVersionPolicy(versionPolicyOpt.value(options)); } if (options.has(normalizePrefixOpt)) { importerOptions.setNormalizePrefix(normalizePrefixOpt.value(options)); } ModelInfo config = null; if (configOpt != null) { File configFile = configOpt.value(options); if (configFile != null) { config = JAXB.unmarshal(configFile, ModelInfo.class); } } ModelInfo modelInfo = ModelImporter.fromXsd(schema, importerOptions, config); JAXBContext jc = JAXBContext.newInstance(ModelInfo.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); File outputfile; if (! options.has(outputOpt) || outputOpt.value(options).isDirectory()) { // construct output filename using modelinfo String name = String.format("%s-modelinfo.xml", modelInfo.getTargetQualifier().getLocalPart()); String basePath = options.has(outputOpt) ? outputOpt.value(options).getAbsolutePath() : schemaFile.getParent(); outputfile = new File(basePath + File.separator + name); } else { outputfile = outputOpt.value(options); } if (outputfile.equals(schemaFile)) { throw new IllegalArgumentException("input schema file and output file must be different!"); } OutputStream os = new FileOutputStream(outputfile, false); try { OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8"); marshaller.marshal(new ObjectFactory().createModelInfo(modelInfo), writer); } finally { os.close(); } }
Example 10
Source File: AegisContext.java From cxf with Apache License 2.0 | 4 votes |
public XmlSchema addTypesSchemaDocument(XmlSchemaCollection collection) { return collection.read(getAegisTypesSchemaDocument(), null); }
Example 11
Source File: AegisContext.java From cxf with Apache License 2.0 | 4 votes |
public XmlSchema addXmimeSchemaDocument(XmlSchemaCollection collection) { return collection.read(getXmimeSchemaDocument(), null); }
Example 12
Source File: XsdReader.java From secure-data-service with Apache License 2.0 | 4 votes |
private static final XmlSchema readSchema(final InputStream istream, final URIResolver schemaResolver) { final XmlSchemaCollection schemaCollection = new XmlSchemaCollection(); schemaCollection.setSchemaResolver(schemaResolver); return schemaCollection.read(new InputSource(istream), null); }
Example 13
Source File: Xsd2JaxbGenerator.java From legstar-core2 with GNU Affero General Public License v3.0 | 3 votes |
/** * Given a COBOL annotated XML schema, produce a set of java classes (source * code) used to convert mainframe data at runtime. * * @param reader reads the COBOL-annotated XML schema source (see * legstar-cob2xsd) * @param packageName the java package the generated classes should reside * in * @return a map of java class names to their source code * @throws Xsd2ConverterException if generation fails */ public Map < String, String > generate(Reader reader, String packageName) throws Xsd2ConverterException { XmlSchemaCollection schemaCol = new XmlSchemaCollection(); XmlSchema xsd = schemaCol.read(new StreamSource(reader)); return generate(xsd, packageName); }
Example 14
Source File: Xsd2CobolTypesGenerator.java From legstar-core2 with GNU Affero General Public License v3.0 | 3 votes |
/** * Given a COBOL annotated XML schema, produce a set of java classes (source * code) used to convert mainframe data at runtime. * * @param reader reads the COBOL-annotated XML schema source (see legstar-cob2xsd) * @param packageName the java package the generated classes should reside * in * @return a map of java class names to their source code * @throws Xsd2ConverterException if generation fails */ public Map < String, String > generate(Reader reader, String packageName) throws Xsd2ConverterException { XmlSchemaCollection schemaCol = new XmlSchemaCollection(); XmlSchema xsd = schemaCol.read(new StreamSource(reader)); return generate(xsd, packageName); }