@@ -0,0 +1,1760 @@
+package org.hisrc.xml.bind.tests;%0A%0Aimport java.io.IOException;%0A%0Aimport javax.xml.bind.JAXBContext;%0Aimport javax.xml.bind.JAXBException;%0Aimport javax.xml.bind.MarshalException;%0Aimport javax.xml.bind.Marshaller;%0Aimport javax.xml.bind.SchemaOutputResolver;%0Aimport javax.xml.bind.annotation.XmlAttribute;%0Aimport javax.xml.bind.annotation.XmlRootElement;%0Aimport javax.xml.transform.Result;%0Aimport javax.xml.transform.dom.DOMResult;%0Aimport javax.xml.transform.dom.DOMSource;%0Aimport javax.xml.validation.Schema;%0Aimport javax.xml.validation.SchemaFactory;%0A%0Aimport org.junit.Test;%0Aimport org.xml.sax.SAXException;%0A%0Aimport com.sun.xml.bind.v2.WellKnownNamespace;%0A%0Apublic class DynamicSchemaTest %7B%0A%0A%09@XmlRootElement%0A%09public static class A %7B%0A%09%09@XmlAttribute(required = true)%0A%09%09public String name;%0A%0A%09%09public A() %7B%0A%09%09%7D%0A%0A%09%09public A(String name) %7B%0A%09%09%09this.name = name;%0A%09%09%7D%0A%09%7D%0A%0A%09@Test(expected = MarshalException.class)%0A%09public void generatesAndUsesSchema() throws JAXBException, IOException,%0A%09%09%09SAXException %7B%0A%09%09final JAXBContext context = JAXBContext.newInstance(A.class);%0A%09%09final DOMResult result = new DOMResult();%0A%09%09result.setSystemId(%22schema.xsd%22);%0A%09%09context.generateSchema(new SchemaOutputResolver() %7B%0A%09%09%09@Override%0A%09%09%09public Result createOutput(String namespaceUri,%0A%09%09%09%09%09String suggestedFileName) %7B%0A%09%09%09%09return result;%0A%09%09%09%7D%0A%09%09%7D);%0A%0A%09%09@SuppressWarnings(%22deprecation%22)%0A%09%09final SchemaFactory schemaFactory = SchemaFactory%0A%09%09%09%09.newInstance(WellKnownNamespace.XML_SCHEMA);%0A%09%09final Schema schema = schemaFactory.newSchema(new DOMSource(result%0A%09%09%09%09.getNode()));%0A%0A%09%09final Marshaller marshaller = context.createMarshaller();%0A%09%09marshaller.setSchema(schema);%0A%09%09// Works%0A%09%09marshaller.marshal(new A(%22works%22), System.out);%0A%09%09// Fails%0A%09%09marshaller.marshal(new A(null), System.out);%0A%09%7D%0A%7D%0A

Test case for dynamic schema creation.