}
}
};
factory.registerDefaultFieldMapper(myHint);
MapperFacade mapper = factory.getMapperFacade();
// -----------------------------------------------------------------------------
File projectRoot = MavenProjectUtil.findProjectRoot();
ClassLoader threadContextLoader = Thread.currentThread().getContextClassLoader();
EclipseJdtCompiler complier = new EclipseJdtCompiler(threadContextLoader);
ClassLoader childLoader = complier.compile(new File(projectRoot, "src/main/java-hidden"),threadContextLoader);
@SuppressWarnings("unchecked")
Class<? extends Author> hiddenAuthorType = (Class<? extends Author>) childLoader.loadClass("types.AuthorHidden");
@SuppressWarnings("unchecked")
Class<? extends Book> hiddenBookType = (Class<? extends Book>) childLoader.loadClass("types.BookHidden");
@SuppressWarnings("unchecked")
Class<? extends Library> hiddenLibraryType = (Class<? extends Library>) childLoader.loadClass("types.LibraryHidden");
try {
threadContextLoader.loadClass("types.LibraryHidden");
Assert.fail("types.LibraryHidden should not be accessible to the thread context class loader");
} catch (ClassNotFoundException e0) {
try {
threadContextLoader.loadClass("types.AuthorHidden");
Assert.fail("types.AuthorHidden should not be accessible to the thread context class loader");
} catch (ClassNotFoundException e1) {
try {
threadContextLoader.loadClass("types.BookHidden");
Assert.fail("types.BookHidden should not be accessible to the thread context class loader");
} catch (ClassNotFoundException e2) {
/* good: all of these types should be inaccessible */
}
}
}
// Now, these types are hidden from the current class-loader, but they
// implement types
// that are accessible to this loader
// -----------------------------------------------------------------------------
Book book = createBook(hiddenBookType);
book.setAuthor(createAuthor(hiddenAuthorType));
Library lib = createLibrary(hiddenLibraryType);
lib.getBooks().add(book);
LibraryMyDTO mappedLib = mapper.map(lib, LibraryMyDTO.class);
Assert.assertEquals(lib.getTitle(), mappedLib.getMyTitle());
Assert.assertEquals(book.getTitle(), mappedLib.getMyBooks().get(0).getMyTitle());
Assert.assertEquals(book.getAuthor().getName(), mappedLib.getMyBooks().get(0).getMyAuthor().getMyName());