コード例 #1
0
  public void testCompile() throws Exception {

    final File schema = new File(getClass().getResource("schema.xsd").toURI());
    final File bindings = new File(getClass().getResource("bindings.xjb").toURI());

    final DynamicCompiler compiler =
        new DynamicCompiler(new File[] {schema}, new File[] {bindings}, null, temporaryDirectory);

    compiler.execute();

    final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      final ClassLoader newClassLoader = compiler.createClassLoader(oldClassLoader);
      Thread.currentThread().setContextClassLoader(newClassLoader);

      final RoundtripTest test =
          new RoundtripTest() {
            @Override
            public String getContextPath() {
              return compiler.getContextPath();
            }

            @Override
            protected File getSamplesDirectory() {
              return schema.getParentFile();
            }

            @Override
            protected ClassLoader getContextClassLoader() {
              return Thread.currentThread().getContextClassLoader();
            }
          };

      test.setUp();

      test.testSamples();

      test.tearDown();
    } finally {
      Thread.currentThread().setContextClassLoader(oldClassLoader);
    }
  }
コード例 #2
0
  public void testUnmarshall() throws Exception {

    final File schema = new File(getClass().getResource("schema.xsd").toURI());
    final File bindings = new File(getClass().getResource("bindings.xjb").toURI());
    final File sample = new File(getClass().getResource("po.xml").toURI());

    final DynamicCompiler compiler =
        new DynamicCompiler(new File[] {schema}, new File[] {bindings}, null, temporaryDirectory);

    compiler.execute();

    final JAXBContext context =
        JAXBContext.newInstance(compiler.getContextPath(), compiler.getClassLoader());

    final JAXBElement element = (JAXBElement) context.createUnmarshaller().unmarshal(sample);

    final String elementValueClassName = element.getValue().getClass().getName();
    logger.debug("We have just loaded an instance of [" + elementValueClassName + "]");
    Assert.assertEquals(
        "org.jvnet.hyperjaxb3.ejb.tests.pocustomized.PurchaseOrderType", elementValueClassName);
  }