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

jvergara
19.09.2010 838e873376cc4a1cc3588746f6bf8dec4c9355a9
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
/*
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * 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
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  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 2008-2010 Sun Microsystems, Inc.
 */
 
package org.opends.quicksetup.installandupgrader;
 
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.messages.Message;
import static org.opends.messages.QuickSetupMessages.*;
 
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
 
import org.opends.quicksetup.ButtonName;
import org.opends.quicksetup.Constants;
import org.opends.quicksetup.CurrentInstallStatus;
import org.opends.quicksetup.ProgressStep;
import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.Step;
import org.opends.quicksetup.UserData;
import org.opends.quicksetup.UserDataException;
import org.opends.quicksetup.WizardStep;
import org.opends.quicksetup.event.ProgressUpdateListener;
import org.opends.quicksetup.installandupgrader.ui.WelcomePanel;
import org.opends.quicksetup.installer.offline.OfflineInstaller;
import org.opends.quicksetup.installer.webstart.WebStartInstaller;
import org.opends.quicksetup.ui.FieldName;
import org.opends.quicksetup.ui.GuiApplication;
import org.opends.quicksetup.ui.QuickSetup;
import org.opends.quicksetup.ui.QuickSetupDialog;
import org.opends.quicksetup.ui.QuickSetupStepPanel;
import org.opends.quicksetup.upgrader.UpgradeWizardStep;
import org.opends.quicksetup.upgrader.Upgrader;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.DynamicConstants;
 
/**
 * Application that allows to upgrade or install OpenDS.
 */
public class InstallAndUpgrader extends GuiApplication
{
  private GuiApplication installer;
  private GuiApplication upgrader;
  private InstallAndUpgradeUserData userData;
 
  /**
   * Creates a default instance.
   */
  public InstallAndUpgrader() {
 
    // Initialize the logs if necessary
    try {
      if (!QuickSetupLog.isInitialized())
        QuickSetupLog.initLogFileHandler(
                File.createTempFile(
                        Constants.LOG_FILE_PREFIX,
                        QuickSetupLog.LOG_FILE_SUFFIX));
    } catch (IOException e) {
      System.err.println(INFO_ERROR_INITIALIZING_LOG.get());
      e.printStackTrace();
    }
    if (Utils.isWebStart())
    {
      installer = new WebStartInstaller();
    }
    else
    {
      installer = new OfflineInstaller();
    }
    upgrader = new Upgrader();
  }
 
 
 
  /**
   * {@inheritDoc}
   */
  public void setProgressMessageFormatter(ProgressMessageFormatter formatter) {
    super.setProgressMessageFormatter(formatter);
    installer.setProgressMessageFormatter(formatter);
    upgrader.setProgressMessageFormatter(formatter);
  }
 
  /**
   * {@inheritDoc}
   */
  public void setCurrentInstallStatus(CurrentInstallStatus installStatus) {
    super.setCurrentInstallStatus(installStatus);
    installer.setCurrentInstallStatus(installStatus);
    upgrader.setCurrentInstallStatus(installStatus);
  }
 
  /**
   * {@inheritDoc}
   */
  public UserData getUserData()
  {
    return getDelegateApplication().getUserData();
  }
 
  /**
   * {@inheritDoc}
   */
  public Message getFrameTitle() {
    return Utils.getCustomizedObject("INFO_FRAME_INSTALL_TITLE",
        INFO_FRAME_INSTALL_TITLE.get(DynamicConstants.PRODUCT_NAME),
        Message.class);
  }
 
  /**
   * {@inheritDoc}
   */
  public WizardStep getFirstWizardStep() {
    return Step.WELCOME;
  }
 
  /**
   * {@inheritDoc}
   */
  public WizardStep getFinishedStep() {
    return getDelegateApplication().getFinishedStep();
  }
 
  /**
   * {@inheritDoc}
   */
  public void run()
  {
    getDelegateApplication().run();
  }
 
  /**
   * {@inheritDoc}
   */
  public void addProgressUpdateListener(ProgressUpdateListener l)
  {
    installer.addProgressUpdateListener(l);
    upgrader.addProgressUpdateListener(l);
  }
 
