private void reconfigureAEExtensions(ApplicationEntity from) {
   for (Iterator<Class<? extends AEExtension>> it = extensions.keySet().iterator();
       it.hasNext(); ) {
     if (!from.extensions.containsKey(it.next())) it.remove();
   }
   for (AEExtension src : from.extensions.values()) {
     Class<? extends AEExtension> clazz = src.getClass();
     AEExtension ext = extensions.get(clazz);
     if (ext == null)
       try {
         addAEExtension(ext = clazz.newInstance());
       } catch (Exception e) {
         throw new RuntimeException("Failed to instantiate " + clazz.getName(), e);
       }
     ext.reconfigure(src);
   }
 }
  private static ApplicationEntity createAE(
      String aet,
      String description,
      Connection dicom,
      Connection dicomTLS,
      QueryRetrieveView qrView,
      boolean storeSCP,
      boolean storeSCU) {
    ApplicationEntity ae = new ApplicationEntity(aet);
    ae.setDescription(description);
    ae.addConnection(dicom);
    if (dicomTLS != null) ae.addConnection(dicomTLS);

    ArchiveAEExtension aeExt = new ArchiveAEExtension();
    ae.addAEExtension(aeExt);
    ae.setAssociationAcceptor(true);
    ae.setAssociationInitiator(true);
    addTC(ae, null, SCP, UID.VerificationSOPClass, UID.ImplicitVRLittleEndian);
    addTC(ae, null, SCU, UID.VerificationSOPClass, UID.ImplicitVRLittleEndian);
    addTCs(ae, EnumSet.allOf(QueryOption.class), SCP, QUERY_CUIDS, UID.ImplicitVRLittleEndian);
    if (storeSCU) {
      addTCs(
          ae, EnumSet.of(QueryOption.RELATIONAL), SCP, RETRIEVE_CUIDS, UID.ImplicitVRLittleEndian);
      for (int i = 0; i < CUIDS_TSUIDS.length; i++, i++)
        addTCs(ae, null, SCU, CUIDS_TSUIDS[i], CUIDS_TSUIDS[i + 1]);
    }
    if (storeSCP) {
      for (int i = 0; i < CUIDS_TSUIDS.length; i++, i++)
        addTCs(ae, null, SCP, CUIDS_TSUIDS[i], CUIDS_TSUIDS[i + 1]);
      addTC(ae, null, SCP, UID.StorageCommitmentPushModelSOPClass, UID.ImplicitVRLittleEndian);
      addTC(ae, null, SCP, UID.ModalityPerformedProcedureStepSOPClass, UID.ImplicitVRLittleEndian);
      addTC(ae, null, SCU, UID.ModalityPerformedProcedureStepSOPClass, UID.ImplicitVRLittleEndian);
    }
    aeExt.setQueryRetrieveViewID(qrView.getViewID());
    return ae;
  }