diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/PackageBasedQueryGroup.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/PackageBasedQueryGroup.java | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/PackageBasedQueryGroup.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/PackageBasedQueryGroup.java deleted file mode 100644 index 252bb7fd..00000000 --- a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/PackageBasedQueryGroup.java +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2012, Abel Hegedus, Mark Czotter, 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.api; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.HashSet; | ||
13 | import java.util.Set; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.api.impl.BaseQueryGroup; | ||
16 | import tools.refinery.viatra.runtime.registry.IQuerySpecificationRegistry; | ||
17 | import tools.refinery.viatra.runtime.registry.IQuerySpecificationRegistryEntry; | ||
18 | import tools.refinery.viatra.runtime.registry.IQuerySpecificationRegistryChangeListener; | ||
19 | import tools.refinery.viatra.runtime.registry.IRegistryView; | ||
20 | import tools.refinery.viatra.runtime.registry.IRegistryViewFilter; | ||
21 | import tools.refinery.viatra.runtime.registry.QuerySpecificationRegistry; | ||
22 | |||
23 | /** | ||
24 | * Package based {@link BaseQueryGroup} implementation. It handles patterns as a group within the same package. | ||
25 | * | ||
26 | * @author Abel Hegedus, Mark Czotter | ||
27 | * | ||
28 | */ | ||
29 | public class PackageBasedQueryGroup extends BaseQueryGroup { | ||
30 | |||
31 | private final Set<IQuerySpecification<?>> querySpecifications = new HashSet<>(); | ||
32 | private final String packageName; | ||
33 | private final boolean includeSubPackages; | ||
34 | private IRegistryView view; | ||
35 | |||
36 | /** | ||
37 | * Creates a query group with specifications of a given package from the {@link QuerySpecificationRegistry}. Only | ||
38 | * query specifications with the exact package fully qualified name are included. | ||
39 | * | ||
40 | * @param packageName | ||
41 | * that contains the specifications | ||
42 | */ | ||
43 | public PackageBasedQueryGroup(String packageName) { | ||
44 | this(packageName, false); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Creates a query group with specifications of a given package from the {@link QuerySpecificationRegistry}. | ||
49 | * | ||
50 | * @param packageName | ||
51 | * that contain the specifications | ||
52 | * @param includeSubPackages | ||
53 | * if true all query specifications with package names starting with the given package are included | ||
54 | */ | ||
55 | public PackageBasedQueryGroup(String packageName, boolean includeSubPackages) { | ||
56 | super(); | ||
57 | this.packageName = packageName; | ||
58 | this.includeSubPackages = includeSubPackages; | ||
59 | IQuerySpecificationRegistry registry = QuerySpecificationRegistry.getInstance(); | ||
60 | view = registry.createView(new PackageNameBasedViewFilter()); | ||
61 | for (IQuerySpecificationRegistryEntry entry : view.getEntries()) { | ||
62 | this.querySpecifications.add(entry.get()); | ||
63 | } | ||
64 | SpecificationSetUpdater listener = new SpecificationSetUpdater(); | ||
65 | view.addViewListener(listener); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | public Set<IQuerySpecification<?>> getSpecifications() { | ||
70 | return Collections.unmodifiableSet(new HashSet<>(querySpecifications)); | ||
71 | } | ||
72 | |||
73 | public String getPackageName() { | ||
74 | return packageName; | ||
75 | } | ||
76 | |||
77 | public boolean isIncludeSubPackages() { | ||
78 | return includeSubPackages; | ||
79 | } | ||
80 | |||
81 | /** | ||
82 | * Refreshes the pattern group from the query specification registry based on the parameters used during the | ||
83 | * initialization. | ||
84 | */ | ||
85 | public void refresh() { | ||
86 | // do nothing, view is automatically refreshed | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * Listener to update the specification set | ||
91 | * | ||
92 | * @author Abel Hegedus | ||
93 | * | ||
94 | */ | ||
95 | private final class SpecificationSetUpdater implements IQuerySpecificationRegistryChangeListener { | ||
96 | @Override | ||
97 | public void entryAdded(IQuerySpecificationRegistryEntry entry) { | ||
98 | querySpecifications.add(entry.get()); | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | public void entryRemoved(IQuerySpecificationRegistryEntry entry) { | ||
103 | querySpecifications.remove(entry.get()); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | * Registry view filter that checks FQNs against the given package name. | ||
109 | * | ||
110 | * @author Abel Hegedus | ||
111 | * | ||
112 | */ | ||
113 | private final class PackageNameBasedViewFilter implements IRegistryViewFilter { | ||
114 | @Override | ||
115 | public boolean isEntryRelevant(IQuerySpecificationRegistryEntry entry) { | ||
116 | String fqn = entry.getFullyQualifiedName(); | ||
117 | if (packageName.length() + 1 < fqn.length()) { | ||
118 | if (includeSubPackages) { | ||
119 | if (fqn.startsWith(packageName + '.')) { | ||
120 | return true; | ||
121 | } | ||
122 | } else { | ||
123 | String name = fqn.substring(fqn.lastIndexOf('.') + 1, fqn.length()); | ||
124 | if (fqn.equals(packageName + '.' + name)) { | ||
125 | return true; | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | } | ||