/** @author Klaus Meffert */
 public void testGetName_1() {
   Configuration conf = new Configuration("tEstName");
   conf.setName("HallI");
   assertEquals("HallI", conf.getName());
   conf.setName("HallA");
   assertEquals("HallA", conf.getName());
 }
예제 #2
0
 public static ArrayList<Configuration> findConfiguration(
     ThingMLModel model, String name, boolean fuzzy) {
   ArrayList<Configuration> result = new ArrayList<Configuration>();
   for (Configuration c : allConfigurations(model)) {
     if (c.getName().startsWith(name)) {
       if (fuzzy) result.add(c);
       else if (c.getName().equals(name)) result.add(c);
     }
   }
   return result;
 }
예제 #3
0
        public void run() {
          String command = inputTextArea.getText().trim();
          if (command == null || command.length() == 0) {
            JOptionPane.showMessageDialog(
                mainWindow, "Command window is empty", "Out of order", JOptionPane.WARNING_MESSAGE);
            return;
          }

          // make busy dialog same width as main window.
          Dimension dlgBounds = busyDialog.getSize();
          dlgBounds.width = mainWindow.getSize().width;
          busyDialog.setSize(dlgBounds);

          runButton.setEnabled(false);
          Configuration config = (Configuration) connectionsList.getSelectedItem();
          if (passwdPromptCheckBox.isSelected() || !config.hasPassword()) {
            String pass = getPassword("Connection password for " + config.getName());
            config.setPassword(pass);
          }
          resultsStatusBar.reset();
          busyDialog.setVisible(true);

          try {
            currentConnection = configManager.getConnection(config);

            SQLRunner.setVerbosity(Verbosity.QUIET);
            SQLRunner prog = new SQLRunner(currentConnection, null, "t");
            prog.setGUI(SQLRunnerGUI.this);
            if (mode != null) {
              prog.setOutputMode(mode);
            }
            prog.setOutputFile(out);

            // RUN THE SQL
            prog.runStatement(command);

            if (prog.isEscape()) {
              outputPanel.setSelectedIndex(0);
            }
            resultsStatusBar.showSuccess(); // If no exception thrown!
          } catch (Exception e) {
            resultsStatusBar.showFailure();
            eHandler.handleError(e);
          } finally {
            runButton.setEnabled(true);
            busyDialog.setVisible(false);
            try {
              // Nested try here is deliberate, not a big deal if this call crashes
              if (currentConnection != null) {
                currentConnection.close();
              }
            } catch (SQLException ex) {
              System.err.println("Warning: close caused " + ex);
            }
          }
        }
  private void addTemplate(SearchDialogFactory searchDialogFactory) {
    SearchDialog dialog = createDialog(searchDialogFactory);
    dialog.show();
    if (!dialog.isOK()) return;
    Configuration configuration = dialog.getConfiguration();

    if (configuration.getName() == null
        || configuration.getName().equals(SearchDialog.USER_DEFINED)) {
      String name = dialog.showSaveTemplateAsDialog();

      if (name != null) {
        name =
            ConfigurationManager.findAppropriateName(myConfigurations, name, dialog.getProject());
      }
      if (name == null) return;
      configuration.setName(name);
    }
    myConfigurations.add(configuration);

    configurationsChanged(dialog.getSearchContext());
  }