  /**
   * {@inheritDoc}
   */
  public void removeProgressUpdateListener(ProgressUpdateListener l)
  {
    installer.removeProgressUpdateListener(l);
    upgrader.removeProgressUpdateListener(l);
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isCancellable()
  {
    return getDelegateApplication().isCancellable();
  }
 
  /**
   * {@inheritDoc}
   */
  public void setWizardDialogState(QuickSetupDialog dlg,
                                      UserData userData,
                                      WizardStep step) {
    if ((getDelegateApplication() == upgrader) &&
        (step == Step.WELCOME))
    {
      step = UpgradeWizardStep.WELCOME;
    }
    getDelegateApplication().setWizardDialogState(dlg, userData, step);
  }
 
  /**
   * {@inheritDoc}
   */
  public WizardStep getNextWizardStep(WizardStep step) {
    if ((getDelegateApplication() == upgrader) &&
        (step == Step.WELCOME))
    {
      step = UpgradeWizardStep.WELCOME;
    }
    return getDelegateApplication().getNextWizardStep(step);
  }
 
  /**
   * {@inheritDoc}
   */
  public QuickSetupStepPanel createWizardStepPanel(WizardStep step) {
    QuickSetupStepPanel p = null;
    if (step == Step.WELCOME) {
      p = new WelcomePanel(this);
    }
    if (p == null)
    {
      p = upgrader.createWizardStepPanel(step);
    }
    if (p == null)
    {
      p = installer.createWizardStepPanel(step);
    }
    return p;
  }
 
  /**
   * {@inheritDoc}
   */
  public WizardStep getPreviousWizardStep(WizardStep step) {
    WizardStep s = getDelegateApplication().getPreviousWizardStep(step);
    if (s == UpgradeWizardStep.WELCOME)
    {
      s = Step.WELCOME;
    }
    return s;
  }
 
  /**
   * {@inheritDoc}
   */
  public LinkedHashSet<WizardStep> getOrderedSteps()
  {
    LinkedHashSet<WizardStep> set = new LinkedHashSet<WizardStep>();
    set.addAll(installer.getOrderedSteps());
    set.addAll(upgrader.getOrderedSteps());
    set.remove(UpgradeWizardStep.WELCOME);
    return set;
  }
 
  /**
   * {@inheritDoc}
   */
  public ProgressStep getCurrentProgressStep() {
    return getDelegateApplication().getCurrentProgressStep();
  }
 
  /**
   * {@inheritDoc}
   */
  public Integer getRatio(ProgressStep step) {
    return getDelegateApplication().getRatio(step);
  }
 
  /**
   * {@inheritDoc}
   */
  public Message getSummary(ProgressStep step) {
    return getDelegateApplication().getSummary(step);
  }
 
  /**
   * {@inheritDoc}
   */
  public void windowClosing(QuickSetupDialog dlg, WindowEvent evt) {
    getDelegateApplication().windowClosing(dlg, evt);
  }
 
  /**
   * {@inheritDoc}
   */
  public ButtonName getInitialFocusButtonName() {
    return getDelegateApplication().getInitialFocusButtonName();
  }
 
  /**
   * {@inheritDoc}
   */
  public Set<? extends WizardStep> getWizardSteps() {
    Set<WizardStep> set = new HashSet<WizardStep>();
    set.addAll(installer.getWizardSteps());
    set.addAll(upgrader.getWizardSteps());
    set.remove(UpgradeWizardStep.WELCOME);
    return set;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isVisible(WizardStep step, UserData userData)
  {
    boolean isVisible;
    if (step == Step.WELCOME)
    {
      isVisible = true;
    }
    else
    {
      isVisible = getDelegateApplication().isVisible(step,
          getDelegateApplication().getUserData()) &&
      getDelegateApplication().getWizardSteps().contains(step);
    }
    return isVisible;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isVisible(WizardStep step, QuickSetup qs)
  {
    boolean isVisible;
    if (step == Step.WELCOME)
    {
      isVisible = true;
    }
    else
    {
      GuiApplication appl;
      Boolean isUpgrade = (Boolean)qs.getFieldValue(FieldName.IS_UPGRADE);
      if (Boolean.TRUE.equals(isUpgrade))
      {
        appl = upgrader;
      }
      else
      {
        appl = installer;
      }
      isVisible = appl.isVisible(step, qs) &&
      appl.getWizardSteps().contains(step);
    }
    return isVisible;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isSubStep(WizardStep step)
  {
    boolean isSubStep;
    if (step == Step.WELCOME)
    {
      isSubStep = false;
    }
    else
    {
      isSubStep = getDelegateApplication().isSubStep(step);
    }
    return isSubStep;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean canGoBack(WizardStep step) {
    boolean canGoBack;
    if (step == Step.WELCOME)
    {
      canGoBack = false;
    }
    else
    {
      canGoBack = getDelegateApplication().canGoBack(step);
    }
    return canGoBack;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean canGoForward(WizardStep step) {
    boolean canGoForward;
    if (step == Step.WELCOME)
    {
      canGoForward = true;
    }
    else
    {
      canGoForward = getDelegateApplication().canGoForward(step);
    }
    return canGoForward;
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean canFinish(WizardStep step) {
    return getDelegateApplication().canFinish(step);
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean canQuit(WizardStep step) {
    return getDelegateApplication().canQuit(step);
  }
 
  /**
   * {@inheritDoc}
   */
  public void previousClicked(WizardStep cStep, QuickSetup qs)
  {
    getDelegateApplication().previousClicked(cStep, qs);
  }
 
  /**
   * {@inheritDoc}
   */
  public void nextClicked(WizardStep cStep, QuickSetup qs)
  {
    getDelegateApplication().nextClicked(cStep, qs);
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean finishClicked(WizardStep cStep, QuickSetup qs)
  {
    return getDelegateApplication().finishClicked(cStep, qs);
  }
 
  /**
   * {@inheritDoc}
   */
  public void closeClicked(WizardStep cStep, QuickSetup qs)
  {
    getDelegateApplication().closeClicked(cStep, qs);
  }
 
  /**
   * {@inheritDoc}
   */
  public void quitClicked(WizardStep cStep, QuickSetup qs)
  {
    getDelegateApplication().quitClicked(cStep, qs);
  }
 
  /**
   * {@inheritDoc}
   */
  public void updateUserData(WizardStep cStep, QuickSetup qs)
  throws UserDataException
  {
    if (cStep == Step.WELCOME)
    {
      Boolean isUpgrade = (Boolean)qs.getFieldValue(FieldName.IS_UPGRADE);
      getInstallAndUpgradeUserData().setUpgrade(isUpgrade);
      if (isUpgrade)
      {
        upgrader.updateUserData(UpgradeWizardStep.WELCOME, qs);
        getUserData().setServerLocation(
            upgrader.getUserData().getServerLocation());
      }
      else
      {
        installer.updateUserData(cStep, qs);
      }
    }
    else
    {
      getDelegateApplication().updateUserData(cStep, qs);
    }
  }
 
  /**
   * {@inheritDoc}
   */
  public void cancel()
  {
    getDelegateApplication().cancel();
  }
 
  /**
   * {@inheritDoc}
   */
  public boolean isFinished()
  {
    return getDelegateApplication().isFinished();
  }
 
  /**
   * {@inheritDoc}
   */
  public String getInstallationPath()
  {
    return getDelegateApplication().getInstallationPath();
  }
 
 
  /**
   * {@inheritDoc}
   */
  public String getInstancePath()
  {
    return getDelegateApplication().getInstancePath();
  }
 
  /**
   * {@inheritDoc}
   */
  public void setQuickSetupDialog(QuickSetupDialog dialog) {
    installer.setQuickSetupDialog(dialog);
    upgrader.setQuickSetupDialog(dialog);
  }
 
  private GuiApplication getDelegateApplication()
  {
    GuiApplication application;
    if (getInstallAndUpgradeUserData().isUpgrade())
    {
      application = upgrader;
    }
    else
    {
      application = installer;
    }
    return application;
  }
 
  /**
   * Returns the install and upgrader specific user data.
   * @return the install and upgrader specific user data.
   */
  public InstallAndUpgradeUserData getInstallAndUpgradeUserData()
  {
    if (userData == null) {
      userData = new InstallAndUpgradeUserData();
    }
    return userData;
  }
 
  /**
   * Returns the trust manager that can be used to establish secure connections.
   * @return the trust manager that can be used to establish secure connections.
   */
  public ApplicationTrustManager getTrustManager()
  {
    return getDelegateApplication().getTrustManager();
  }
}