List of usage examples for javax.xml.bind JAXBContext getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.sarm.lonelyplanet.process.DestinationProcessorTest.java
/** * This method is not a JUnit test method. This is used to create an XML * file of 30000 destinations and to regressively test the UnMarshalling * technique used in the LPUnMarshaller. This is called by the test method : * testProcessDestinationByStAXfor30000 to test the 30000 destinations. * * @param destinationFileName//from www. j av a 2 s .c om * @throws JAXBException * @throws FileNotFoundException * @throws XMLStreamException * @throws UnsupportedEncodingException */ public static void testMarshall(String destinationFileName) throws JAXBException, FileNotFoundException, XMLStreamException, UnsupportedEncodingException { DestinationProcessor destinationProcessor = new DestinationProcessor(); List<Destination> destinations = destinationProcessor.processDestinationByStAX(destinationFileName); List<Destination> tempDestinations = new ArrayList<>(); for (int i = 0; i < 1500; i++) { for (Destination destination : destinations) { Destination temp = new Destination(); temp = destination.clone(); temp.setTitle(temp.getTitle() + i); tempDestinations.add(temp); } } Destinations destinationList = new Destinations(); destinationList.setDestinations(tempDestinations); logger.info(" destinationList " + destinationList.getDestinations().size()); JAXBContext jc = JAXBContext.newInstance(Destinations.class); logger.debug(jc.getClass()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(destinationList, new File(regressDestinationfile)); logger.info("Successfully created regressDestinationfile " + regressDestinationfile); }
From source file:org.javelin.sws.ext.bind.SweJaxbContextCreationTest.java
@Test public void useDefaultImplementation() throws Exception { JAXBContext context = JAXBContext.newInstance(String.class); assertThat(context.getClass().getName(), equalTo(com.sun.xml.bind.v2.runtime.JAXBContextImpl.class.getName())); context = JAXBContext.newInstance(new Class<?>[] { String.class }, new HashMap<String, Object>()); assertThat(context.getClass().getName(), equalTo(com.sun.xml.bind.v2.runtime.JAXBContextImpl.class.getName())); }
From source file:org.javelin.sws.ext.bind.SweJaxbContextCreationTest.java
@Test public void useBothOurAndDefaultImplementationInTheSamePackage() throws Exception { // this way we can only get one (default or configured on different levels of properties) implementation - we're using // javax.xml.bind.ContextFinder for this and we can't change its implementation... JAXBContext context = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context2.MyClassJ2.class); assertThat(context.getClass().getName(), equalTo(com.sun.xml.bind.v2.runtime.JAXBContextImpl.class.getName())); // but no one will forbid us to call this method :) context = SweJaxbContextFactory.createContext("org.springframework.ws.jaxws.soapenc.context2", null); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); }
From source file:org.javelin.sws.ext.bind.SweJaxbContextCreationTest.java
@Test public void useOurImplementation() throws Exception { JAXBContext context = JAXBContext.newInstance(org.javelin.sws.ext.bind.context1.MyClass1.class); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); context = JAXBContext.newInstance(org.javelin.sws.ext.bind.context1.MyClass1.class.getPackage().getName()); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); context = JAXBContext.newInstance(new Class<?>[] { org.javelin.sws.ext.bind.context1.MyClass1.class }, new HashMap<String, Object>()); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); context = JAXBContext.newInstance(org.javelin.sws.ext.bind.context1.MyClass1.class.getPackage().getName(), this.getClass().getClassLoader()); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); context = JAXBContext.newInstance(org.javelin.sws.ext.bind.context1.MyClass1.class.getPackage().getName(), this.getClass().getClassLoader(), new HashMap<String, Object>()); assertThat(context.getClass().getName(), equalTo("org.javelin.sws.ext.bind.SweJaxbContext")); }
From source file:com.sarm.lonelyplanet.process.DestinationProcessorTest.java
/** * This method tests the JAXB provider. The validates if the JAXB provider * is eclipse provider MOXy. In essence it tests that the jaxb.properties * file is present and it has the correct JAXBContextFactory configured. *///w ww . ja va 2 s. c o m @Test public void testJAXBContext() { logger.info("Testing testJAXBContext "); JAXBContext jc = null; try { jc = JAXBContext.newInstance(Destinations.class); } catch (JAXBException ex) { logger.error(ex); ex.printStackTrace(); } String context = "class org.eclipse.persistence.jaxb.JAXBContext"; assertEquals(context, jc.getClass().toString()); }
From source file:com.googlecode.arit.websphere.jaxb.JAXBUtilsPoolScanner.java
public Set<ClassLoader> getClassLoaders(JAXBContext context) { Set<ClassLoader> classLoaders = new HashSet<ClassLoader>(); if (rbf.getRBeanInfo(JAXBContextImplRBean.class).getTargetClass().isInstance(context)) { JAXBModelRBean model = rbf.createRBean(JAXBContextImplRBean.class, context).getModel(); // The model may be null if the JAXBContextImpl failed to create the model if (model != null) { for (ValueTypeInformationRBean typeInformation : model.getTypeInformation()) { classLoaders.add(typeInformation.getJavaType().getClassLoader()); }/* w w w .j a va 2 s.c o m*/ } } else { String msg = "Encountered unexpected JAXBContext implementation " + context.getClass().getName(); LOG.warn(msg); if (messages != null) { messages.addMessage(msg); } } return classLoaders; }
From source file:org.opennms.core.xml.JaxbUtils.java
public static Marshaller getMarshallerFor(final Object obj, final JAXBContext jaxbContext) { final Class<?> clazz = (Class<?>) (obj instanceof Class<?> ? obj : obj.getClass()); Map<Class<?>, Marshaller> marshallers = m_marshallers.get(); if (jaxbContext == null) { if (marshallers == null) { marshallers = new WeakHashMap<Class<?>, Marshaller>(); m_marshallers.set(marshallers); }/* w w w . j ava 2 s .co m*/ if (marshallers.containsKey(clazz)) { LOG.trace("found unmarshaller for {}", clazz); return marshallers.get(clazz); } } LOG.trace("creating unmarshaller for {}", clazz); try { final JAXBContext context; if (jaxbContext == null) { context = getContextFor(clazz); } else { context = jaxbContext; } final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); if (context.getClass().getName().startsWith("org.eclipse.persistence.jaxb")) { marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, new EmptyNamespacePrefixMapper()); marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, true); } final Schema schema = getValidatorFor(clazz); marshaller.setSchema(schema); if (jaxbContext == null) marshallers.put(clazz, marshaller); return marshaller; } catch (final JAXBException e) { throw EXCEPTION_TRANSLATOR.translate("creating XML marshaller", e); } }