Esempio n. 1
0
  public boolean executeDmlValidationBlock(Operation dml, Element self) throws ValidationException {

    Element result = null;

    // Store the old local variables and iterators. Needed because structure
    // templates need to keep the state across template.execute() calls.
    LocalVariableMap oldVariables = createLocalVariableMap(null);
    IteratorMap oldIterators = createIteratorMap();

    // Initialize the SELF reference to the local self value.
    SelfHolder selfHolder = new ReadOnlySelfHolder(self);
    initializeSelfHolder(selfHolder);

    try {

      result = dml.execute(this);

    } catch (ReturnValueException rve) {

      result = rve.getElement();

    } catch (EvaluationException ee) {

      File objectFile = (objectTemplate != null) ? objectTemplate.source : null;
      ValidationException ve =
          ValidationException.create(MSG_VALIDATION_FAILED_BECAUSE_OF_EXCEPTION);
      ve.setObjectTemplate(objectFile);
      ve.initCause(ee);
      throw ve;

    } finally {
      clearSelf();

      restoreLocalVariableMap(oldVariables);
      restoreIteratorMap(oldIterators);
    }

    try {
      BooleanProperty bresult = (BooleanProperty) result;
      return bresult.getValue().booleanValue();
    } catch (ClassCastException cce) {
      File objectFile = (objectTemplate != null) ? objectTemplate.source : null;
      ValidationException ve =
          ValidationException.create(
              MSG_INVALID_VALIDATION_FUNCTION_RETURN_TYPE, result.getTypeAsString());
      throw ve.setObjectTemplate(objectFile);
    }
  }
Esempio n. 2
0
  public Element executeDmlBlock(Operation dml) {
    Element result = null;

    // Store the old local variables and iterators. Needed because structure
    // templates need to keep the state across template.execute() calls.
    LocalVariableMap oldVariables = createLocalVariableMap(null);
    IteratorMap oldIterators = createIteratorMap();

    // If the TEMPLATE variable is already set, then don't set the value to
    // the current template. This can happen when executing structure
    // templates and we want to keep the outermost value.
    boolean setTemplate = (getGlobalVariable(TPL_VAR) == null);

    // Set the value of TEMPLATE to the current template. Be careful,
    // compile time execution doesn't set the current template. In this
    // case, don't set the global variable.
    if (setTemplate) {
      Template current = getCurrentTemplate();
      if (current != null) {
        StringProperty tname = StringProperty.getInstance(current.name);
        setGlobalVariable(TPL_VAR, tname, true);
      } else {
        setTemplate = false;
      }
    }

    // Run the DML block. Making sure to always restore the previous
    // variables and iterators.
    try {
      result = dml.execute(this);
    } catch (ReturnValueException rve) {
      result = rve.getElement();
    } finally {

      // Remove TEMPLATE variable if we set it above.
      if (setTemplate) {
        removeGlobalVariable(TPL_VAR);
      }

      // Restore the saved local variables and iterators.
      restoreLocalVariableMap(oldVariables);
      restoreIteratorMap(oldIterators);
    }

    return result;
  }