final ParserOptions options = ParserOptions.builder().suppressOutput(true).build(); final ErrorHandler handler = new ErrorHandler(options);
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder() .stopOnError(true) .suppressOutput(true) .warningsFatal(true) .build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new EnumType(list.item(i)); map.put(t.name(), t); } return map; } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
/** * Validate the SBE Schema against the XSD. * * @param sbeSchemaFilename to be validated * @param xsdFilename XSD against which to validate * @throws Exception if an error occurs while validating */ public static void validateAgainstSchema(final String sbeSchemaFilename, final String xsdFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { XmlSchemaParser.validate(xsdFilename, in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions .builder() .xsdFilename(System.getProperty(SbeTool.VALIDATION_XSD)) .stopOnError(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(SbeTool.VALIDATION_SUPPRESS_OUTPUT))); try (final BufferedInputStream in = new BufferedInputStream(new FileInputStream(sbeSchemaFilename))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
/** * Creates a builder. * * @return a new builder instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a builder. * * @return a new builder instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a builder. * * @return a new builder instance. */ public static Builder builder() { return new Builder(); }
@Test public void shouldGenerateConstCharArrayMethods() throws Exception final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final MessageSchema schema = parse(TestUtil.getLocalResource("issue505.xml"), options); final IrGenerator irg = new IrGenerator();
@Test public void shouldGenerateAndEncodeIr() throws Exception { System.setProperty(SbeTool.KEYWORD_APPEND_TOKEN, "_"); final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final MessageSchema schema = parse(TestUtil.getLocalResource("FixBinary.xml"), options); final IrGenerator irg = new IrGenerator(); final Ir ir = irg.generate(schema); final ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024); final IrEncoder irEncoder = new IrEncoder(buffer, ir); irEncoder.encode(); buffer.flip(); final IrDecoder irDecoder = new IrDecoder(buffer); final Ir decodedIr = irDecoder.decode(); assertEquals(ir.id(), decodedIr.id()); assertEquals(ir.version(), decodedIr.version()); assertEquals(ir.byteOrder(), decodedIr.byteOrder()); assertEquals(ir.applicableNamespace(), decodedIr.applicableNamespace()); assertEquals(ir.packageName(), decodedIr.packageName()); assertEquals(ir.types().size(), decodedIr.types().size()); assertEquals(ir.messages().size(), decodedIr.messages().size()); } }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder() .stopOnError(true) .suppressOutput(true) .warningsFatal(true) .build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new SetType(list.item(i)); map.put(t.name(), t); } return map; } }
@Test public void shouldGenerateValidJava() throws Exception { System.setProperty(SbeTool.KEYWORD_APPEND_TOKEN, "_"); final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final MessageSchema schema = parse(TestUtil.getLocalResource("FixBinary.xml"), options); final IrGenerator irg = new IrGenerator(); final Ir ir = irg.generate(schema); final JavaGenerator generator = new JavaGenerator( ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager); outputManager.setPackageName(ir.applicableNamespace()); generator.generateMessageHeaderStub(); generator.generateTypeStubs(); generator.generate(); final Map<String, CharSequence> sources = outputManager.getSources(); final String className = "MDIncrementalRefreshTradeSummary42Decoder"; final String fqClassName = ir.applicableNamespace() + "." + className; final Class<?> aClass = CompilerUtil.compileInMemory(fqClassName, sources); assertNotNull(aClass); }
private static Ir generateIrForResource(final String localResourceName) { final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final String xmlLocalResourceName = localResourceName.endsWith(".xml") ? localResourceName : localResourceName + ".xml"; final MessageSchema schema; try { schema = parse(TestUtil.getLocalResource(xmlLocalResourceName), options); } catch (final Exception e) { throw new IllegalStateException(e); } final IrGenerator irg = new IrGenerator(); return irg.generate(schema); }
/** * Parse the message schema specification. * * @param sbeSchemaFilename file containing the SBE specification for the * @return the parsed {@link MessageSchema} for the specification found in the file. * @throws Exception if an error occurs when parsing the specification. */ public static MessageSchema parseSchema(final String sbeSchemaFilename) throws Exception { final ParserOptions.Builder optionsBuilder = ParserOptions.builder() .xsdFilename(System.getProperty(VALIDATION_XSD)) .xIncludeAware(Boolean.parseBoolean(System.getProperty(XINCLUDE_AWARE))) .stopOnError(Boolean.parseBoolean(System.getProperty(VALIDATION_STOP_ON_ERROR))) .warningsFatal(Boolean.parseBoolean(System.getProperty(VALIDATION_WARNINGS_FATAL))) .suppressOutput(Boolean.parseBoolean(System.getProperty(VALIDATION_SUPPRESS_OUTPUT))); try (InputStream in = new BufferedInputStream(Files.newInputStream(Paths.get(sbeSchemaFilename)))) { return XmlSchemaParser.parse(in, optionsBuilder.build()); } }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder().stopOnError(true).suppressOutput(true).build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new CompositeType(list.item(i)); map.put(t.name(), t); } return map; } }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder().stopOnError(true).suppressOutput(true).build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new EncodedDataType(list.item(i)); map.put(t.name(), t); } return map; } }
@Test public void shouldGenerateWhenUsingATypeThatIsConstrainedToFitInAnIntAsTheGroupSize() throws Exception { final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); final MessageSchema schema = parse(TestUtil.getLocalResource("issue567-valid.xml"), options); final IrGenerator irg = new IrGenerator(); final Ir ir = irg.generate(schema); final StringWriterOutputManager outputManager = new StringWriterOutputManager(); outputManager.setPackageName(ir.applicableNamespace()); final CSharpGenerator generator = new CSharpGenerator(ir, outputManager); // Act + Assert (no exception) generator.generate(); } }