private IdleStrategy parseIdleStrategy(final String arg) throws ParseException {
    if (arg == null || arg.equalsIgnoreCase(NULL_VALUE)) {
      return null;
    }
    IdleStrategy strategy;
    if (arg.startsWith(BackoffIdleStrategy.class.getName())) {
      // this is a special case for BackoffIdleStrategy that allows us to pass in
      // the constructor parameters. At some point, we may want to add a generic way to
      // do this, but for now BackoffIdleStrategy gets special treatment.
      strategy = parseBackoffIdleStrategy(arg);
    } else {
      // Use reflection to create the new IdleStrategy with no parameters.
      try {
        final Class clazz = Class.forName(arg);
        strategy = (IdleStrategy) clazz.newInstance();
      } catch (final ClassNotFoundException
          | IllegalAccessException
          | InstantiationException
          | ClassCastException ex) {
        throw new ParseException(
            "Error creating new instance of '" + arg + "': " + ex.getMessage());
      }
    }

    return strategy;
  }
 /**
  * Should parse a string to select, initialize, and return the user interface selected
  *
  * @param optionValue the string to parse
  * @return the user interface to use
  */
 private void selectUI(String optionValue) {
   try {
     Class<?> cls = Class.forName("com.kpro.ui." + optionValue);
     userInterface = (UserIO) cls.newInstance();
   } catch (Exception e) {
     System.err.println("Selected UserIO not found");
   }
 }
 /**
  * Starts the NetworkR specificied by the configuration settings.
  *
  * @throws ClassNotFoundException
  * @throws InvocationTargetException
  * @throws IllegalAccessException
  * @throws InstantiationException
  * @throws SecurityException
  * @throws IllegalArgumentException
  */
 private void startNetwork()
     throws ClassNotFoundException, IllegalArgumentException, SecurityException,
         InstantiationException, IllegalAccessException, InvocationTargetException {
   // System.err.println("startnetwork called");
   Class<?> cls = Class.forName("com.kpro.datastorage." + genProps.getProperty("NetworkRType"));
   if (cls == null) {
     System.err.println("NetworkRType incorrect- null in Gio.startNetwork()");
   }
   nr =
       (NetworkR)
           cls.getDeclaredConstructors()[0].newInstance(genProps.getProperty("NetworkROptions"));
   // System.err.println("nr in startNetwork="+nr);
 }
 private static ITransportFactory getTransportFactory(String transportFactory) {
   try {
     Class<?> factory = Class.forName(transportFactory);
     if (!ITransportFactory.class.isAssignableFrom(factory))
       throw new IllegalArgumentException(
           String.format(
               "transport factory '%s' " + "not derived from ITransportFactory",
               transportFactory));
     return (ITransportFactory) factory.newInstance();
   } catch (Exception e) {
     throw new IllegalArgumentException(
         String.format("Cannot create a transport factory '%s'.", transportFactory), e);
   }
 }
  private static AuthorizationDataSource getAuthorizationDataSource(
      String snaaName, Properties props)
      throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    for (Object o : props.keySet()) {
      String dataSourceName = snaaName + authorizationAtt + authorizationDataSource;
      if (o.equals(dataSourceName)) {
        AuthorizationDataSource dataSource =
            (AuthorizationDataSource) Class.forName(props.getProperty((String) o)).newInstance();

        String dataSourceUsername =
            props.getProperty(dataSourceName + authorizationDataSourceUsername);
        String dataSourcePassword =
            props.getProperty(dataSourceName + authorizationDataSourcePassword);
        String dataSourceUrl = props.getProperty(dataSourceName + authorizationDataSourceUrl);

        if (dataSourceUsername != null) {
          dataSource.setUsername(dataSourceUsername);
        }
        if (dataSourcePassword != null) {
          dataSource.setPassword(dataSourcePassword);
        }
        if (dataSourceUrl != null) {
          dataSource.setUrl(dataSourceUrl);
        }

        return dataSource;
      }
    }
    // set default
    return new ShibbolethDataSource();
  }
  private LossGenerator parseLossGenerator(final String arg) throws ParseException {
    if (arg == null || arg.equalsIgnoreCase(NULL_VALUE)) {
      return null;
    }
    LossGenerator lossGenerator;
    try {
      final Class clazz = Class.forName(arg);
      lossGenerator = (LossGenerator) clazz.newInstance();
    } catch (final ClassNotFoundException
        | IllegalAccessException
        | InstantiationException
        | ClassCastException ex) {
      throw new ParseException("Error creating new instance of '" + arg + "': " + ex.getMessage());
    }

    return lossGenerator;
  }
