/** * A helper method to parse and convert the XML representation of an EPCIS * query results into a QueryResults object. * * @param xml * The InputStream containing the XML representation of a * QueryResults object. * @return The parsed QueryResults object. * @throws IOException * If an error de-serializing the InputStream occurred. */ public static QueryResults parseResults(final InputStream xml) throws IOException { // de-serialize the XML try { JAXBContext context = JAXBContext.newInstance(QueryResults.class); Unmarshaller unmarshaller = context.createUnmarshaller(); // setting schema to null will turn XML validation off // unmarshaller.setSchema(null); JAXBElement<?> results = (JAXBElement<?>) unmarshaller.unmarshal(xml); return (QueryResults) results.getValue(); } catch (JAXBException e) { // wrap JAXBException into IOException to keep the interface // JAXB-free IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
/** * Marshals the given QueryResults object to its XML representations and * returns it as a String. * * @param results * The QueryResults object to marshal into XML. * @param out * The OutputStream to which the XML representation will be * written to. * @throws IOException * If an error marshaling the QueryResults object occurred. */ public static String queryResultsToXml(final QueryResults results) throws IOException { // serialize the response try { StringWriter writer = new StringWriter(); JAXBElement<QueryResults> item = factory.createQueryResults(results); JAXBContext context = JAXBContext.newInstance(QueryResults.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(item, writer); return writer.toString(); } catch (JAXBException e) { IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
} catch (JAXBException e) { IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe;
ioe.setStackTrace(e.getStackTrace()); throw ioe;
/** * Parses the XML from the given input stream as an Unsubscribe object and * unsubscribes the specified subscription ID from the repository. * * @param unsubscribeIs * @throws ImplementationExceptionResponse * @throws SecurityExceptionResponse * @throws ValidationExceptionResponse * @throws NoSuchSubscriptionExceptionResponse * @throws IOException */ public void unsubscribe(final InputStream unsubscribeIs) throws ImplementationExceptionResponse, SecurityExceptionResponse, ValidationExceptionResponse, NoSuchSubscriptionExceptionResponse, IOException { try { JAXBContext context = JAXBContext.newInstance("org.fosstrak.epcis.model"); Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<?> elem = (JAXBElement<?>) unmarshaller.unmarshal(unsubscribeIs); Unsubscribe unsubscribe = (Unsubscribe) elem.getValue(); unsubscribe(unsubscribe.getSubscriptionID()); } catch (JAXBException e) { // wrap JAXBException into IOException to keep the interface // JAXB-free IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } } }
/** * A helper method to parse and convert the XML representation of an EPCIS * query document into an QueryResults object. * * @param xml * The Reader containing the XML representation of an * EPCISQueryDocumentType object. * @return The parsed QueryResults object. * @throws IOException * If an error de-serializing the InputStream occurred. */ public static QueryResults parseQueryDocResults(final Reader r) throws IOException { // de-serialize the XML try { JAXBContext context = JAXBContext.newInstance(EPCISQueryDocumentType.class); Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<?> results = (JAXBElement<?>) unmarshaller.unmarshal(r); EPCISQueryDocumentType doc = (EPCISQueryDocumentType) results.getValue(); return doc.getEPCISBody().getQueryResults(); } catch (JAXBException e) { // wrap JAXBException into IOException to keep the interface // JAXB-free IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
ioe.setStackTrace(e.getStackTrace()); throw ioe;
} catch (JAXBException e) { IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } catch (ParserConfigurationException e) {