private static void addTypeWithNameCheck(final Map<String, Type> typeByNameMap, final Type type, final Node node) { if (typeByNameMap.get(type.name()) != null) { handleWarning(node, "type already exists for name: " + type.name()); } checkForValidName(node, type.name()); typeByNameMap.put(type.name(), type); }
/** * Check the composite for any specified offsets and validate they are correctly specified. * * @param node of the XML for this composite */ public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
@Test public void shouldHandleMultipleTypes() throws Exception { final String testXmlString = "<types>" + " <type name=\"testType1\" presence=\"required\" primitiveType=\"char\" length=\"1\" " + "variableLength=\"false\"/>" + " <type name=\"testType2\" presence=\"required\" primitiveType=\"int8\" length=\"1\" " + "variableLength=\"false\"/>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); // assert that testType is in map and name of Type is correct assertThat(map.size(), is(2)); assertThat(map.get("testType1").name(), is("testType1")); assertThat(map.get("testType2").name(), is("testType2")); }
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; } }
@Test public void shouldHandleCompositeTypeList() throws Exception { final String testXmlString = "<types>" + "<composite name=\"decimal\">" + " <type name=\"mantissa\" primitiveType=\"int64\"/>" + " <type name=\"exponent\" primitiveType=\"int8\"/>" + "</composite>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/composite", testXmlString); final CompositeType c = (CompositeType)map.get("decimal"); assertThat(c.getTypeList().size(), is(2)); assertThat(c.getTypeList().get(0).name(), is("mantissa")); assertThat(c.getTypeList().get(1).name(), is("exponent")); }
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; } }
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; } }
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; } }
else if (!valueRefType.equals(type.name()))
map.put(type.name(), type);
@Test public void shouldSetAppropriateDefaultsWhenNoneSpecified() throws Exception { final String testXmlString = "<types>" + " <type name=\"testType\" primitiveType=\"char\"/>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); // assert that testType is in map and name of Type is correct assertThat(map.get("testType").name(), is("testType")); // assert defaults for length, variableLength and presence final Type t = map.get("testType"); assertThat(t.presence(), is(Presence.REQUIRED)); final EncodedDataType d = (EncodedDataType)t; assertThat(d.length(), is(1)); assertThat(d.isVariableLength(), is(false)); }
@Test public void shouldHandleSettingAllAttributes() throws Exception { final String testXmlString = "<types>" + " <type name=\"testType\" presence=\"required\" primitiveType=\"char\" length=\"1\" " + "variableLength=\"false\"/>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); // assert that testType is in map and name of Type is correct final Type t = map.get("testType"); assertThat(t.name(), is("testType")); assertThat(t.presence(), is(Presence.REQUIRED)); final EncodedDataType d = (EncodedDataType)t; assertThat(d.primitiveType(), is(PrimitiveType.CHAR)); assertThat(d.length(), is(1)); assertThat(d.isVariableLength(), is(false)); }
private static void addTypeWithNameCheck(final Map<String, Type> typeByNameMap, final Type type, final Node node) { if (typeByNameMap.get(type.name()) != null) { handleWarning(node, "type already exists for name: " + type.name()); } checkForValidName(node, type.name()); typeByNameMap.put(type.name(), type); }
private static void addTypeWithNameCheck(final Map<String, Type> typeByNameMap, final Type type, final Node node) { if (typeByNameMap.get(type.name()) != null) { handleWarning(node, "type already exists for name: " + type.name()); } checkForValidName(node, type.name()); typeByNameMap.put(type.name(), type); }
private static void addTypeWithNameCheck(final Map<String, Type> typeByNameMap, final Type type, final Node node) { if (typeByNameMap.get(type.name()) != null) { handleWarning(node, "type already exists for name: " + type.name()); } checkForValidName(node, type.name()); typeByNameMap.put(type.name(), type); }
/** * Check the composite for any specified offsets and validate they are correctly specified. * * @param node of the XML for this composite */ public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
/** * Check the composite for any specified offsets and validate they are correctly specified. * * @param node of the XML for this composite */ public void checkForValidOffsets(final Node node) { int offset = 0; for (final Type edt : containedTypeByNameMap.values()) { final int offsetAttribute = edt.offsetAttribute(); if (-1 != offsetAttribute) { if (offsetAttribute < offset) { XmlSchemaParser.handleError( node, String.format("composite element \"%s\" has incorrect offset specified", edt.name())); } offset = offsetAttribute; } offset += edt.encodedLength(); } }
else if (!valueRefType.equals(type.name()))
else if (!valueRefType.equals(type.name()))