Example #1
0
  public void teardown() {
    try {
      // TODO shutdown addon manager and related components?

      // shutdown control modules
      binding.stop();

      // shutdwon event manager
      em.terminate();

      // shutdown SAL
      Terminate terminate = new Terminate();
      sal.terminate(terminate);

      // shutdown IFD
      ReleaseContext releaseContext = new ReleaseContext();
      releaseContext.setContextHandle(contextHandle);
      ifd.releaseContext(releaseContext);
    } catch (Exception ex) {
      _logger.error("Failed to stop Richclient.", ex);
    }

    System.exit(0);
  }
Example #2
0
  public void setup() {
    GUIDefaults.initialize();

    MessageDialog dialog = new MessageDialog();
    dialog.setHeadline(lang.translationForKey("client.startup.failed.headline"));

    try {
      tray = new AppTray(this);
      tray.beginSetup();

      // Set up client environment
      env = new ClientEnv();

      // Set up Management
      TinyManagement management = new TinyManagement(env);
      env.setManagement(management);

      // Set up the IFD
      ifd = new IFD();
      ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
      env.setIFD(ifd);

      // Set up the Dispatcher
      MessageDispatcher dispatcher = new MessageDispatcher(env);
      env.setDispatcher(dispatcher);
      ifd.setDispatcher(dispatcher);

      // Perform an EstablishContext to get a ContextHandle
      EstablishContext establishContext = new EstablishContext();
      EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
      WSHelper.checkResult(establishContextResponse);
      contextHandle = ifd.establishContext(establishContext).getContextHandle();

      // Set up CardRecognition
      recognition = new CardRecognition(ifd, contextHandle);

      // Set up EventManager
      em = new EventManager(recognition, env, contextHandle);
      env.setEventManager(em);

      // Set up SALStateCallback
      cardStates = new CardStateMap();
      SALStateCallback salCallback = new SALStateCallback(recognition, cardStates);
      em.registerAllEvents(salCallback);

      // Set up SAL
      sal = new TinySAL(env, cardStates);
      env.setSAL(sal);

      // Set up GUI
      SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
      sal.setGUI(gui);
      ifd.setGUI(gui);
      recognition.setGUI(gui);

      // Start up control interface
      try {
        binding = new HTTPBinding(HTTPBinding.DEFAULT_PORT);
        manager = new AddonManager(dispatcher, gui, cardStates, recognition, em);
        sal.setAddonManager(manager);
        binding.setAddonManager(manager);
        binding.start();
      } catch (BindException e) {
        dialog.setMessage(lang.translationForKey("client.startup.failed.portinuse"));
        throw e;
      }

      tray.endSetup(recognition, manager);

      // Initialize the EventManager
      em.registerAllEvents(tray.status());
      em.initialize();

    } catch (Exception e) {
      _logger.error(e.getMessage(), e);

      if (dialog.getMessage() == null || dialog.getMessage().isEmpty()) {
        // Add exception message if no custom message is set
        dialog.setMessage(e.getMessage());
      }

      // Show dialog to the user and shut down the client
      JOptionPane.showMessageDialog(null, dialog, "Open eCard App", JOptionPane.PLAIN_MESSAGE);
      teardown();
    }
  }