|
|
|
@ -11,6 +11,7 @@ import javax.xml.bind.JAXBException;
|
|
|
|
|
import javax.xml.bind.Marshaller;
|
|
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
|
|
|
|
|
|
|
import org.eclipse.persistence.jaxb.MarshallerProperties;
|
|
|
|
|
import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -22,19 +23,28 @@ import org.gcube.data.analysis.dminvocation.model.DataMinerInvocation;
|
|
|
|
|
*/
|
|
|
|
|
public class DataMinerInvocationManager {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Marshaling.
|
|
|
|
|
*
|
|
|
|
|
* @param dmInvocation the dm invocation
|
|
|
|
|
* @param mediaType the media type
|
|
|
|
|
* @return the byte array output stream
|
|
|
|
|
* @throws JAXBException the JAXB exception
|
|
|
|
|
*/
|
|
|
|
|
public static ByteArrayOutputStream marshaling(DataMinerInvocation dmInvocation) throws JAXBException
|
|
|
|
|
public static ByteArrayOutputStream marshaling(DataMinerInvocation dmInvocation, MediaType mediaType) throws JAXBException
|
|
|
|
|
{
|
|
|
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class);
|
|
|
|
|
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
|
|
|
|
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
|
|
|
|
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
|
|
|
|
|
|
|
|
switch (mediaType) {
|
|
|
|
|
case ApplicationJSON:
|
|
|
|
|
jaxbMarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, Boolean.TRUE);
|
|
|
|
|
case ApplicationXML:
|
|
|
|
|
default:
|
|
|
|
|
jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType.getMimeType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
jaxbMarshaller.marshal(dmInvocation, baos);
|
|
|
|
|
return baos;
|
|
|
|
@ -45,15 +55,25 @@ public class DataMinerInvocationManager {
|
|
|
|
|
* Unmarshaling.
|
|
|
|
|
*
|
|
|
|
|
* @param dmInvocationXMLStream the dm invocation xml file
|
|
|
|
|
* @param mediaType the media type
|
|
|
|
|
* @return the data miner invocation
|
|
|
|
|
* @throws JAXBException the JAXB exception
|
|
|
|
|
*/
|
|
|
|
|
public static DataMinerInvocation unmarshaling(InputStream dmInvocationXMLStream) throws JAXBException
|
|
|
|
|
public static DataMinerInvocation unmarshaling(InputStream dmInvocationXMLStream, MediaType mediaType) throws JAXBException
|
|
|
|
|
{
|
|
|
|
|
//unMarshalingCategories();
|
|
|
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(DataMinerInvocation.class);
|
|
|
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (mediaType) {
|
|
|
|
|
case ApplicationJSON:
|
|
|
|
|
jaxbUnmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, Boolean.TRUE);
|
|
|
|
|
case ApplicationXML:
|
|
|
|
|
default:
|
|
|
|
|
jaxbUnmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType.getMimeType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//We had written this file in marshalling example
|
|
|
|
|
return (DataMinerInvocation) jaxbUnmarshaller.unmarshal(dmInvocationXMLStream);
|
|
|
|
|
|
|
|
|
|