diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/AbstractRegistrySourceConnector.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/AbstractRegistrySourceConnector.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/AbstractRegistrySourceConnector.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/AbstractRegistrySourceConnector.java new file mode 100644 index 00000000..0e2ef273 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/registry/connector/AbstractRegistrySourceConnector.java | |||
@@ -0,0 +1,81 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Abel Hegedus, IncQuery Labs Ltd. | ||
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.registry.connector; | ||
10 | |||
11 | import java.util.HashSet; | ||
12 | import java.util.Objects; | ||
13 | import java.util.Set; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.registry.IConnectorListener; | ||
16 | import tools.refinery.viatra.runtime.registry.IRegistrySourceConnector; | ||
17 | |||
18 | /** | ||
19 | * Abstract registry source connector implementation that stores the identifier and listener set. | ||
20 | * | ||
21 | * | ||
22 | * @author Abel Hegedus | ||
23 | * @since 1.3 | ||
24 | * | ||
25 | */ | ||
26 | public abstract class AbstractRegistrySourceConnector implements IRegistrySourceConnector { | ||
27 | |||
28 | protected Set<IConnectorListener> listeners; | ||
29 | private String identifier; | ||
30 | private boolean includeInDefaultViews; | ||
31 | |||
32 | /** | ||
33 | * Creates an instance of the connector with the given identifier. The identifier should be unique if you want to | ||
34 | * add it to a registry as a source. | ||
35 | * | ||
36 | * @param identifier | ||
37 | * of the newly created connector | ||
38 | * @param includeInDefaultViews | ||
39 | * true if the specifications in the connector should be included in default views | ||
40 | */ | ||
41 | public AbstractRegistrySourceConnector(String identifier, boolean includeInDefaultViews) { | ||
42 | super(); | ||
43 | Objects.requireNonNull(identifier, "Identifier must not be null!"); | ||
44 | this.identifier = identifier; | ||
45 | this.includeInDefaultViews = includeInDefaultViews; | ||
46 | this.listeners = new HashSet<>(); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public String getIdentifier() { | ||
51 | return identifier; | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public boolean includeSpecificationsInDefaultViews() { | ||
56 | return includeInDefaultViews; | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | public void addListener(IConnectorListener listener) { | ||
61 | Objects.requireNonNull(listener, "Listener must not be null!"); | ||
62 | boolean added = listeners.add(listener); | ||
63 | if (added) { | ||
64 | sendQuerySpecificationsToListener(listener); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | public void removeListener(IConnectorListener listener) { | ||
70 | Objects.requireNonNull(listener, "Listener must not be null!"); | ||
71 | listeners.remove(listener); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Subclasses should send add notifications for each specification in the connector to the given listener. | ||
76 | * | ||
77 | * @param listener that should receive the notifications | ||
78 | */ | ||
79 | protected abstract void sendQuerySpecificationsToListener(IConnectorListener listener); | ||
80 | |||
81 | } \ No newline at end of file | ||