private static void addHL7DeviceExtension(Device device, boolean sampleConfig) {
    HL7DeviceExtension ext = new HL7DeviceExtension();
    device.addDeviceExtension(ext);

    HL7Application hl7App = new HL7Application("*");
    ArchiveHL7ApplicationExtension hl7AppExt = new ArchiveHL7ApplicationExtension();
    hl7App.addHL7ApplicationExtension(hl7AppExt);
    hl7App.setAcceptedMessageTypes(HL7_MESSAGE_TYPES);
    hl7App.setHL7DefaultCharacterSet("8859/1");
    ext.addHL7Application(hl7App);

    Connection hl7 = new Connection("hl7", "localhost", 2575);
    hl7.setBindAddress("0.0.0.0");
    hl7.setClientBindAddress("0.0.0.0");
    hl7.setProtocol(Connection.Protocol.HL7);
    device.addConnection(hl7);
    hl7App.addConnection(hl7);

    if (sampleConfig) {
      Connection hl7TLS = new Connection("hl7-tls", "localhost", 12575);
      hl7TLS.setBindAddress("0.0.0.0");
      hl7TLS.setClientBindAddress("0.0.0.0");
      hl7TLS.setProtocol(Connection.Protocol.HL7);
      hl7TLS.setTlsCipherSuites(
          Connection.TLS_RSA_WITH_AES_128_CBC_SHA, Connection.TLS_RSA_WITH_3DES_EDE_CBC_SHA);
      device.addConnection(hl7TLS);
      hl7App.addConnection(hl7TLS);
    }
  }
  private void loadFrom(HL7Application hl7app, Preferences prefs) {
    hl7app.setAcceptedSendingApplications(
        PreferencesUtils.stringArray(prefs, "hl7AcceptedSendingApplication"));
    hl7app.setAcceptedMessageTypes(PreferencesUtils.stringArray(prefs, "hl7AcceptedMessageType"));
    hl7app.setHL7DefaultCharacterSet(prefs.get("hl7DefaultCharacterSet", null));
    hl7app.setInstalled(PreferencesUtils.booleanValue(prefs.get("dicomInstalled", null)));

    for (PreferencesHL7ConfigurationExtension ext : extensions) ext.loadFrom(hl7app, prefs);
  }