class XmlDataExporter implements DataExporter {

  @Override
  public void exportData(SyncData syncData) {
    String outputPath = properties.getProperty(OUTPUT_PATH);
    checkNotNull(outputPath, "Missing %s in properties", OUTPUT_PATH);
    File outputDirectory = new File(outputPath);
    checkState(outputDirectory.exists(), "Invalid destination: %s doesn't exist", outputPath);
    checkState(outputDirectory.isDirectory(), "Invalid destination: %s is not a directory", outputPath);

    XmlMapper xmlMapper = new XmlMapper();
    ObjectWriter objectWriter = xmlMapper.writerWithDefaultPrettyPrinter();

    Patient patient = new Patient();
    patient.SerialNumber = syncData.getDeviceInfo().getSerialNumber();
    sort(syncData.getGlucoseReads());
    patient.Glucose = newArrayList(Collections2.transform(syncData.getGlucoseReads(),
            GLUCOSE_READ_TO_TIMESTAMPED_VALUE));
    List<EventMarker> eventMarkers = newArrayList(
            Collections2.transform(syncData.getExerciseSessions(), EXERCISE_SESSION_TO_EVENT_MARKER));
    eventMarkers.addAll(Collections2.transform(syncData.getFoodEvents(), FOOD_EVENT_TO_EVENT_MARKER));
    eventMarkers.addAll(Collections2.transform(syncData.getInsulinInjections(), INSULIN_INJECTION_TO_EVENT_MARKER));
    sort(eventMarkers);
    patient.Event = eventMarkers;

    try {
      OutputStream outputStream = getOutputStream(outputDirectory, syncData);
      objectWriter.writeValue(outputStream, patient);
      outputStream.close();
    } catch (IOException e) {
      throw Throwables.propagate(e);
    }
  }

  @Inject public  XmlDataExporter(BloodShepherdProperties properties);

}