예제 #1
0
  public void doInstancePropertyInit(Object instance, QvtOperationalEvaluationVisitor evalVisitor) {
    if (false == instance instanceof EObject) {
      return;
    }
    EObject eInstance = (EObject) instance;

    EClass intermediateClass = eInstance.eClass();

    Map<EStructuralFeature, OCLExpression<EClassifier>> clsFeatures =
        myClassifierInitializations.get(intermediateClass);
    if (clsFeatures == null) {
      return;
    }
    for (EStructuralFeature eFeature : intermediateClass.getEAllStructuralFeatures()) {
      IntermediateStaticFieldAdapter adapter =
          (IntermediateStaticFieldAdapter)
              EcoreUtil.getAdapter(eFeature.eAdapters(), IntermediateStaticFieldAdapter.class);
      if (adapter != null && adapter.isInitialized()) {
        continue;
      }

      OCLExpression<EClassifier> expression = clsFeatures.get(eFeature);

      Object evalResult = expression != null ? evalVisitor.visitExpression(expression) : null;

      if (evalResult == null) {
        // no init expression specified for a single-valued feature, or init expression evaluated to
        // null
        EClassifier featureType =
            evalVisitor.getEnvironment().getUMLReflection().getOCLType(eFeature);
        evalResult =
            EvaluationUtil.createInitialValue(
                featureType,
                evalVisitor.getEnvironment().getOCLStandardLibrary(),
                evalVisitor.getEvaluationEnvironment());
      }

      // temporary switch off read-only property
      boolean isChangeable = eFeature.isChangeable();
      eFeature.setChangeable(true);

      boolean isUndefined =
          QvtOperationalUtil.isUndefined(evalResult, evalVisitor.getEvaluationEnvironment());
      evalVisitor
          .getOperationalEvaluationEnv()
          .callSetter(eInstance, eFeature, evalResult, isUndefined, true);

      eFeature.setChangeable(isChangeable);
    }
  }