Esempio n. 1
0
  /**
   * Creates the match engine specified by the given annotation if it has a public no-arg
   * constructor, use the {@link DefaultMatchEngine default} otherwise.
   *
   * @param annotation The annotation on which is defined the match engine we are to use.
   * @return An instance of the specified match engine if it has a public no-arg constructor; an
   *     instance of the {@link DefaultMatchEngine} otherwise.
   */
  private static IMatchEngine createMatchEngine(MatchTest annotation) {
    final Class<? extends IMatchEngine> engineClass = annotation.matchEngine();

    IMatchEngine engine = null;
    try {
      engine = engineClass.newInstance();
    } catch (InstantiationException e) {
      // Swallow : we'll create a default engine instead.
    } catch (IllegalAccessException e) {
      // Swallow : we'll create a default engine instead.
    }
    if (engine == null) {
      engine = new DefaultMatchEngine();
    }
    return engine;
  }
Esempio n. 2
0
  /**
   * Creates the comparison scope specified by the given annotation if it has a public constructor
   * taking three {@link Notifier}s as parameters. We'll return an instance of the {@link
   * DefaultComparisonScope} otherwise.
   *
   * @param tuple The tuple for which we need a comparison scope.
   * @param annotation The annotation on which is specified the desired scope's class.
   * @return An instance of the specified comparison scope it it has the expected constructor, an
   *     instance of the {@link DefaultComparisonScope} otherwise.
   */
  private static IComparisonScope createComparisonScope(NotifierTuple tuple, MatchTest annotation) {
    final Class<? extends IComparisonScope> scopeClass = annotation.scope();

    IComparisonScope scope = null;
    try {
      final Constructor<? extends IComparisonScope> constructor =
          scopeClass.getConstructor(Notifier.class, Notifier.class, Notifier.class);
      scope = constructor.newInstance(tuple.getLeft(), tuple.getRight(), tuple.getOrigin());
      // CHECKSTYLE:OFF invoking a constructor requires 7 catches. Since
      // we're swallowing all exceptions, we simply catch everything.
    } catch (Exception e) {
      // CHECKSTYLE:ON
      // Swallow : we'll create a default engine instead.
    }
    if (scope == null) {
      scope = new DefaultComparisonScope(tuple.getLeft(), tuple.getRight(), tuple.getOrigin());
    }
    return scope;
  }