Exemple #7
0
 public Monitor mapToMonitor(Map<String, String> map) {
   try {
     Monitor monitor = (Monitor) Class.forName(map.get("class")).newInstance();
     map.remove("class");
     BeanUtils.populate(monitor, map);
     return monitor;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  /**
   * Should parse a string to select, initialize, and return one of the policy databases coded
   *
   * @param optionValue the string to parse
   * @return the policy database being used
   */
  private void selectPDB(String optionValue) {
    try {
      Class<?> cls = Class.forName("com.kpro.datastorage." + optionValue);

      @SuppressWarnings("rawtypes")
      Class[] params = new Class[2];
      params[0] = String.class;
      params[1] = String.class;
      Method m = cls.getDeclaredMethod("getInstance", params);

      Object[] argslist = new Object[2];
      argslist[0] = genProps.getProperty("inDBLoc");
      argslist[1] = genProps.getProperty("outDBLoc", genProps.getProperty("inDBLoc"));
      pdb = (PolicyDatabase) m.invoke(null, argslist);
    } catch (Exception e) {
      System.err.println("Selected PolicyDatabase not found");
    }

    if (pdb == null) {
      System.err.println("pdb null in selectPDB");
    }
  }
 /**
  * runs the part of speech tagger
  *
  * @param file input file
  * @param lang language
  * @param type source or target
  * @return path to the output file of the POS tagger
  */
 public String runPOS(String file, String lang, String type) {
   String posName = resourceManager.getString(lang + ".postagger");
   String langResPath = input + File.separator + lang;
   File f = new File(file);
   String absoluteSourceFilePath = f.getAbsolutePath();
   String fileName = f.getName();
   String relativeFilePath = langResPath + File.separator + fileName + ".pos";
   String absoluteOutputFilePath = (new File(relativeFilePath)).getAbsolutePath();
   String posSourceTaggerPath = resourceManager.getString(lang + ".postagger.exePath");
   String outPath = "";
   try {
     Class c = Class.forName(posName);
     PosTagger tagger = (PosTagger) c.newInstance();
     tagger.setParameters(
         type, posName, posSourceTaggerPath, absoluteSourceFilePath, absoluteOutputFilePath);
     PosTagger.ForceRun(forceRun);
     outPath = tagger.run();
   } catch (Exception e) {
     e.printStackTrace();
   }
   // returns the path of the output file; this is for convenience only so
   // we do't have to calculate it again
   return outPath;
 }
 private static IUserAuthorization getAuthorizationModule(String className)
     throws ClassNotFoundException, InstantiationException, IllegalAccessException {
   return (IUserAuthorization) Class.forName(className).newInstance();
 }
  private int setJobParameters(Job job, AminoJob aj) throws Exception {
    final Configuration conf = job.getConfiguration();
    final Class<? extends DataLoader> dataLoaderClass = aj.getDataLoaderClass();
    AminoInputFormat.setDataLoader(job.getConfiguration(), dataLoaderClass.newInstance());

    if (aj instanceof AminoEnrichmentJob) {
      String output = "";
      int returnType = JOB_TYPE_ENRICHMENT;

      if (aj instanceof AminoReuseEnrichmentJob) {
        System.out.println("Running REUSE Enrichment Join Job");

        AminoReuseEnrichmentJob reuseJob = (AminoReuseEnrichmentJob) aj;
        AminoInputFormat.setDataLoader(
            job.getConfiguration(), reuseJob.getFirstPhaseDataLoaderClass().newInstance());

        String root = conf.get(AminoDriverUtils.ENRICHMENT_ROOT_OUTPUT);
        String front = "";
        if (!root.endsWith("/")) front = "/";
        root += front;
        String dir = reuseJob.getOutputSubDirectory(conf);
        output += root + dir;

        returnType = JOB_TYPE_REUSE_ENRICHMENT;
      } else {
        System.out.println("Running Enrichment Join Job");
      }

      int numReducers =
          conf.getInt(
              AMINO_NUM_REDUCERS_ENRICH_PHASE1,
              conf.getInt(AMINO_NUM_REDUCERS, DEFAULT_NUM_REDUCERS));
      job.setNumReduceTasks(numReducers);

      // Our Framework mapper and reducer
      job.setMapperClass(FrameworkEnrichmentJoinMapper.class);
      job.setCombinerClass(FrameworkEnrichmentJoinCombiner.class);
      job.setReducerClass(FrameworkEnrichmentJoinReducer.class);

      job.setMapOutputKeyClass(EnrichmentJoinKey.class); // Different
      job.setMapOutputValueClass(MapWritable.class);

      job.setOutputKeyClass(BucketStripped.class);
      job.setOutputValueClass(MapWritable.class); // Different

      job.setPartitionerClass(NaturalKeyPartitioner.class);
      job.setGroupingComparatorClass(NaturalKeyGroupingComparator.class);
      job.setSortComparatorClass(CompositeKeyComparator.class);

      job.setInputFormatClass(AminoMultiInputFormat.class);

      AminoEnrichmentJob aej = (AminoEnrichmentJob) aj;
      // AminoMultiInputFormat.setJoinDataLoader(conf, aej.getEnrichmentDataLoader().newInstance());
      AminoMultiInputFormat.setJoinDataLoaders(conf, aej.getEnrichmentDataLoaders());
      AminoMultiInputFormat.setEnrichWorker(conf, aej.getEnrichWorker().newInstance());

      job.setOutputFormatClass(SequenceFileOutputFormat.class);

      // TODO If it already exists, and its age is less than job running frequency, just reuse it
      // instead of doing the above job...
      if (output.length() == 0) {
        output = getEnrichmentOutputPath(aej, conf);
      }
      System.out.println("Output will be written to: " + PathUtils.getJobDataPath(output));

      SequenceFileOutputFormat.setOutputPath(job, new Path(PathUtils.getJobDataPath(output)));
      JobUtilities.deleteDirectory(conf, output);

      CacheBuilder.buildCaches(AminoDataUtils.getDataLoader(conf), aj, output, conf);

      return returnType;

    } else {
      System.out.println("\n==================== Running Amino Job =================\n");

      // Our Framework mapper and reducer
      job.setMapperClass(FrameworkMapper.class);
      job.setReducerClass(FrameworkReducer.class);

      job.setMapOutputKeyClass(BucketStripped.class);
      job.setMapOutputValueClass(MapWritable.class);

      job.setOutputKeyClass(BucketStripped.class);
      job.setOutputValueClass(AminoWritable.class);

      job.setInputFormatClass(AminoInputFormat.class);

      job.setOutputFormatClass(AminoOutputFormat.class);
      job.setNumReduceTasks(conf.getInt(AMINO_NUM_REDUCERS, DEFAULT_NUM_REDUCERS));

      AminoOutputFormat.setAminoConfigPath(
          job, job.getConfiguration().get(AminoConfiguration.DEFAULT_CONFIGURATION_PATH_KEY));

      String output = conf.get("amino.output");
      System.out.println("Output will be written to: " + PathUtils.getJobDataPath(output));
      AminoOutputFormat.setOutputPath(job, new Path(PathUtils.getJobDataPath(output)));
      JobUtilities.deleteDirectory(conf, output);

      CacheBuilder.buildCaches(AminoDataUtils.getDataLoader(conf), aj, output, conf);
      return JOB_TYPE_NORMAL;
    }
  }