private void checkTargetedCondition(
      AbstractCondition condition,
      ViolationList result,
      AbstractConditionChecker checker,
      Spreadsheet preparedSpreadsheet)
      throws PropertyAccessException, IncompleteConditionException {
    ISingleViolation violation = null;
    IElement element = null;

    /*
     * Prepare / instrumentalize spreadsheet
     */
    try {
      element = retrieveTarget(condition.getTarget(), preparedSpreadsheet);
    } catch (ParseException pe) {
      violation = new ConditionSingleViolation();
      ((ConditionSingleViolation) violation).setCausingElement(null);
      violation.setPolicyRule(this.dynamicRule);
      ((ConditionSingleViolation) violation)
          .setBaseSeverityValue(this.dynamicRule.getSeverityWeight());
      ((ConditionSingleViolation) violation)
          .appendToDescription("Unresolvable target: " + condition.getTarget());
    }

    if (element != null && checker instanceof AbstractConditionChecker) {
      // If no type is set but a target is set check only the
      // target
      checker.setElement(element);
      violation = checker.check(condition);
    }

    if (violation != null) {
      // Add violation to the result list
      result.add(violation);
    }
  }
  /**
   * Checks if the Spreadsheet meets a set of {@link AbstractCondition} instances and adds found
   * violations to the resultList
   *
   * @param conditions
   * @param result
   * @return The {@link ViolationList} containing new violations
   * @throws NoConditionTargetException Thrown, if a condition had no target and no elementType info
   * @throws PropertyAccessException
   * @throws CheckerCreationException
   * @throws IncompleteConditionException
   */
  protected void checkConditions(
      List<AbstractCondition> conditions, ViolationList result, Spreadsheet preparedSpreadsheet)
      throws NoConditionTargetException, PropertyAccessException, CheckerCreationException,
          IncompleteConditionException {

    for (AbstractCondition condition : conditions) {
      ISingleViolation violation = null;

      // get the corresponding checker
      String conditionClassName = condition.getClass().getCanonicalName();
      Class<? extends IConditionChecker> checkerClass = this.checkers.get(conditionClassName);

      IConditionChecker checker;
      try {
        checker =
            checkerClass.getConstructor(AbstractPolicyRule.class).newInstance(this.dynamicRule);
      } catch (IllegalArgumentException e1) {
        throw new CheckerCreationException(e1);
      } catch (InvocationTargetException e1) {
        throw new CheckerCreationException(e1);
      } catch (NoSuchMethodException e1) {
        throw new CheckerCreationException(e1);
      } catch (SecurityException e1) {
        throw new CheckerCreationException(e1);
      } catch (InstantiationException e) {
        throw new CheckerCreationException(e);
      } catch (IllegalAccessException e) {
        throw new CheckerCreationException(e);
      }

      if (condition.getElementType() == null && condition.getTarget() != null) {

        checkTargetedCondition(
            condition, result, (AbstractConditionChecker) checker, preparedSpreadsheet);

      } else if (condition.getElementType() != null && condition.getElementType() != "") {
        if (checker instanceof AbstractConditionChecker) {
          // If a type is set check all elements of that type
          for (AbstractElementList<?> list : this.inventory.getElementLists()) {
            String currentClassName = list.getElementClass().getCanonicalName();
            String expectedClassName = condition.getElementType();
            if (currentClassName.endsWith(expectedClassName)) {
              for (int e = 0; e < list.getElements().size(); e++) {
                AbstractElement element;
                element = (AbstractElement) list.getElements().get(e);
                if (element != null) {
                  AbstractConditionChecker abstractChecker;
                  abstractChecker = ((AbstractConditionChecker) checker);
                  abstractChecker.setElement(element);
                  // If no type is set but a target is set
                  // check only the target
                  violation = abstractChecker.check(condition);
                } else {
                  ConditionSingleViolation csViolation;
                  csViolation = new ConditionSingleViolation();
                  csViolation.setCausingElement(null);
                  csViolation.setPolicyRule(this.dynamicRule);
                  csViolation.setBaseSeverityValue(this.dynamicRule.getSeverityWeight());
                  violation = csViolation;
                }
              }
            }
          }
        } else if (checker instanceof TargetlessConditionChecker) {
          TargetlessConditionChecker tlChecker = ((TargetlessConditionChecker) checker);
          tlChecker.setInventory(inventory);
          violation = tlChecker.check(condition);
        }

        if (violation != null) {
          // Add violation to the result list
          result.add(violation);
        }
      } else {
        // TODO create specific Excepion class
        // ElementType == null && Target == null
        throw new NoConditionTargetException("The Target and elementType of condition are null!");
      }
    }
  }