コード例 #1
0
 public static void init() {
   try {
     if (props == null) {
       props = Configuration.getInstance().getProperties();
     }
   } catch (final IllegalStateException e) {
     log.error(
         MrGeoConstants.MRGEO_HDFS_IMAGE
             + " must be specified in the MrGeo configuration file ("
             + e.getMessage()
             + ")");
   }
 }
コード例 #2
0
 public void toClipBoard() {
   try {
     Toolkit.getDefaultToolkit()
         .getSystemClipboard()
         .setContents(new StringSelection(PArray.cat(M)), null);
   } catch (IllegalStateException e) {
     JOptionPane.showConfirmDialog(
         null,
         "Copy to clipboard failed : " + e.getMessage(),
         "Error",
         JOptionPane.DEFAULT_OPTION,
         JOptionPane.ERROR_MESSAGE);
   }
 }
コード例 #3
0
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param user the user identifier
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   */
  public ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String user) throws OperationFailedException {
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    accountProperties.put(
        ProtocolProviderFactory.ACCOUNT_ICON_PATH,
        "resources/images/protocol/gibberish/gibberish32x32.png");

    if (registration.isRememberPassword()) {
      accountProperties.put(ProtocolProviderFactory.PASSWORD, registration.getPassword());
    }

    if (isModification()) {
      providerFactory.uninstallAccount(protocolProvider.getAccountID());
      this.protocolProvider = null;
      setModification(false);
    }

    try {
      AccountID accountID = providerFactory.installAccount(user, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) GibberishAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Exception exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
コード例 #4
0
 private JWebBrowser createWebBrowser() {
   try {
     if (!NativeInterface.isOpen()) throw new Exception("Native Interface is not initialized");
     JWebBrowser browser;
     if (Platform.isLinux()) {
       if (Platform.is64Bit()) {
         try {
           System.setProperty("org.eclipse.swt.browser.UseWebKitGTK", "true");
           // System.setProperty("nativeswing.webbrowser.runtime", "webkit");
           browser = new JWebBrowser(JWebBrowser.useWebkitRuntime());
           log.info("Using WebKit runtime to create WebBrowser");
         } catch (IllegalStateException e) {
           System.clearProperty("org.eclipse.swt.browser.UseWebKitGTK");
           browser = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
           log.info("Using XULRunner runtime to create WebBrowser: " + e.getMessage());
         }
       } else {
         try {
           System.setProperty("org.eclipse.swt.browser.UseWebKitGTK", "true");
           browser = new JWebBrowser(JWebBrowser.useWebkitRuntime());
           log.info("Using WebKit runtime to create WebBrowser");
         } catch (IllegalStateException e) {
           System.clearProperty("org.eclipse.swt.browser.UseWebKitGTK");
           browser = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
           log.info("Using XULRunner runtime to create WebBrowser: " + e.getMessage());
         }
       }
     } else {
       browser = new JWebBrowser();
     }
     browser.setBarsVisible(false);
     browser.setJavascriptEnabled(true);
     return browser;
   } catch (Throwable t) {
     log.severe("Cannot create WebBrowser: " + t.getMessage());
     setInitializationCause(t);
     return null;
   }
 }
コード例 #5
0
  /**
   * Creates an account for the given Account ID, Identity File and Known Hosts File
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param user the user identifier
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   */
  public ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String user) throws OperationFailedException {
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    accountProperties.put(
        ProtocolProviderFactory.ACCOUNT_ICON_PATH, "resources/images/protocol/ssh/ssh32x32.png");

    accountProperties.put(
        ProtocolProviderFactory.NO_PASSWORD_REQUIRED, new Boolean(true).toString());

    accountProperties.put(
        ProtocolProviderFactorySSHImpl.IDENTITY_FILE, registration.getIdentityFile());

    accountProperties.put(
        ProtocolProviderFactorySSHImpl.KNOWN_HOSTS_FILE,
        String.valueOf(registration.getKnownHostsFile()));

    try {
      AccountID accountID = providerFactory.installAccount(user, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) SSHAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Exception exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
コード例 #6
0
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param userName the user identifier
   * @param passwd the password
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   * @throws OperationFailedException if the operation didn't succeed
   */
  protected ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String userName, String passwd)
      throws OperationFailedException {
    if (logger.isTraceEnabled()) {
      logger.trace("Preparing to install account for user " + userName);
    }
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    String protocolIconPath = getProtocolIconPath();

    String accountIconPath = getAccountIconPath();

    registration.storeProperties(
        userName, passwd, protocolIconPath, accountIconPath, accountProperties);

    accountProperties.put(
        ProtocolProviderFactory.IS_PREFERRED_PROTOCOL, Boolean.toString(isPreferredProtocol()));
    accountProperties.put(ProtocolProviderFactory.PROTOCOL, getProtocol());

    if (isModification()) {
      providerFactory.modifyAccount(protocolProvider, accountProperties);

      setModification(false);

      return protocolProvider;
    }

    try {
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Will install account for user "
                + userName
                + " with the following properties."
                + accountProperties);
      }

      AccountID accountID = providerFactory.installAccount(userName, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) JabberAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalArgumentException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Username, password or server is null.", OperationFailedException.ILLEGAL_ARGUMENT);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Throwable exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account.", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }
コード例 #7
0
ファイル: Main.java プロジェクト: TomGebhardt/k
  // execute krun in debug mode (i.e. step by step execution)
  // isSwitch variable is true if we enter in debug execution from normal
  // execution (we use the search command with --graph option)
  @SuppressWarnings("unchecked")
  public static void debugExecution(
      Term kast,
      String lang,
      KRunResult<SearchResults> state,
      org.kframework.kil.loader.Context context) {
    try {
      // adding autocompletion and history feature to the stepper internal
      // commandline by using the JLine library
      ConsoleReader reader = new ConsoleReader();
      reader.setBellEnabled(false);

      List<Completor> argCompletor = new LinkedList<Completor>();
      argCompletor.add(
          new SimpleCompletor(
              new String[] {
                "help",
                "abort",
                "resume",
                "step",
                "step-all",
                "select",
                "show-search-graph",
                "show-node",
                "show-edge",
                "save",
                "load",
                "read"
              }));
      argCompletor.add(new FileNameCompletor());
      List<Completor> completors = new LinkedList<Completor>();
      completors.add(new ArgumentCompletor(argCompletor));
      reader.addCompletor(new MultiCompletor(completors));

      new File(K.compiled_def + K.fileSeparator + "main.maude").getCanonicalPath();
      RunProcess rp = new RunProcess();
      KRun krun = obtainKRun(context);
      krun.setBackendOption("io", false);
      KRunDebugger debugger;
      try {
        if (state == null) {
          Term t = makeConfiguration(kast, "", rp, (K.term != null), context);
          debugger = krun.debug(t);
          System.out.println("After running one step of execution the result is:");
          AnsiConsole.out.println(debugger.printState(debugger.getCurrentState()));
        } else {
          debugger = krun.debug(state.getResult().getGraph());
        }
      } catch (UnsupportedBackendOptionException e) {
        Error.report("Backend \"" + K.backend + "\" does not support option " + e.getMessage());
        throw e; // unreachable
      }
      while (true) {
        System.out.println();
        String input = reader.readLine("Command > ");
        if (input == null) {
          // probably pressed ^D
          System.out.println();
          System.exit(0);
        }

        // construct the right command line input when we specify the
        // "step" option with an argument (i.e. step=3)
        input = input.trim();
        String[] tokens = input.split(" ");
        // store the tokens that are not a blank space
        List<String> items = new ArrayList<String>();
        for (int i = 0; i < tokens.length; i++) {
          if ((!(tokens[i].equals(" ")) && (!tokens[i].equals("")))) {
            items.add(tokens[i]);
          }
        }
        StringBuilder aux = new StringBuilder();
        // excepting the case of a command like: help
        if (items.size() > 1) {
          for (int i = 0; i < items.size(); i++) {
            if (i > 0) {
              aux.append("=");
              aux.append(items.get(i));
            } else if (i == 0) {
              aux.append(items.get(i));
            }
          }
          input = aux.toString();
        }
        // apply trim to remove possible blank spaces from the inserted
        // command
        String[] cmds = new String[] {"--" + input};
        CommandlineOptions cmd_options = new CommandlineOptions();
        CommandLine cmd = cmd_options.parse(cmds);
        // when an error occurred during parsing the commandline
        // continue the execution of the stepper
        if (cmd == null) {
          continue;
        } else {
          if (cmd.hasOption("help")) {
            printDebugUsage(cmd_options);
          }
          if (cmd.hasOption("abort")) {
            System.exit(0);
          }
          if (cmd.hasOption("resume")) {
            try {
              debugger.resume();
              AnsiConsole.out.println(debugger.printState(debugger.getCurrentState()));
            } catch (IllegalStateException e) {
              Error.silentReport(
                  "Wrong command: If you previously used the step-all command you must"
                      + K.lineSeparator
                      + "seletc first a solution with step command before executing steps of rewrites!");
            }
          }
          // one step execution (by default) or more if you specify an
          // argument
          if (cmd.hasOption("step")) {
            // by default execute only one step at a time
            String arg = new String("1");
            String[] remainingArguments = null;
            remainingArguments = cmd.getArgs();
            if (remainingArguments.length > 0) {
              arg = remainingArguments[0];
            }
            try {
              int steps = Integer.parseInt(arg);
              debugger.step(steps);
              AnsiConsole.out.println(debugger.printState(debugger.getCurrentState()));
            } catch (NumberFormatException e) {
              Error.silentReport("Argument to step must be an integer.");
            } catch (IllegalStateException e) {
              Error.silentReport(
                  "Wrong command: If you previously used the step-all command you must"
                      + K.lineSeparator
                      + "select first a solution with step command before executing steps of rewrites!");
            }
          }
          if (cmd.hasOption("step-all")) {
            // by default compute all successors in one transition
            String arg = new String("1");
            String[] remainingArguments = null;
            remainingArguments = cmd.getArgs();
            if (remainingArguments.length > 0) {
              arg = remainingArguments[0];
            }
            try {
              int steps = Integer.parseInt(arg);
              SearchResults states = debugger.stepAll(steps);
              AnsiConsole.out.println(states);

            } catch (NumberFormatException e) {
              Error.silentReport("Argument to step-all must be an integer.");
            } catch (IllegalStateException e) {
              Error.silentReport(
                  "Wrong command: If you previously used the step-all command you must"
                      + K.lineSeparator
                      + "select first a solution with step command before executing steps of rewrites!");
            }
          }
          // "select n7" or "select 3" are both valid commands
          if (cmd.hasOption("select")) {
            String arg = new String();
            arg = cmd.getOptionValue("select").trim();
            try {
              int stateNum = Integer.parseInt(arg);
              debugger.setCurrentState(stateNum);
              AnsiConsole.out.println(debugger.printState(debugger.getCurrentState()));
            } catch (NumberFormatException e) {
              Error.silentReport("Argument to select must bean integer.");
            } catch (IllegalArgumentException e) {
              System.out.println(
                  "A node with the specified state number could not be found in the"
                      + K.lineSeparator
                      + "search graph");
            }
          }
          if (cmd.hasOption("show-search-graph")) {
            System.out.println(K.lineSeparator + "The search graph is:" + K.lineSeparator);
            System.out.println(debugger.getGraph());
          }
          if (cmd.hasOption("show-node")) {
            String nodeId = cmd.getOptionValue("show-node").trim();
            try {
              int stateNum = Integer.parseInt(nodeId);
              AnsiConsole.out.println(debugger.printState(stateNum));
            } catch (NumberFormatException e) {
              Error.silentReport("Argument to select node to show must be an integer.");
            } catch (IllegalArgumentException e) {
              System.out.println(
                  "A node with the specified state number could not be found in the"
                      + K.lineSeparator
                      + "search graph");
            }
          }
          if (cmd.hasOption("show-edge")) {
            String[] vals = cmd.getOptionValues("show-edge");
            vals = vals[0].split("=", 2);
            try {
              int state1 = Integer.parseInt(vals[0].trim());
              int state2 = Integer.parseInt(vals[1].trim());
              AnsiConsole.out.println(debugger.printEdge(state1, state2));
            } catch (ArrayIndexOutOfBoundsException e) {
              Error.silentReport("Must specify two nodes with an edge between them.");
            } catch (NumberFormatException e) {
              Error.silentReport("Arguments to select edge to show must be integers.");
            } catch (IllegalArgumentException e) {
              System.out.println(
                  "An edge with the specified endpoints could not be found in the"
                      + K.lineSeparator
                      + "search graph");
            }
          }

          DirectedGraph<KRunState, Transition> savedGraph = null;
          if (cmd.hasOption("save")) {
            BinaryLoader.save(
                new File(cmd.getOptionValue("save")).getCanonicalPath(), debugger.getGraph());
            System.out.println("File successfully saved.");
          }
          if (cmd.hasOption("load")) {
            savedGraph =
                (DirectedGraph<KRunState, Transition>)
                    BinaryLoader.load(cmd.getOptionValue("load"));
            krun = new MaudeKRun(context);
            debugger = krun.debug(savedGraph);
            debugger.setCurrentState(1);
            System.out.println("File successfully loaded.");
          }
          if (cmd.hasOption("read")) {
            try {
              debugger.readFromStdin(
                  StringBuiltin.valueOf("\"" + cmd.getOptionValue("read") + "\"").stringValue());
              AnsiConsole.out.println(debugger.printState(debugger.getCurrentState()));
            } catch (IllegalStateException e) {
              Error.silentReport(e.getMessage());
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }