Java Code Examples for javax.xml.bind.JAXBContext#getClass()
The following examples show how to use
javax.xml.bind.JAXBContext#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXBContextWithSubclassedFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void test(Class<?> factoryClass) throws JAXBException { System.clearProperty(JAXBContext.JAXB_CONTEXT_FACTORY); System.out.println("** Testing with Factory Class: " + factoryClass.getName()); System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = " + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "")); System.out.println("Calling " + "JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class)"); tmp = JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class); System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, factoryClass.getName()); System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = " + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY)); System.out.println("Calling " + "JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class)"); JAXBContext ctxt = JAXBContext.newInstance(JAXBContextWithSubclassedFactory.class); System.out.println("Successfully loaded JAXBcontext: " + System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName()); if (ctxt.getClass() != JAXBContextImpl.class) { throw new RuntimeException("Wrong JAXBContext class" + "\n\texpected: " + System.identityHashCode(tmp) + "@" + JAXBContextImpl.class.getName() + "\n\tactual: " + System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName()); } if (((JAXBContextImpl)ctxt).creator != factoryClass) { throw new RuntimeException("Wrong Factory class" + "\n\texpected: " + System.identityHashCode(tmp) + "@" + factoryClass.getName() + "\n\tactual: " + System.identityHashCode(ctxt) + "@" + ((JAXBContextImpl)ctxt).creator.getName()); } }
Example 2
Source File: JAXBContextWithLegacyFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void test(Class<?> factoryClass, Class<?> creatorClass) throws JAXBException { System.clearProperty(JAXBContext.JAXB_CONTEXT_FACTORY); System.out.println("** Testing with Factory Class: " + factoryClass.getName()); System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = " + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY, "")); System.out.println("Calling " + "JAXBContext.newInstance(JAXBContextWithLegacyFactory.class)"); tmp = JAXBContext.newInstance(JAXBContextWithLegacyFactory.class); System.setProperty(JAXBContext.JAXB_CONTEXT_FACTORY, factoryClass.getName()); System.out.println(JAXBContext.JAXB_CONTEXT_FACTORY + " = " + System.getProperty(JAXBContext.JAXB_CONTEXT_FACTORY)); System.out.println("Calling " + "JAXBContext.newInstance(JAXBContextWithLegacyFactory.class)"); JAXBContext ctxt = JAXBContext.newInstance(JAXBContextWithLegacyFactory.class); System.out.println("Successfully loaded JAXBcontext: " + System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName()); if (ctxt.getClass() != JAXBContextImpl.class) { throw new RuntimeException("Wrong JAXBContext class" + "\n\texpected: " + System.identityHashCode(tmp) + "@" + JAXBContextImpl.class.getName() + "\n\tactual: " + System.identityHashCode(ctxt) + "@" + ctxt.getClass().getName()); } if (((JAXBContextImpl)ctxt).creator != creatorClass) { throw new RuntimeException("Wrong Factory class" + "\n\texpected: " + System.identityHashCode(tmp) + "@" + creatorClass.getName() + "\n\tactual: " + System.identityHashCode(ctxt) + "@" + ((JAXBContextImpl)ctxt).creator.getName()); } }