List of usage examples for javax.xml.bind JAXBContext newInstance
public static JAXBContext newInstance(Class<?>[] classesToBeBound, Map<String, ?> properties) throws JAXBException
From source file:com.technofovea.hl2parse.vdf.MaterialReader.java
public static final MaterialRefList loadFromXml(InputStream stream) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(MaterialReference.class, MaterialRefList.class); Unmarshaller um = jc.createUnmarshaller(); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Object o = um.unmarshal(stream); return (MaterialRefList) o; }
From source file:com.radialpoint.uima.typemapper.RulesFileLoader.java
public static Rules loadRulesFromStream(InputStream stream) throws JAXBException, FileNotFoundException { Rules rules = new Rules(); // Unmarshal/*from w ww. j av a2 s . co m*/ JAXBContext jc = JAXBContext.newInstance(Rules.class, Rule.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); rules = (Rules) unmarshaller.unmarshal(stream); if (rules == null || CollectionUtils.isEmpty(rules.getRuleList())) { throw new JAXBException("Rules list is empty. Binding error?"); } return rules; }
From source file:Main.java
/** * Initialize the JAXB context.//from ww w. j a va2s.c om * * @param classloader * class loader to access JAXB classes * * @throws JAXBException * if the JAXB context is not initialized properly */ public synchronized static void initContext(ClassLoader classloader) throws JAXBException { JAXB = JAXBContext.newInstance(JAXB_PACKAGES, classloader); }
From source file:com.lolay.citygrid.BaseInvoker.java
protected static <T> T parseResults(Class<T> type, Response response) throws InvokerException { if (Response.Status.OK.getStatusCode() != response.getStatus() && Response.Status.BAD_REQUEST.getStatusCode() != response.getStatus()) { throw new RuntimeException(String.format("Can only parse 200 and 400 responses, the reponse was %s", response.getStatus()));/*from w ww .j a v a 2s . c o m*/ } if (response.getEntity() != null && response.getEntity().getClass().equals(type)) { return type.cast(response.getEntity()); } else if (response.getEntity() instanceof ErrorResults) { throw new InvokerException(ErrorResults.class.cast(response.getEntity())); } else if (response.getEntity() instanceof InputStream) { InputStream stream = InputStream.class.cast(response.getEntity()); Object results = null; try { JAXBContext context = JAXBContext.newInstance(type, ErrorResults.class); results = context.createUnmarshaller().unmarshal(stream); } catch (JAXBException e) { throw new RuntimeException("Problem unmarshalling the entity", e); } if (results != null && results.getClass().equals(type)) { return type.cast(results); } else { throw new InvokerException(ErrorResults.class.cast(results)); } } else { throw new RuntimeException( String.format("Do not know how to parse %s", response.getEntity().getClass())); } }
From source file:Main.java
/** * Create a {@link Marshaller} for the given context and return it. * /*from w w w . j av a 2 s . c o m*/ * @param jaxbContextName the context name where to look to find jaxb classes * @param cl : {@link ClassLoader} of the ObjectFactory * @return the created {@link Marshaller} * @throws JAXBException */ public static Marshaller createMarshaller(final String jaxbContextName, ClassLoader cl) throws JAXBException { final JAXBContext jaxbContext = JAXBContext.newInstance(jaxbContextName, cl); return jaxbContext.createMarshaller(); }
From source file:edu.htwm.vsp.phone.services.XmlMappingTest.java
@Before public void prepareXmlMarshalling() throws JAXBException { /*/*w w w . ja v a 2 s. c om*/ * Code Duplizierung vermeiden * (DRY -> http://de.wikipedia.org/wiki/Don%E2%80%99t_repeat_yourself) und * aufwndige, immer wieder verwendete Objekte nur einmal erzeugen * */ JAXBContext context = JAXBContext.newInstance(PhoneUser.class, PhoneNumber.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = context.createUnmarshaller(); }
From source file:org.sonarqube.shell.services.JsonContext.java
public JsonContext() throws JAXBException { System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory"); Map<String, Object> properties = new HashMap<>(); properties.put(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); properties.put(UnmarshallerProperties.JSON_INCLUDE_ROOT, false); properties.put(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); this.context = JAXBContext.newInstance(new Class[] { ChronosEntry.class, Profile.class }, properties); }