List of usage examples for javax.xml.bind JAXBException getLinkedException
public Throwable getLinkedException()
From source file:org.opencastproject.index.service.impl.index.event.Event.java
/** * Reads the recording event from the input stream. * * @param xml/*w ww .java 2s . com*/ * the input stream * @return the deserialized recording event * @throws JSONException * @throws XMLStreamException * @throws JAXBException */ public static Event valueOf(InputStream xml) throws IOException { try { if (context == null) { createJAXBContext(); } Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(xml), Event.class).getValue(); } catch (JAXBException e) { throw new IOException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IoSupport.closeQuietly(xml); } }
From source file:org.opencastproject.index.service.impl.index.event.Event.java
/** * Serializes the recording event./*w ww . j av a 2 s. c om*/ * * @param event * the recording event * @return the serialized recording event */ @Override public String toJSON() { try { if (context == null) { createJAXBContext(); } Marshaller marshaller = Event.context.createMarshaller(); Configuration config = new Configuration(); config.setSupressAtAttributes(true); MappedNamespaceConvention con = new MappedNamespaceConvention(config); StringWriter writer = new StringWriter(); XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) { @Override public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException { super.writeStartElement("", local, ""); } @Override public void writeStartElement(String uri, String local) throws XMLStreamException { super.writeStartElement("", local, ""); } @Override public void setPrefix(String pfx, String uri) throws XMLStreamException { } @Override public void setDefaultNamespace(String uri) throws XMLStreamException { } }; marshaller.marshal(this, xmlStreamWriter); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
From source file:org.opencastproject.index.service.impl.index.event.Event.java
/** * Serializes the recording event to an XML format. * * @return A String with this event's content as XML. *//* w w w . j a va 2 s .co m*/ public String toXML() { try { if (context == null) { createJAXBContext(); } StringWriter writer = new StringWriter(); Marshaller marshaller = Event.context.createMarshaller(); marshaller.marshal(this, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
From source file:org.opencastproject.mediapackage.MediaPackageElementParser.java
/** * Serializes the media package element to a string. * /*from w w w. j ava 2 s .c o m*/ * @param element * the element * @return the serialized media package element * @throws MediaPackageException * if serialization failed */ public static String getAsXml(MediaPackageElement element) throws MediaPackageException { if (element == null) throw new IllegalArgumentException("Mediapackage element must not be null"); StringWriter writer = new StringWriter(); Marshaller m = null; try { m = MediaPackageImpl.context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); m.marshal(element, writer); return writer.toString(); } catch (JAXBException e) { throw new MediaPackageException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
From source file:org.opencastproject.mediapackage.MediaPackageImpl.java
/** * Reads the media package from the input stream. * /*from w w w. j ava 2s. co m*/ * @param xml * the input stream * @return the deserialized media package */ public static MediaPackageImpl valueOf(InputStream xml) throws MediaPackageException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(xml), MediaPackageImpl.class).getValue(); } catch (JAXBException e) { throw new MediaPackageException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IoSupport.closeQuietly(xml); } }
From source file:org.opencastproject.security.api.OrganizationParser.java
public static Organization fromXml(String xml) { InputStream in = null;//from w w w . jav a 2s . c o m try { in = IOUtils.toInputStream(xml); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(in), JaxbOrganization.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(in); } }
From source file:org.opencastproject.security.api.OrganizationParser.java
public static String toXml(Organization organization) { try {/* www . j av a 2s.c o m*/ Marshaller marshaller = jaxbContext.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(organization, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
From source file:org.opencastproject.security.api.UserParser.java
public static User fromXml(String xml) { InputStream in = null;// w w w. j a va 2 s. c o m try { in = IOUtils.toInputStream(xml); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(in), JaxbUser.class).getValue(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } finally { IOUtils.closeQuietly(in); } }
From source file:org.opencastproject.security.api.UserParser.java
public static String toXml(User user) { try {/* w ww . j av a 2s .c om*/ Marshaller marshaller = jaxbContext.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(user, writer); return writer.toString(); } catch (JAXBException e) { throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e); } }
From source file:org.opencds.service.evaluate.UnmarshalVMRSchemaPayload2VMR.java
@Override public synchronized JAXBElement<org.opencds.vmr.v1_0.schema.CDSInput> mappingInbound(String payloadString, Date evalTime, TimingData timingData) throws InvalidDriDataFormatExceptionFault, UnrecognizedLanguageExceptionFault, RequiredDataNotProvidedExceptionFault, UnsupportedLanguageExceptionFault, UnrecognizedScopedEntityExceptionFault, EvaluationExceptionFault, InvalidTimeZoneOffsetExceptionFault, DSSRuntimeExceptionFault { // this begins the guts for building fact lists for input data based on one particular fact model (opencds-vmr-1_0) log.debug("starting UnmarshalVMRSchemaPayload2VMR"); JAXBElement<org.opencds.vmr.v1_0.schema.CDSInput> cdsInput = null; StreamSource payloadStream = new StreamSource(fileU.getInputStreamFromString(payloadString)); try {//from w w w .j a va 2s . c o m Unmarshaller unmarshaller = SimpleKnowledgeRepository .getRequiredUnmarshallerInstanceForUnmarshallerClassCache("org.opencds.vmr^VMR^1.0"); cdsInput = unmarshaller.unmarshal(payloadStream, org.opencds.vmr.v1_0.schema.CDSInput.class); } catch (JAXBException e) { String jaxBError = e.getLinkedException().fillInStackTrace().getMessage(); e.printStackTrace(); throw new InvalidDriDataFormatExceptionFault(jaxBError + ", therefore unable to unmarshal input Semantic Payload xml string: " + payloadString); } log.debug("finished UnmarshalVMRSchemaPayload2VMR"); return cdsInput; }