예제 #5
0
 /**
  * Set the selected Configuration Object in the Connections chooser from a given Configuration
  * Name passed as a String.
  *
  * @param config The chosen name.
  */
 private void setConfig(String config) {
   if (config == null) {
     throw new NullPointerException("Configuration name may not be null");
   }
   for (Configuration configListItem : configurations) {
     if (config.equals(configListItem.getName())) {
       connectionsList.setSelectedItem(configListItem);
       return;
     }
   }
   System.err.printf("Warning: Configuration %s not found", config);
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  * @since 2.6
  */
 public void testToString_1() throws Exception {
   Configuration conf = new ConfigurationForTesting();
   conf.getGeneticOperators().clear();
   conf.getNaturalSelectors(false).clear();
   conf.getNaturalSelectors(true).clear();
   privateAccessor.setField(conf, "m_eventManager", null);
   String s = trimString(conf.toString());
   String eventmgr = conf.S_NONE;
   String genops = conf.S_NONE;
   // natural selectors (pre)
   String natselsPre = conf.S_NONE;
   // natural selectors (post)
   String natselsPost = conf.S_NONE;
   assertEquals(
       trimString(
           conf.S_CONFIGURATION
               + ":"
               + conf.S_CONFIGURATION_NAME
               + ":"
               + conf.getName()
               + " "
               + conf.S_POPULATION_SIZE
               + ":"
               + conf.getPopulationSize()
               + " "
               + conf.S_MINPOPSIZE
               + ":"
               + conf.getMinimumPopSizePercent()
               + " "
               + conf.S_CHROMOSOME_SIZE
               + ":"
               + conf.getChromosomeSize()
               + " "
               + conf.S_SAMPLE_CHROM
               + ":"
               + conf.S_SIZE
               + ":"
               + conf.getSampleChromosome().size()
               + " "
               + conf.S_TOSTRING
               + ":"
               + conf.getSampleChromosome().toString()
               + " "
               + conf.S_RANDOM_GENERATOR
               + ":"
               + conf.getRandomGenerator().getClass().getName()
               + " "
               + conf.S_EVENT_MANAGER
               + ":"
               + eventmgr
               + " "
               + conf.S_CONFIGURATION_HANDLER
               + ":"
               + conf.getConfigurationHandler().getName()
               + " "
               + conf.S_FITNESS_FUNCTION
               + ":"
               + conf.getFitnessFunction().getClass().getName()
               + " "
               + conf.S_FITNESS_EVALUATOR
               + ":"
               + conf.getFitnessEvaluator().getClass().getName()
               + " "
               + conf.S_GENETIC_OPERATORS
               + ":"
               + genops
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_PRE
               + ")"
               + ":"
               + natselsPre
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_POST
               + ")"
               + ":"
               + natselsPost
               + " "
           //                            + conf.S_POPCONSTANT_SELECTOR + ":"
           //                            + "null" + " "
           ),
       s);
 }
 /**
  * @throws Exception
  * @author Klaus Meffert
  * @since 2.4
  */
 public void testToString_0() throws Exception {
   Configuration conf = new ConfigurationForTesting();
   conf.addGeneticOperator(new MutationOperator(conf));
   conf.addNaturalSelector(new WeightedRouletteSelector(conf), true);
   conf.addNaturalSelector(new WeightedRouletteSelector(conf), false);
   conf.addNaturalSelector(new BestChromosomesSelector(conf), false);
   String s = trimString(conf.toString());
   String eventmgr =
       conf.getEventManager() != null ? conf.getEventManager().getClass().getName() : conf.S_NONE;
   String genops = "";
   if (conf.getGeneticOperators().size() < 1) {
     genops = conf.S_NONE;
   } else {
     for (int i = 0; i < conf.getGeneticOperators().size(); i++) {
       if (i > 0) {
         genops += "; ";
       }
       genops += conf.getGeneticOperators().get(i).getClass().getName();
       ;
     }
   }
   // natural selectors (pre)
   String natselsPre = "";
   int natsize = conf.getNaturalSelectors(true).size();
   if (natsize < 1) {
     natselsPre = conf.S_NONE;
   } else {
     for (int i = 0; i < natsize; i++) {
       if (i > 0) {
         natselsPre += "; ";
       }
       natselsPre += " " + conf.getNaturalSelectors(true).get(i).getClass().getName();
     }
   }
   // natural selectors (post)
   String natselsPost = "";
   natsize = conf.getNaturalSelectors(false).size();
   if (natsize < 1) {
     natselsPost = conf.S_NONE;
   } else {
     for (int i = 0; i < natsize; i++) {
       if (i > 0) {
         natselsPost += "; ";
       }
       natselsPost += " " + conf.getNaturalSelectors(false).get(i).getClass().getName();
     }
   }
   assertEquals(
       trimString(
           conf.S_CONFIGURATION
               + ":"
               + conf.S_CONFIGURATION_NAME
               + ":"
               + conf.getName()
               + " "
               + conf.S_POPULATION_SIZE
               + ":"
               + conf.getPopulationSize()
               + " "
               + conf.S_MINPOPSIZE
               + ":"
               + conf.getMinimumPopSizePercent()
               + " "
               + conf.S_CHROMOSOME_SIZE
               + ":"
               + conf.getChromosomeSize()
               + " "
               + conf.S_SAMPLE_CHROM
               + ":"
               + conf.S_SIZE
               + ":"
               + conf.getSampleChromosome().size()
               + " "
               + conf.S_TOSTRING
               + ":"
               + conf.getSampleChromosome().toString()
               + " "
               + conf.S_RANDOM_GENERATOR
               + ":"
               + conf.getRandomGenerator().getClass().getName()
               + " "
               + conf.S_EVENT_MANAGER
               + ":"
               + eventmgr
               + " "
               + conf.S_CONFIGURATION_HANDLER
               + ":"
               + conf.getConfigurationHandler().getName()
               + " "
               + conf.S_FITNESS_FUNCTION
               + ":"
               + conf.getFitnessFunction().getClass().getName()
               + " "
               + conf.S_FITNESS_EVALUATOR
               + ":"
               + conf.getFitnessEvaluator().getClass().getName()
               + " "
               + conf.S_GENETIC_OPERATORS
               + ":"
               + genops
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_PRE
               + ")"
               + ":"
               + natselsPre
               + " "
               + conf.S_NATURAL_SELECTORS
               + "("
               + conf.S_POST
               + ")"
               + ":"
               + natselsPost
               + " "
           //                            + conf.S_POPCONSTANT_SELECTOR + ":"
           //                            + "null" + " "
           ),
       s);
 }
 /** @author Klaus Meffert */
 public void testGetName_2() {
   Configuration conf = new Configuration();
   assertEquals(null, conf.getName());
 }
 /** @author Klaus Meffert */
 public void testGetName_0() {
   Configuration conf = new Configuration("tEstName");
   assertEquals("tEstName", conf.getName());
 }
예제 #10
0
  /**
   * Implements the Configurable interface using bean introspection.
   *
   * <p>Subclasses are allowed to add behaviour. After the bean based setup has completed first the
   * method {@link #finishLocalSetup finishLocalSetup} is called to allow completion of the bean's
   * local setup, after that the method {@link #setupChild setupChild} is called for each {@link
   * Configuration#getChildren child Configuration} of <code>aConfiguration</code>.
   *
   * @param aConfiguration {@inheritDoc}
   * @throws CheckstyleException {@inheritDoc}
   * @see Configurable
   */
  public final void configure(Configuration aConfiguration) throws CheckstyleException {
    mConfiguration = aConfiguration;

    final BeanUtilsBean beanUtils = createBeanUtilsBean();

    // TODO: debug log messages
    final String[] attributes = aConfiguration.getAttributeNames();

    for (final String key : attributes) {
      final String value = aConfiguration.getAttribute(key);

      try {
        // BeanUtilsBean.copyProperties silently ignores missing setters
        // for key, so we have to go through great lengths here to
        // figure out if the bean property really exists.
        final PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(this, key);
        if ((pd == null) || (pd.getWriteMethod() == null)) {
          throw new CheckstyleException(
              "Property '"
                  + key
                  + "' in module "
                  + aConfiguration.getName()
                  + " does not exist, please check the documentation");
        }

        // finally we can set the bean property
        beanUtils.copyProperty(this, key, value);
      } catch (final InvocationTargetException e) {
        throw new CheckstyleException(
            "Cannot set property '"
                + key
                + "' in module "
                + aConfiguration.getName()
                + " to '"
                + value
                + "': "
                + e.getTargetException().getMessage(),
            e);
      } catch (final IllegalAccessException e) {
        throw new CheckstyleException(
            "cannot access " + key + " in " + this.getClass().getName(), e);
      } catch (final NoSuchMethodException e) {
        throw new CheckstyleException(
            "cannot access " + key + " in " + this.getClass().getName(), e);
      } catch (final IllegalArgumentException e) {
        throw new CheckstyleException(
            "illegal value '"
                + value
                + "' for property '"
                + key
                + "' of module "
                + aConfiguration.getName(),
            e);
      } catch (final ConversionException e) {
        throw new CheckstyleException(
            "illegal value '"
                + value
                + "' for property '"
                + key
                + "' of module "
                + aConfiguration.getName(),
            e);
      }
    }

    finishLocalSetup();

    final Configuration[] childConfigs = aConfiguration.getChildren();
    for (final Configuration childConfig : childConfigs) {
      setupChild(childConfig);
    }
  }
 private ResolveOptions createResolveOptions(Configuration configuration) {
   ResolveOptions resolveOptions = new ResolveOptions();
   resolveOptions.setDownload(false);
   resolveOptions.setConfs(WrapUtil.toArray(configuration.getName()));
   return resolveOptions;
 }