mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
03.10.2014 31216400c324b43c15b8a9eea6d89604247ebb14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 */
 
package org.opends.guitools.uninstaller;
 
import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
 
import org.opends.admin.ads.ADSContext;
import org.opends.admin.ads.ServerDescriptor;
import org.opends.admin.ads.TopologyCache;
import org.opends.admin.ads.TopologyCacheException;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.guitools.controlpanel.datamodel.ConnectionProtocolPolicy;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
 
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.messages.QuickSetupMessages.*;
 
import org.opends.quicksetup.*;
import org.opends.quicksetup.event.ProgressUpdateEvent;
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
import org.opends.quicksetup.util.ServerController;
import org.opends.quicksetup.util.Utils;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.ToolConstants;
import org.opends.server.tools.dsconfig.LDAPManagementContextFactory;
import org.opends.server.util.args.ArgumentException;
import org.opends.server.util.cli.CLIException;
import org.opends.server.util.cli.ConsoleApplication;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
import org.opends.server.util.cli.Menu;
import org.opends.server.util.cli.MenuBuilder;
import org.opends.server.util.cli.MenuResult;
 
 
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Collections;
 
import org.forgerock.i18n.slf4j.LocalizedLogger;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
 
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.net.ssl.TrustManager;
 
/**
 * The class used to provide some CLI interface in the uninstall.
 *
 * This class basically is in charge of parsing the data provided by the user
 * in the command line and displaying messages asking the user for information.
 *
 * Once the user has provided all the required information it calls Uninstaller
 * and launches it.
 *
 */
public class UninstallCliHelper extends ConsoleApplication {
 
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
  private UninstallerArgumentParser parser;
 
  private boolean forceNonInteractive;
 
  private LDAPConnectionConsoleInteraction ci = null;
 
  private ControlPanelInfo info;
 
  // This CLI is always using the administration connector with SSL
  private final boolean alwaysSSL = true;
  private boolean useSSL = true;
  private boolean useStartTLS = false;
 
  /**
   * Default constructor.
   */
  public UninstallCliHelper()
  {
    super(System.in, System.out, System.err);
  }
 
  /**
   * Creates a UserData based in the arguments provided.  It asks
   * user for additional information if what is provided in the arguments is not
   * enough.
   * @param args the ArgumentParser with the allowed arguments of the command
   * line.  The code assumes that the arguments have already been parsed.
   * @param rawArguments the arguments provided in the command line.
   * @return the UserData object with what the user wants to uninstall
   * and null if the user cancels the uninstallation.
   * @throws UserDataException if there is an error with the data
   * in the arguments.
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   */
  public UninstallUserData createUserData(UninstallerArgumentParser args,
      String[] rawArguments)
  throws UserDataException, ApplicationException
  {
    parser = args;
    UninstallUserData userData = new UninstallUserData();
    try
    {
      boolean isInteractive;
      boolean isQuiet;
      boolean isVerbose;
      boolean isCanceled = false;
 
      /* Step 1: analyze the arguments.
       */
 
      isInteractive = args.isInteractive();
 
      isQuiet = args.isQuiet();
 
      isVerbose = args.isVerbose();
 
      userData.setQuiet(isQuiet);
      userData.setVerbose(isVerbose);
      userData.setForceOnError(args.isForceOnError());
      userData.setTrustManager(args.getTrustManager());
 
      userData.setConnectTimeout(getConnectTimeout());
 
      /*
       * Step 2: check that the provided parameters are compatible.
       */
      LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
      int v = args.validateGlobalOptions(buf);
      if (v != DsFrameworkCliReturnCode.SUCCESSFUL_NOP.getReturnCode())
      {
        throw new UserDataException(null, buf.toMessage());
      }
 
      /* Step 3: If this is an interactive uninstall ask for confirmation to
       * delete the different parts of the installation if the user did not
       * specify anything to delete.  If we are not in interactive mode
       * check that the user specified something to be deleted.
       */
      Set<String> outsideDbs;
      Set<String> outsideLogs;
      Configuration config =
        Installation.getLocal().getCurrentConfiguration();
      try {
        outsideDbs = config.getOutsideDbs();
      } catch (IOException ioe) {
        outsideDbs = Collections.emptySet();
        logger.debug(LocalizableMessage.raw("error determining outside databases", ioe));
      }
 
      try {
        outsideLogs = config.getOutsideLogs();
      } catch (IOException ioe) {
        outsideLogs = Collections.emptySet();
        logger.debug(LocalizableMessage.raw("error determining outside logs", ioe));
      }
 
      boolean somethingSpecifiedToDelete =
        args.removeAll() ||
        args.removeBackupFiles() ||
        args.removeDatabases() ||
        args.removeLDIFFiles() ||
        args.removeConfigurationFiles() ||
        args.removeLogFiles() ||
        args.removeServerLibraries();
 
      if (somethingSpecifiedToDelete)
      {
        userData.setRemoveBackups(args.removeAll() || args.removeBackupFiles());
        userData.setRemoveConfigurationAndSchema(args.removeAll() ||
            args.removeConfigurationFiles());
        userData.setRemoveDatabases(args.removeAll() || args.removeDatabases());
        userData.setRemoveLDIFs(args.removeAll() || args.removeLDIFFiles());
        userData.setRemoveLibrariesAndTools(args.removeAll() ||
            args.removeServerLibraries());
        userData.setRemoveLogs(args.removeAll() || args.removeLogFiles());
 
        userData.setExternalDbsToRemove(outsideDbs);
        userData.setExternalLogsToRemove(outsideLogs);
      }
      else
      {
        if (!isInteractive)
        {
          throw new UserDataException(null,
             ERR_CLI_UNINSTALL_NOTHING_TO_BE_UNINSTALLED_NON_INTERACTIVE.get());
        }
        else
        {
          isCanceled = askWhatToDelete(userData, outsideDbs, outsideLogs);
        }
      }
      String adminUid = args.getAdministratorUID();
      if ((adminUid == null) && !args.isInteractive())
      {
        adminUid = args.getDefaultAdministratorUID();
      }
      userData.setAdminUID(adminUid);
      userData.setAdminPwd(args.getBindPassword());
      String referencedHostName = args.getReferencedHostName();
      if ((referencedHostName == null) && !args.isInteractive())
      {
        referencedHostName = args.getDefaultReferencedHostName();
      }
      try
      {
        UninstallData d = new UninstallData(Installation.getLocal());
        userData.setReplicationServer(
            referencedHostName+":"+d.getReplicationServerPort());
      }
      catch (Throwable t)
      {
        logger.error(LocalizableMessage.raw("Could not create UninstallData: "+t, t));
        userData.setReplicationServer(
            referencedHostName+":8989");
      }
      info = ControlPanelInfo.getInstance();
      info.setTrustManager(userData.getTrustManager());
      info.setConnectTimeout(getConnectTimeout());
      info.regenerateDescriptor();
      info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
 
      String adminConnectorUrl = info.getAdminConnectorURL();
 
      if (adminConnectorUrl == null)
      {
        logger.warn(LocalizableMessage.raw(
        "Error retrieving a valid LDAP URL in conf file."));
        if (!parser.isInteractive())
        {
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
        }
      }
      userData.setLocalServerUrl(adminConnectorUrl);
      userData.setReferencedHostName(referencedHostName);
 
      /*
       * Step 4: check if server is running.  Depending if it is running and the
       * OS we are running, ask for authentication information.
       */
      if (!isCanceled)
      {
        isCanceled = checkServerState(userData);
      }
 
      if (isCanceled && !userData.isForceOnError())
      {
        logger.debug(LocalizableMessage.raw("User cancelled uninstall."));
        userData = null;
      }
 
      if ((userData != null) && !args.isQuiet())
      {
        println();
      }
    }
    catch (Throwable t)
    {
      logger.warn(LocalizableMessage.raw("Exception: "+t, t));
      if (t instanceof UserDataException)
      {
        throw (UserDataException)t;
      }
      else if (t instanceof ApplicationException)
      {
        throw (ApplicationException)t;
      }
      else
      {
        throw new IllegalStateException("Unexpected error: "+t, t);
      }
    }
    logger.debug(LocalizableMessage.raw("Successfully created user data"));
    return userData;
  }
 
