blob: 7a3e377b80df2ae68eb447c45fc46ccec97f94cf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.CftFactory
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition
import java.util.Map
import org.eclipse.viatra.query.runtime.api.IPatternMatch
import org.eclipse.xtend.lib.annotations.Accessors
class ComponentFaultTreeTrace {
@Accessors val componentFaultTree = CftFactory.eINSTANCE.createComponentFaultTree
val nameGenerator = new ComponentNameGenerator
val Map<IPatternMatch, ComponentInstanceTrace> componentInstancesMap = newHashMap
def instantiateComponent(IPatternMatch patternMatch, ComponentDefinition componenDefinition) {
if (componentInstancesMap.containsKey(patternMatch)) {
throw new IllegalArgumentException("Already instantiated component for match: " + patternMatch)
}
val componentTrace = new ComponentInstanceTrace(componentFaultTree, componenDefinition, nameGenerator)
componentInstancesMap.put(patternMatch, componentTrace)
componentTrace
}
def setTopLevel(ComponentInstanceTrace trace) {
if (componentFaultTree.topEvent !== null) {
throw new IllegalArgumentException("Top level component already set")
}
val outputs = trace.outputs
if (outputs.size !== 1) {
throw new IllegalArgumentException("Top level component must have 1 output, got " + outputs.size +
" instead")
}
componentFaultTree.topEvent = outputs.head
}
def lookup(IPatternMatch patternMatch) {
componentInstancesMap.get(patternMatch)
}
}
|