aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/ComponentFaultTreeTrace.xtend
blob: 10c91fb408d7dbd3a038ced747b5fc52f4d7c59e (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
40
41
42
43
44
45
46
47
48
49
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 hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Modality
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) {
		instantiateComponent(patternMatch, componenDefinition, Modality.MUST, false)
	}

	def instantiateComponent(IPatternMatch patternMatch, ComponentDefinition componenDefinition, Modality exists,
		boolean allowMultiple) {
		if (componentInstancesMap.containsKey(patternMatch)) {
			throw new IllegalArgumentException("Already instantiated component for match: " + patternMatch)
		}
		val componentTrace = new ComponentInstanceTrace(componentFaultTree, componenDefinition, nameGenerator,
			exists, allowMultiple)
		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")
		}
		if (!trace.appearsExactlyOnce) {
			throw new IllegalArgumentException("Top level must appear in the fault tree exactly once")
		}
		componentFaultTree.topEvent = outputs.head
	}

	def lookup(IPatternMatch patternMatch) {
		componentInstancesMap.get(patternMatch)
	}
}