  /**
   * Commodity method used to ask the user to confirm the deletion of certain
   * parts of the server.  It updates the provided UserData object
   * accordingly.  Returns <CODE>true</CODE> if the user cancels and <CODE>
   * false</CODE> otherwise.
   * @param userData the UserData object to be updated.
   * @param outsideDbs the set of relative paths of databases located outside
   * the installation path of the server.
   * @param outsideLogs the set of relative paths of log files located outside
   * the installation path of the server.
   * @return <CODE>true</CODE> if the user cancels and <CODE>false</CODE>
   * otherwise.
   */
  private boolean askWhatToDelete(UninstallUserData userData,
      Set<String> outsideDbs, Set<String> outsideLogs) throws UserDataException
  {
    boolean cancelled = false;
    final int REMOVE_ALL = 1;
    final int SPECIFY_TO_REMOVE = 2;
    int[] indexes = {REMOVE_ALL, SPECIFY_TO_REMOVE};
    LocalizableMessage[] msgs = new LocalizableMessage[] {
        INFO_CLI_UNINSTALL_REMOVE_ALL.get(),
        INFO_CLI_UNINSTALL_SPECIFY_WHAT_REMOVE.get()
      };
 
    MenuBuilder<Integer> builder = new MenuBuilder<Integer>(this);
    builder.setPrompt(INFO_CLI_UNINSTALL_WHAT_TO_DELETE.get());
 
    for (int i=0; i<indexes.length; i++)
    {
      builder.addNumberedOption(msgs[i], MenuResult.success(indexes[i]));
    }
 
    builder.addQuitOption();
 
    builder.setDefault(LocalizableMessage.raw(String.valueOf(REMOVE_ALL)),
        MenuResult.success(REMOVE_ALL));
 
    builder.setMaxTries(CONFIRMATION_MAX_TRIES);
 
    Menu<Integer> menu = builder.toMenu();
    int choice;
    try
    {
      MenuResult<Integer> m = menu.run();
      if (m.isSuccess())
      {
        choice = m.getValue();
      }
      else if (m.isQuit())
      {
        choice = REMOVE_ALL;
        cancelled = true;
      }
      else
      {
        // Should never happen.
        throw new RuntimeException();
      }
    }
    catch (CLIException ce)
    {
      logger.warn(LocalizableMessage.raw("Error reading input: "+ce, ce));
      throw new UserDataException(null, ce.getMessageObject(), ce);
    }
 
    if (cancelled)
    {
      // Nothing to do
    }
    else if (choice == REMOVE_ALL)
    {
      userData.setRemoveBackups(true);
      userData.setRemoveConfigurationAndSchema(true);
      userData.setRemoveDatabases(true);
      userData.setRemoveLDIFs(true);
      userData.setRemoveLibrariesAndTools(true);
      userData.setRemoveLogs(true);
 
      userData.setExternalDbsToRemove(outsideDbs);
      userData.setExternalLogsToRemove(outsideLogs);
    }
    else
    {
      boolean somethingSelected = false;
      while (!somethingSelected && !cancelled)
      {
        println();
//      Ask for confirmation for the different items
        msgs = new LocalizableMessage [] {
                INFO_CLI_UNINSTALL_CONFIRM_LIBRARIES_BINARIES.get(),
                INFO_CLI_UNINSTALL_CONFIRM_DATABASES.get(),
                INFO_CLI_UNINSTALL_CONFIRM_LOGS.get(),
                INFO_CLI_UNINSTALL_CONFIRM_CONFIGURATION_SCHEMA.get(),
                INFO_CLI_UNINSTALL_CONFIRM_BACKUPS.get(),
                INFO_CLI_UNINSTALL_CONFIRM_LDIFS.get(),
                INFO_CLI_UNINSTALL_CONFIRM_OUTSIDEDBS.get(
                        Utils.getStringFromCollection(outsideDbs,
                                Constants.LINE_SEPARATOR)),
                INFO_CLI_UNINSTALL_CONFIRM_OUTSIDELOGS.get(
                        Utils.getStringFromCollection(outsideLogs,
                                Constants.LINE_SEPARATOR)
                )
        };
 
        boolean[] answers = new boolean[msgs.length];
        try
        {
          for (int i=0; i<msgs.length; i++)
          {
            boolean ignore = ((i == 6) && (outsideDbs.size() == 0)) ||
            ((i == 7) && (outsideLogs.size() == 0));
            if (!ignore)
            {
              answers[i] = askConfirmation(msgs[i], true, logger);
            }
            else
            {
              answers[i] = false;
            }
          }
        }
        catch (CLIException ce)
        {
          throw new UserDataException(null, ce.getMessageObject(), ce);
        }
 
        if (!cancelled)
        {
          for (int i=0; i<answers.length; i++)
          {
            switch (i)
            {
            case 0:
              userData.setRemoveLibrariesAndTools(answers[i]);
              break;
 
            case 1:
              userData.setRemoveDatabases(answers[i]);
              break;
 
            case 2:
              userData.setRemoveLogs(answers[i]);
              break;
 
            case 3:
              userData.setRemoveConfigurationAndSchema(answers[i]);
              break;
 
            case 4:
              userData.setRemoveBackups(answers[i]);
              break;
 
            case 5:
              userData.setRemoveLDIFs(answers[i]);
              break;
 
            case 6:
              if (answers[i])
              {
                userData.setExternalDbsToRemove(outsideDbs);
              }
              break;
 
            case 7:
              if (answers[i])
              {
                userData.setExternalLogsToRemove(outsideLogs);
              }
              break;
            }
          }
          if ((userData.getExternalDbsToRemove().size() == 0) &&
              (userData.getExternalLogsToRemove().size() == 0) &&
              !userData.getRemoveLibrariesAndTools() &&
              !userData.getRemoveDatabases() &&
              !userData.getRemoveConfigurationAndSchema() &&
              !userData.getRemoveBackups() &&
              !userData.getRemoveLDIFs() &&
              !userData.getRemoveLogs())
          {
            somethingSelected = false;
            println();
            printErrorMessage(
                ERR_CLI_UNINSTALL_NOTHING_TO_BE_UNINSTALLED.get());
          }
          else
          {
            somethingSelected = true;
          }
        }
      }
    }
 
    return cancelled;
  }
 
