XmlMatrix { public static Adapter getAdapter(){ return ADAPTER; }  int[] getDimensions(); void setDimensions(int[] dimensions); double[] getValues(); void setValues(double[] values); static Adapter getAdapter();  }
@Test @Ignore public void testMarshal() throws FileNotFoundException, JAXBException, IOException { JAXBContext jaxb = JAXBContext.newInstance(XmlMatrix.class); Matrix m = new Matrix(5, 8); m.set((r, c) -> (r + 1) * (c + 1)); XmlMatrix xmat = XmlMatrix.getAdapter().marshal(m); FileOutputStream ostream = new FileOutputStream(FILE); try (OutputStreamWriter writer = new OutputStreamWriter(ostream, StandardCharsets.UTF_8)) { Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(xmat, writer); writer.flush(); } XmlMatrix rslt = null; FileInputStream istream = new FileInputStream(FILE); try (InputStreamReader reader = new InputStreamReader(istream, StandardCharsets.UTF_8)) { Unmarshaller unmarshaller = jaxb.createUnmarshaller(); unmarshaller.setSchema(Schemas.Core); unmarshaller.setEventHandler(new TestValidationEventHandler()); rslt = (XmlMatrix) unmarshaller.unmarshal(reader); Matrix m2 = XmlMatrix.getAdapter().unmarshal(rslt); assertTrue(m.equals(m2, 1e-6)); } }
@Test public void testValidation() throws FileNotFoundException, JAXBException, IOException, SAXException { JAXBContext jaxb = JAXBContext.newInstance(XmlMatrix.class); Matrix m = new Matrix(5, 8); m.set((r, c) -> (r + 1) * (c + 1)); XmlMatrix xmat = XmlMatrix.getAdapter().marshal(m); JAXBSource source = new JAXBSource(jaxb, xmat); Validator validator = Schemas.Core.newValidator(); validator.validate(source); }