document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); final Map<String, Type> typeByNameMap = findTypes(document, xPath); errorHandler.checkIfShouldExit();
document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); final Map<String, Type> typeByNameMap = findTypes(document, xPath); errorHandler.checkIfShouldExit();
document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); final Map<String, Type> typeByNameMap = findTypes(document, xPath); errorHandler.checkIfShouldExit();
/** * Take an {@link InputStream} and parse it generating map of template ID to Message objects, types, and schema * Input could be from {@link java.io.FileInputStream}, {@link java.io.ByteArrayInputStream}, etc. * Exceptions are passed back up for any problems. * * @param in stream from which schema is read. * @param options to be applied during parsing. * @return {@link MessageSchema} encoding for the schema. * @throws Exception on parsing error. */ public static MessageSchema parse(final InputStream in, final ParserOptions options) throws Exception { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final Document document = factory.newDocumentBuilder().parse(in); final XPath xPath = XPathFactory.newInstance().newXPath(); final ErrorHandler errorHandler = new ErrorHandler(options); document.setUserData(ERROR_HANDLER_KEY, errorHandler, null); final Map<String, Type> typeByNameMap = findTypes(document, xPath); errorHandler.checkIfShouldExit(); final Map<Long, Message> messageByIdMap = findMessages(document, xPath, typeByNameMap); errorHandler.checkIfShouldExit(); final Node schemaNode = (Node)xPath.compile(MESSAGE_SCHEMA_XPATH_EXPR).evaluate(document, XPathConstants.NODE); final MessageSchema messageSchema = new MessageSchema(schemaNode, typeByNameMap, messageByIdMap); errorHandler.checkIfShouldExit(); return messageSchema; }