  /**
   * Commodity method used to ask the user (when necessary) if the server must
   * be stopped or not.  It also prompts (if required) for authentication.
   * @param userData the UserData object to be updated with the
   * authentication of the user.
   * @return <CODE>true</CODE> if the user wants to continue with uninstall and
   * <CODE>false</CODE> otherwise.
   * @throws UserDataException if there is a problem with the data
   * provided by the user (in the particular case where we are on
   * non-interactive uninstall and some data is missing or not valid).
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   */
  private boolean checkServerState(UninstallUserData userData)
  throws UserDataException, ApplicationException
  {
    boolean cancelled = false;
    boolean interactive = parser.isInteractive();
    boolean forceOnError = parser.isForceOnError();
    UninstallData conf = null;
    try
    {
      conf = new UninstallData(Installation.getLocal());
    }
    catch (Throwable t)
    {
      logger.warn(LocalizableMessage.raw("Error processing task: "+t, t));
      throw new UserDataException(Step.CONFIRM_UNINSTALL,
          Utils.getThrowableMsg(INFO_BUG_MSG.get(), t));
    }
    logger.debug(LocalizableMessage.raw("interactive: "+interactive));
    logger.debug(LocalizableMessage.raw("forceOnError: "+forceOnError));
    logger.debug(LocalizableMessage.raw("conf.isADS(): "+conf.isADS()));
    logger.debug(LocalizableMessage.raw("conf.isReplicationServer(): "+
        conf.isReplicationServer()));
    logger.debug(LocalizableMessage.raw("conf.isServerRunning(): "+conf.isServerRunning()));
    if (conf.isADS() && conf.isReplicationServer())
    {
      if (conf.isServerRunning())
      {
        if (interactive)
        {
          try
          {
            if (confirmToUpdateRemote())
            {
              println();
              cancelled = !askForAuthenticationIfNeeded(userData);
              if (cancelled)
              {
                /* Ask for confirmation to stop server */
                println();
                cancelled = !confirmToStopServer();
              }
              else
              {
                cancelled = !updateUserUninstallDataWithRemoteServers(userData);
                if (cancelled)
                {
                  println();
                  /* Ask for confirmation to stop server */
                  cancelled = !confirmToStopServer();
                }
              }
            }
            else
            {
              println();
              /* Ask for confirmation to stop server */
              cancelled = !confirmToStopServer();
            }
          }
          catch (CLIException ce)
          {
            throw new UserDataException(null, ce.getMessageObject(), ce);
          }
        }
        else
        {
          boolean errorWithRemote =
            !updateUserUninstallDataWithRemoteServers(userData);
          cancelled = errorWithRemote && !parser.isForceOnError();
          logger.debug(LocalizableMessage.raw("Non interactive mode.  errorWithRemote: "+
              errorWithRemote));
        }
      }
      else
      {
        if (interactive)
        {
          println();
          try
          {
            if (confirmToUpdateRemoteAndStart())
            {
              boolean startWorked = startServer(userData.isQuiet());
              // Ask for authentication if needed, etc.
              if (startWorked)
              {
                cancelled = !askForAuthenticationIfNeeded(userData);
                if (cancelled)
                {
                  println();
                  /* Ask for confirmation to stop server */
                  cancelled = !confirmToStopServer();
                }
                else
                {
                  cancelled =
                    !updateUserUninstallDataWithRemoteServers(userData);
                  if (cancelled)
                  {
                    println();
                    /* Ask for confirmation to stop server */
                    cancelled = !confirmToStopServer();
                  }
                }
                userData.setStopServer(true);
              }
              else
              {
                userData.setStopServer(false);
                println();
                /* Ask for confirmation to delete files */
                cancelled = !confirmDeleteFiles();
              }
            }
            else
            {
              println();
              /* Ask for confirmation to delete files */
              cancelled = !confirmDeleteFiles();
            }
          }
          catch (CLIException ce)
          {
            throw new UserDataException(null, ce.getMessageObject(), ce);
          }
        }
        else
        {
          boolean startWorked = startServer(userData.isQuiet());
          // Ask for authentication if needed, etc.
          if (startWorked)
          {
            userData.setStopServer(true);
            boolean errorWithRemote =
              !updateUserUninstallDataWithRemoteServers(userData);
            cancelled = errorWithRemote && !parser.isForceOnError();
          }
          else
          {
            cancelled  = !forceOnError;
            userData.setStopServer(false);
          }
        }
      }
      if (!cancelled || parser.isForceOnError())
      {
        /* During all the confirmations, the server might be stopped. */
        userData.setStopServer(
            Installation.getLocal().getStatus().isServerRunning());
        logger.debug(LocalizableMessage.raw("Must stop the server after confirmations? "+
            userData.getStopServer()));
      }
    }
    else
    {
      if (conf.isServerRunning())
      {
        try
        {
          if (interactive)
          {
            println();
            /* Ask for confirmation to stop server */
            cancelled = !confirmToStopServer();
          }
 
          if (!cancelled)
          {
            /* During all the confirmations, the server might be stopped. */
            userData.setStopServer(
                Installation.getLocal().getStatus().isServerRunning());
            logger.debug(LocalizableMessage.raw("Must stop the server after confirmations? "+
                userData.getStopServer()));
          }
        }
        catch (CLIException ce)
        {
          throw new UserDataException(null, ce.getMessageObject(), ce);
        }
      }
      else
      {
        userData.setStopServer(false);
        if (interactive)
        {
          println();
          /* Ask for confirmation to delete files */
          try
          {
            cancelled = !confirmDeleteFiles();
          }
          catch (CLIException ce)
          {
            throw new UserDataException(null, ce.getMessageObject(), ce);
          }
        }
      }
    }
    logger.debug(LocalizableMessage.raw("cancelled: "+cancelled));
    return cancelled;
  }
 
