예제 #1
0
    /** @generated */
    private void initExtentMap(Object context) {
      if (!getStatus().isOK() || context == null) {
        return;
      }
      final Query queryToInit = getQuery();
      final Object extentContext = context;

      queryToInit.setExtentMap(Collections.EMPTY_MAP);
      if (queryToInit.queryText() != null && queryToInit.queryText().indexOf("allInstances") >= 0) {
        AbstractVisitor visitior =
            new AbstractVisitor() {
              private boolean usesAllInstances = false;

              public Object visitOperationCallExp(OperationCallExp oc) {
                if (!usesAllInstances) {
                  usesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();
                  if (usesAllInstances) {
                    queryToInit.setExtentMap(
                        EcoreEnvironmentFactory.ECORE_INSTANCE.createExtentMap(extentContext));
                  }
                }
                return super.visitOperationCallExp(oc);
              }
            };
        queryToInit.getExpression().accept(visitior);
      }
    }
예제 #2
0
    /** @generated */
    protected Object doEvaluate(Object context, Map env) {
      Query oclQuery = getQuery();
      if (oclQuery == null) {
        return null;
      }
      EvaluationEnvironment evalEnv = oclQuery.getEvaluationEnvironment();
      // init environment
      for (Iterator it = env.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry nextEntry = (Map.Entry) it.next();
        evalEnv.replace((String) nextEntry.getKey(), nextEntry.getValue());
      }

      try {
        initExtentMap(context);
        Object result = oclQuery.evaluate(context);
        return (result != Types.OCL_INVALID) ? result : null;
      } finally {
        evalEnv.clear();
        oclQuery.setExtentMap(Collections.EMPTY_MAP);
      }
    }