package au.gov.ga.geodesy.support.marshalling.moxy;

import java.io.Reader;
import java.io.Writer;
import java.util.Properties;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.springframework.stereotype.Component;

import au.gov.ga.geodesy.interfaces.geodesyml.GeodesyMLMarshaller;
import au.gov.ga.geodesy.interfaces.geodesyml.MarshallingException;
import au.gov.xml.icsm.geodesyml.v_0_2_2.GeodesyMLType;
@Component
public class GeodesyMLMoxy implements GeodesyMLMarshaller {

    private JAXBContext jaxbContext;

    public GeodesyMLMoxy() throws MarshallingException {
        try {
            jaxbContext = JAXBContextFactory.createContext(new Class[] {GeodesyMLType.class}, new Properties());
        } catch (JAXBException e) {
            throw new MarshallingException("Failed to initialise JAXBContext", e);
        }
    }

    private Marshaller createMarshaller() throws MarshallingException {
        try {
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
            return marshaller;
        } catch (JAXBException e) {
            throw new MarshallingException("Failed to create marshaller", e);
        }
    }

    private Unmarshaller createUnmarshaller() throws MarshallingException {
        try {
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            return unmarshaller;
        } catch (JAXBException e) {
            throw new MarshallingException("Failed to create unmarshaller", e);
        }
    }

    public void marshal(GeodesyMLType site, Writer writer) throws MarshallingException {
        try {
            createMarshaller().marshal(site, writer);
        } catch (JAXBException e) {
            throw new MarshallingException("Failed to marshal a site log", e);
        }
    }

    @SuppressWarnings("unchecked")
    public JAXBElement<GeodesyMLType> unmarshal(Reader reader) throws MarshallingException {
        try {
            return (JAXBElement<GeodesyMLType>) createUnmarshaller().unmarshal(reader);
        } catch (JAXBException e) {
            throw new MarshallingException("Failed to unmarshal a site log", e);
        }
    }
}

@@ -1333,16 +1333,121 @@
 59-1%22);%0A
+            marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, %22urn:xml-gov-au:icsm:egeodesy:0.2%22);%0A
         
@@ -1954,16 +1954,28 @@
 marshal(
+JAXBElement%3C
 GeodesyM
@@ -1979,16 +1979,17 @@
 syMLType
+%3E
  site, W

Update marshaller to take JAXBElement<GeodesyMLType>