  /**
   *  Ask for confirmation to stop server.
   *  @return <CODE>true</CODE> if the user wants to continue and stop the
   *  server.  <CODE>false</CODE> otherwise.
   *  @throws CLIException if the user reached the confirmation limit.
   */
  private boolean confirmToStopServer() throws CLIException
  {
    return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_STOP.get(), true, logger);
  }
 
  /**
   *  Ask for confirmation to delete files.
   *  @return <CODE>true</CODE> if the user wants to continue and delete the
   *  files.  <CODE>false</CODE> otherwise.
   *  @throws CLIException if the user reached the confirmation limit.
   */
  private boolean confirmDeleteFiles() throws CLIException
  {
    return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_DELETE_FILES.get(), true,
        logger);
  }
 
  /**
   *  Ask for confirmation to update configuration on remote servers.
   *  @return <CODE>true</CODE> if the user wants to continue and stop the
   *  server.  <CODE>false</CODE> otherwise.
   *  @throws CLIException if the user reached the confirmation limit.
   */
  private boolean confirmToUpdateRemote() throws CLIException
  {
    return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_UPDATE_REMOTE.get(), true,
        logger);
  }
 
  /**
   *  Ask for confirmation to update configuration on remote servers.
   *  @return <CODE>true</CODE> if the user wants to continue and stop the
   *  server.  <CODE>false</CODE> otherwise.
   *  @throws CLIException if the user reached the confirmation limit.
   */
  private boolean confirmToUpdateRemoteAndStart() throws CLIException
  {
    return askConfirmation(
        INFO_CLI_UNINSTALL_CONFIRM_UPDATE_REMOTE_AND_START.get(), true, logger);
  }
 
  /**
   *  Ask for confirmation to provide again authentication.
   *  @return <CODE>true</CODE> if the user wants to provide authentication
   *  again.  <CODE>false</CODE> otherwise.
   *  @throws CLIException if the user reached the confirmation limit.
   */
  private boolean promptToProvideAuthenticationAgain() throws CLIException
  {
    return askConfirmation(
        INFO_UNINSTALL_CONFIRM_PROVIDE_AUTHENTICATION_AGAIN.get(), true, logger);
  }
 
  /**
   *  Ask for data required to update configuration on remote servers.  If
   *  all the data is provided and validated, we assume that the user wants
   *  to update the remote servers.
   *  @return <CODE>true</CODE> if the user wants to continue and update the
   *  remote servers.  <CODE>false</CODE> otherwise.
   *  @throws UserDataException if there is a problem with the information
   *  provided by the user.
   *  @throws ApplicationException if there is an error processing data.
   */
  private boolean askForAuthenticationIfNeeded(UninstallUserData userData)
  throws UserDataException, ApplicationException
  {
    boolean accepted = true;
    String uid = userData.getAdminUID();
    String pwd = userData.getAdminPwd();
 
    boolean couldConnect = false;
 
    while (!couldConnect && accepted)
    {
 
      // This is done because we do not need to ask the user about these
      // parameters.  If we force their presence the class
      // LDAPConnectionConsoleInteraction will not prompt the user for
      // them.
      SecureConnectionCliArgs secureArgsList = parser.getSecureArgsList();
 
      secureArgsList.hostNameArg.setPresent(true);
      secureArgsList.portArg.setPresent(true);
      secureArgsList.hostNameArg.clearValues();
      secureArgsList.hostNameArg.addValue(
          secureArgsList.hostNameArg.getDefaultValue());
      secureArgsList.portArg.clearValues();
      secureArgsList.portArg.addValue(
          secureArgsList.portArg.getDefaultValue());
      secureArgsList.bindDnArg.clearValues();
      if (uid != null)
      {
        secureArgsList.bindDnArg.addValue(ADSContext.getAdministratorDN(uid));
        secureArgsList.bindDnArg.setPresent(true);
      }
      else
      {
        secureArgsList.bindDnArg.setPresent(false);
      }
      secureArgsList.bindPasswordArg.clearValues();
      if (pwd != null)
      {
        secureArgsList.bindPasswordArg.addValue(pwd);
        secureArgsList.bindPasswordArg.setPresent(true);
      }
      else
      {
        secureArgsList.bindPasswordArg.setPresent(false);
      }
 
      if (ci == null)
      {
        ci =
        new LDAPConnectionConsoleInteraction(this, parser.getSecureArgsList());
        ci.setDisplayLdapIfSecureParameters(true);
      }
 
      InitialLdapContext ctx = null;
      try
      {
        ci.run(true, false);
        userData.setAdminUID(ci.getAdministratorUID());
        userData.setAdminPwd(ci.getBindPassword());
 
        info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
 
        String adminConnectorUrl = info.getAdminConnectorURL();
        if (adminConnectorUrl == null)
        {
          logger.warn(LocalizableMessage.raw(
         "Error retrieving a valid Administration Connector URL in conf file."));
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
            throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
                null);
        }
        try
        {
          URI uri = new URI(adminConnectorUrl);
          int port = uri.getPort();
          secureArgsList.portArg.clearValues();
          secureArgsList.portArg.addValue(String.valueOf(port));
          ci.setPortNumber(port);
        }
        catch (Throwable t)
        {
          logger.error(LocalizableMessage.raw("Error parsing url: "+adminConnectorUrl));
        }
        LDAPManagementContextFactory factory =
          new LDAPManagementContextFactory(alwaysSSL);
        factory.getManagementContext(this, ci);
        updateTrustManager(userData, ci);
 
        info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
 
        adminConnectorUrl = info.getAdminConnectorURL();
 
        if (adminConnectorUrl == null)
        {
          logger.warn(LocalizableMessage.raw(
         "Error retrieving a valid Administration Connector URL in conf file."));
          LocalizableMessage msg = ERR_COULD_NOT_FIND_VALID_LDAPURL.get();
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
        }
 
        userData.setLocalServerUrl(adminConnectorUrl);
        couldConnect = true;
      }
      catch (ArgumentException e) {
        printErrorMessage(e.getMessageObject());
        println();
      }
      catch (ClientException e) {
        printErrorMessage(e.getMessageObject());
        println();
      }
      finally
      {
        if (ctx != null)
        {
          try
          {
            ctx.close();
          }
          catch (Throwable t)
          {
            logger.debug(LocalizableMessage.raw("Error closing connection: "+t, t));
          }
        }
      }
 
      if (!couldConnect)
      {
        try
        {
          accepted = promptToProvideAuthenticationAgain();
          if (accepted)
          {
            uid = null;
            pwd = null;
          }
        }
        catch (CLIException ce)
        {
          throw new UserDataException(null, ce.getMessageObject(), ce);
        }
      }
    }
 
    if (accepted)
    {
      String referencedHostName = parser.getReferencedHostName();
      while (referencedHostName == null)
      {
        println();
        referencedHostName = askForReferencedHostName(userData.getHostName());
      }
      try
      {
        UninstallData d = new UninstallData(Installation.getLocal());
        userData.setReplicationServer(
            referencedHostName+":"+d.getReplicationServerPort());
        userData.setReferencedHostName(referencedHostName);
      }
      catch (Throwable t)
      {
        logger.error(LocalizableMessage.raw("Could not create UninstallData: "+t, t));
      }
    }
    userData.setUpdateRemoteReplication(accepted);
    return accepted;
  }
 
  private String askForReferencedHostName(String defaultHostName)
  {
    String s = defaultHostName;
    try
    {
      s = readInput(INFO_UNINSTALL_CLI_REFERENCED_HOSTNAME_PROMPT.get(),
          defaultHostName);
    }
    catch (CLIException ce)
    {
      logger.warn(LocalizableMessage.raw("Error reading input: %s", ce), ce);
    }
    return s;
  }
 
  private boolean startServer(boolean supressOutput)
  {
    logger.debug(LocalizableMessage.raw("startServer, supressOutput: "+supressOutput));
    boolean serverStarted = false;
    Application application = new Application()
    {
      /**
       * {@inheritDoc}
       */
      public String getInstallationPath()
      {
        return Installation.getLocal().getRootDirectory().getAbsolutePath();
      }
      /**
       * {@inheritDoc}
       */
      public String getInstancePath()
      {
        String installPath =  getInstallationPath();
 
        // look for <installPath>/lib/resource.loc
        String instancePathFileName = installPath + File.separator + "lib"
        + File.separator + "resource.loc";
        File f = new File(instancePathFileName);
 
        if (! f.exists())
        {
          return installPath;
        }
 
        BufferedReader reader;
        try
        {
          reader = new BufferedReader(new FileReader(instancePathFileName));
        }
        catch (Exception e)
        {
          return installPath;
        }
 
 
        // Read the first line and close the file.
        String line;
        try
        {
          line = reader.readLine();
          return new File(line).getAbsolutePath();
        }
        catch (Exception e)
        {
          return installPath;
        }
        finally
        {
          try
          {
            reader.close();
          } catch (Exception e) {}
        }
      }
      /**
       * {@inheritDoc}
       */
      public ProgressStep getCurrentProgressStep()
      {
        return UninstallProgressStep.NOT_STARTED;
      }
      /**
       * {@inheritDoc}
       */
      public Integer getRatio(ProgressStep step)
      {
        return 0;
      }
      /**
       * {@inheritDoc}
       */
      public LocalizableMessage getSummary(ProgressStep step)
      {
        return null;
      }
      /**
       * {@inheritDoc}
       */
      public boolean isFinished()
      {
        return false;
      }
      /**
       * {@inheritDoc}
       */
      public boolean isCancellable()
      {
        return false;
      }
      /**
       * {@inheritDoc}
       */
      public void cancel()
      {
      }
      /**
       * {@inheritDoc}
       */
      public void run()
      {
      }
    };
    application.setProgressMessageFormatter(
        new PlainTextProgressMessageFormatter());
    if (!supressOutput)
    {
      application.addProgressUpdateListener(
          new ProgressUpdateListener() {
            public void progressUpdate(ProgressUpdateEvent ev) {
              System.out.print(ev.getNewLogs().toString());
              System.out.flush();
            }
          });
    }
    ServerController controller = new ServerController(application,
        Installation.getLocal());
    try
    {
      if (!supressOutput)
      {
        printlnProgress();
      }
      controller.startServer(supressOutput);
      if (!supressOutput)
      {
        printlnProgress();
      }
      serverStarted = Installation.getLocal().getStatus().isServerRunning();
      logger.debug(LocalizableMessage.raw("server started successfully. serverStarted: "+
          serverStarted));
    }
    catch (ApplicationException ae)
    {
      logger.warn(LocalizableMessage.raw("ApplicationException: "+ae, ae));
      if (!supressOutput)
      {
        printErrorMessage(ae.getMessageObject());
      }
    }
    catch (Throwable t)
    {
      logger.error(LocalizableMessage.raw("Unexpected error: "+t, t));
      throw new IllegalStateException("Unexpected error: "+t, t);
    }
    return serverStarted;
  }
 
  /**
   * Updates the contents of the UninstallUserData while trying to connect
   * to the remote servers.  It returns <CODE>true</CODE> if we could connect
   * to the remote servers and all the presented certificates were accepted and
   * <CODE>false</CODE> otherwise.
   * continue if
   * @param userData the user data to be updated.
   * @return <CODE>true</CODE> if we could connect
   * to the remote servers and all the presented certificates were accepted and
   * <CODE>false</CODE> otherwise.
   * @throws UserDataException if were are not in interactive mode and not in
   * force on error mode and the operation must be stopped.
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   */
  private boolean updateUserUninstallDataWithRemoteServers(
      UninstallUserData userData) throws UserDataException, ApplicationException
  {
    boolean accepted = false;
    boolean interactive = parser.isInteractive();
    boolean forceOnError = parser.isForceOnError();
 
    boolean exceptionOccurred = true;
 
    LocalizableMessage exceptionMsg = null;
 
    logger.debug(LocalizableMessage.raw("Updating user data with remote servers."));
 
    InitialLdapContext ctx = null;
    try
    {
      info.setTrustManager(userData.getTrustManager());
      info.setConnectTimeout(getConnectTimeout());
      String host = "localhost";
      int port = 389;
      String adminUid = userData.getAdminUID();
      String pwd = userData.getAdminPwd();
      String dn = ADSContext.getAdministratorDN(adminUid);
 
      info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
      String adminConnectorUrl = info.getAdminConnectorURL();
      try
      {
        URI uri = new URI(adminConnectorUrl);
        host = uri.getHost();
        port = uri.getPort();
      }
      catch (Throwable t)
      {
        logger.error(LocalizableMessage.raw("Error parsing url: "+adminConnectorUrl));
      }
      ctx = createAdministrativeContext(host, port, useSSL, useStartTLS, dn,
          pwd, getConnectTimeout(),
          userData.getTrustManager());
 
      ADSContext adsContext = new ADSContext(ctx);
      if (interactive && (userData.getTrustManager() == null))
      {
        // This is required when the user did  connect to the server using SSL
        // or Start TLS in interactive mode.  In this case
        // LDAPConnectionInteraction.run does not initialize the keystore and
        // the trust manager is null.
        forceTrustManagerInitialization();
        updateTrustManager(userData, ci);
      }
      logger.debug(LocalizableMessage.raw("Reloading topology"));
      TopologyCache cache = new TopologyCache(adsContext,
          userData.getTrustManager(), getConnectTimeout());
      cache.getFilter().setSearchMonitoringInformation(false);
      cache.reloadTopology();
 
      accepted = handleTopologyCache(cache, userData);
 
      exceptionOccurred = false;
    }
    catch (NamingException ne)
    {
      logger.warn(LocalizableMessage.raw("Error connecting to server: "+ne, ne));
      if (Utils.isCertificateException(ne))
      {
        String details = ne.getMessage() != null ?
            ne.getMessage() : ne.toString();
        exceptionMsg =
          INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE.get(details);
      }
      else
      {
        exceptionMsg = Utils.getThrowableMsg(
            INFO_ERROR_CONNECTING_TO_LOCAL.get(), ne);
      }
    } catch (TopologyCacheException te)
    {
      logger.warn(LocalizableMessage.raw("Error connecting to server: "+te, te));
      exceptionMsg = Utils.getMessage(te);
 
    } catch (ApplicationException ae)
    {
      throw ae;
 
    } catch (Throwable t)
    {
      logger.warn(LocalizableMessage.raw("Error connecting to server: "+t, t));
      exceptionMsg = Utils.getThrowableMsg(INFO_BUG_MSG.get(), t);
    }
    finally
    {
      if (ctx != null)
      {
        try
        {
          ctx.close();
        }
        catch (Throwable t)
        {
          logger.debug(LocalizableMessage.raw("Error closing connection: "+t, t));
        }
      }
    }
    if (exceptionOccurred)
    {
      if (!interactive)
      {
        if (forceOnError)
        {
          println();
          printErrorMessage(ERR_UNINSTALL_ERROR_UPDATING_REMOTE_FORCE.get(
              "--"+parser.getSecureArgsList().adminUidArg.getLongIdentifier(),
              "--"+ToolConstants.OPTION_LONG_BINDPWD,
              "--"+ToolConstants.OPTION_LONG_BINDPWD_FILE,
              exceptionMsg));
        }
        else
        {
          println();
          throw new UserDataException(null,
              ERR_UNINSTALL_ERROR_UPDATING_REMOTE_NO_FORCE.get(
                  "--"+
                  parser.getSecureArgsList().adminUidArg.getLongIdentifier(),
                  "--"+ToolConstants.OPTION_LONG_BINDPWD,
                  "--"+ToolConstants.OPTION_LONG_BINDPWD_FILE,
                  "--"+parser.forceOnErrorArg.getLongIdentifier(),
                  exceptionMsg));
        }
      }
      else
      {
        try
        {
          accepted = askConfirmation(
              ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(),
              false, logger);
        }
        catch (CLIException ce)
        {
          throw new UserDataException(null, ce.getMessageObject(), ce);
        }
      }
    }
    userData.setUpdateRemoteReplication(accepted);
    logger.debug(LocalizableMessage.raw("accepted: "+accepted));
    return accepted;
  }
 
  /**
   * Method that interacts with the user depending on what errors where
   * encountered in the TopologyCache object.  This method assumes that the
   * TopologyCache has been reloaded.
   * Returns <CODE>true</CODE> if the user accepts all the problems encountered
   * and <CODE>false</CODE> otherwise.
   * @param userData the user data.
   * @throws UserDataException if there is an error with the information
   * provided by the user when we are in non-interactive mode.
   * @throws ApplicationException if there is an error processing data in
   * non-interactive mode and an error must be thrown (not in force on error
   * mode).
   */
  private boolean handleTopologyCache(TopologyCache cache,
      UninstallUserData userData) throws UserDataException, ApplicationException
  {
    boolean returnValue;
    boolean stopProcessing = false;
    boolean reloadTopologyCache = false;
    boolean interactive = parser.isInteractive();
 
    logger.debug(LocalizableMessage.raw("Handle topology cache."));
 
    Set<TopologyCacheException> exceptions =
      new HashSet<TopologyCacheException>();
    /* Analyze if we had any exception while loading servers.  For the moment
     * only throw the exception found if the user did not provide the
     * Administrator DN and this caused a problem authenticating in one server
     * or if there is a certificate problem.
     */
    Set<ServerDescriptor> servers = cache.getServers();
    userData.setRemoteServers(servers);
    for (ServerDescriptor server : servers)
    {
      TopologyCacheException e = server.getLastException();
      if (e != null)
      {
        exceptions.add(e);
      }
    }
    Set<LocalizableMessage> exceptionMsgs = new LinkedHashSet<LocalizableMessage>();
    /* Check the exceptions and see if we throw them or not. */
    for (TopologyCacheException e : exceptions)
    {
      logger.debug(LocalizableMessage.raw("Analyzing exception: "+e, e));
      if (stopProcessing)
      {
        break;
      }
      switch (e.getType())
      {
      case NOT_GLOBAL_ADMINISTRATOR:
        println();
        printErrorMessage(INFO_NOT_GLOBAL_ADMINISTRATOR_PROVIDED.get());
        stopProcessing = true;
        break;
      case GENERIC_CREATING_CONNECTION:
        if ((e.getCause() != null) &&
            Utils.isCertificateException(e.getCause()))
        {
          if (interactive)
          {
            println();
            if (ci.promptForCertificateConfirmation(e.getCause(),
                e.getTrustManager(), e.getLdapUrl(), true, logger))
            {
              stopProcessing = true;
              reloadTopologyCache = true;
              updateTrustManager(userData, ci);
            }
            else
            {
              stopProcessing = true;
            }
          }
          else
          {
            exceptionMsgs.add(
                INFO_ERROR_READING_CONFIG_LDAP_CERTIFICATE_SERVER.get(
                e.getHostPort(), e.getCause().getMessage()));
          }
        }
        else
        {
          exceptionMsgs.add(Utils.getMessage(e));
        }
        break;
      default:
        exceptionMsgs.add(Utils.getMessage(e));
      }
    }
    if (interactive)
    {
      if (!stopProcessing && (exceptionMsgs.size() > 0))
      {
        println();
        try
        {
          returnValue = askConfirmation(
            ERR_UNINSTALL_READING_REGISTERED_SERVERS_CONFIRM_UPDATE_REMOTE.get(
                Utils.getMessageFromCollection(exceptionMsgs,
                  Constants.LINE_SEPARATOR)), true, logger);
        }
        catch (CLIException ce)
        {
          throw new UserDataException(null, ce.getMessageObject(), ce);
        }
      }
      else if (reloadTopologyCache)
      {
       returnValue = updateUserUninstallDataWithRemoteServers(userData);
      }
      else
      {
        returnValue = !stopProcessing;
      }
    }
    else
    {
      logger.debug(LocalizableMessage.raw("exceptionMsgs: "+exceptionMsgs));
      if (exceptionMsgs.size() > 0)
      {
        if (parser.isForceOnError())
        {
          LocalizableMessage msg = Utils.getMessageFromCollection(exceptionMsgs,
              Constants.LINE_SEPARATOR);
          println();
          printErrorMessage(msg);
          returnValue = false;
        }
        else
        {
          LocalizableMessage msg =
            ERR_UNINSTALL_ERROR_UPDATING_REMOTE_NO_FORCE.get(
              "--"+
              parser.getSecureArgsList().adminUidArg.getLongIdentifier(),
              "--"+ToolConstants.OPTION_LONG_BINDPWD,
              "--"+ToolConstants.OPTION_LONG_BINDPWD_FILE,
              "--"+parser.forceOnErrorArg.getLongIdentifier(),
              Utils.getMessageFromCollection(exceptionMsgs,
                  Constants.LINE_SEPARATOR));
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, msg,
              null);
        }
      }
      else
      {
        returnValue = true;
      }
    }
    logger.debug(LocalizableMessage.raw("Return value: "+returnValue));
    return returnValue;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isAdvancedMode() {
    return false;
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public boolean isInteractive() {
    if (forceNonInteractive)
    {
      return false;
    }
    else
    {
      return parser.isInteractive();
    }
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isMenuDrivenMode() {
    return true;
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public boolean isQuiet() {
    return false;
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public boolean isScriptFriendly() {
    return false;
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public boolean isVerbose() {
    return true;
  }
 
  /**
   * Commodity method to update the user data with the trust manager in the
   * LDAPConnectionConsoleInteraction object.
   * @param userData the user data to be updated.
   * @param ci the LDAPConnectionConsoleInteraction object to be used to update
   * the user data object.
   */
   private void updateTrustManager(UninstallUserData userData,
       LDAPConnectionConsoleInteraction ci)
   {
     ApplicationTrustManager trust = null;
     TrustManager t = ci.getTrustManager();
     if (t != null)
     {
       if (t instanceof ApplicationTrustManager)
       {
         trust = (ApplicationTrustManager)t;
       }
       else
       {
         trust = new ApplicationTrustManager(ci.getKeyStore());
       }
     }
     userData.setTrustManager(trust);
   }
 
 
 
   /**
    * Forces the initialization of the trust manager in the
    * LDAPConnectionInteraction object.
    */
   private void forceTrustManagerInitialization()
   {
     forceNonInteractive = true;
     try
     {
       ci.initializeTrustManagerIfRequired();
     }
     catch (ArgumentException ae)
     {
       logger.warn(LocalizableMessage.raw("Error initializing trust store: "+ae, ae));
     }
     forceNonInteractive = false;
   }
 
   private void printErrorMessage(LocalizableMessage msg)
   {
     super.println(msg);
     logger.warn(LocalizableMessage.raw(msg));
   }
 
   /**
    * Returns the timeout to be used to connect in milliseconds.  The method
    * must be called after parsing the arguments.
    * @return the timeout to be used to connect in milliseconds.  Returns
    * {@code 0} if there is no timeout.
    * @throw {@code IllegalStateException} if the method is called before
    * parsing the arguments.
    */
   private int getConnectTimeout()
   {
     try
     {
       return parser.getSecureArgsList().connectTimeoutArg.getIntValue();
     }
     catch (ArgumentException ae)
     {
       throw new IllegalStateException("Argument parser is not parsed: "+ae,
           ae);
     }
   }
}