diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/emf/DynamicEMFQueryRuntimeContext.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/emf/DynamicEMFQueryRuntimeContext.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/emf/DynamicEMFQueryRuntimeContext.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/emf/DynamicEMFQueryRuntimeContext.java new file mode 100644 index 00000000..a6da213e --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/emf/DynamicEMFQueryRuntimeContext.java | |||
@@ -0,0 +1,47 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Bergmann Gabor, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.emf; | ||
10 | |||
11 | import org.apache.log4j.Logger; | ||
12 | import tools.refinery.viatra.runtime.base.api.NavigationHelper; | ||
13 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
14 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
15 | |||
16 | /** | ||
17 | * In dynamic EMF mode, we need to make sure that EEnum literal constants and values returned by eval() expressions | ||
18 | * are canonicalized in the same way as enum literals from the EMF model. | ||
19 | * | ||
20 | * <p> This canonicalization is a one-way mapping, so | ||
21 | * {@link #unwrapElement(Object)} and {@link #unwrapTuple(Object)} remain NOPs. | ||
22 | * | ||
23 | * @author Bergmann Gabor | ||
24 | * | ||
25 | */ | ||
26 | public class DynamicEMFQueryRuntimeContext extends EMFQueryRuntimeContext { | ||
27 | |||
28 | public DynamicEMFQueryRuntimeContext(NavigationHelper baseIndex, Logger logger, EMFScope emfScope) { | ||
29 | super(baseIndex, logger, emfScope); | ||
30 | } | ||
31 | |||
32 | @Override | ||
33 | public Object wrapElement(Object externalElement) { | ||
34 | return baseIndex.toCanonicalValueRepresentation(externalElement); | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public Tuple wrapTuple(Tuple externalElements) { | ||
39 | Object[] elements = externalElements.getElements(); | ||
40 | for (int i=0; i< elements.length; ++i) | ||
41 | elements[i] = wrapElement(elements[i]); | ||
42 | return Tuples.flatTupleOf(elements); | ||
43 | } | ||
44 | |||
45 | |||
46 | |||
47 | } | ||