1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.riskanalysis;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import no.sintef.assetrepository.Asset;
29 import no.sintef.lock.LockException;
30 import no.sintef.lock.LockRequiredException;
31 import no.sintef.xml.XmlException;
32 import coras.common.CorasRepresentation;
33 import coras.representations.DiagramRepresentation;
34 import coras.representations.FaultTreeModel;
35 import coras.representations.RepresentationFactory;
36 import coras.representations.RepresentationTypeEnum;
37 import coras.structure.ConcernEnum;
38 import coras.structure.ViewpointEnum;
39 import coras.types.ElementTypeEnum;
40 import coras.types.IFaultTree;
41
42 /***
43 * @author fvr
44 *
45 * TODO To change the template for this generated type comment go to
46 * Window - Preferences - Java - Code Style - Code Templates
47 */
48 public final class FaultTreeResult extends RiskAnalysisResult implements IFaultTree {
49
50 /***
51 * @param project
52 * @param subtype
53 * @param name
54 * @param description
55 * @param concern
56 * @param viewpoint
57 * @return
58 * @throws LockException
59 */
60 protected static FaultTreeResult create(RiskAnalysisProject project,
61 String name, String shortDescription, String fullDescription,
62 ConcernEnum concern, ViewpointEnum viewpoint,
63 FaultTreeModel faultTreeModel, DiagramRepresentation diagram)
64 throws LockException {
65 List representationList = new ArrayList();
66 if (faultTreeModel != null) {
67 representationList.add(faultTreeModel);
68 }
69 if (diagram != null) {
70 representationList.add(diagram);
71 }
72 CorasRepresentation[] representations = (CorasRepresentation[]) representationList.toArray(new CorasRepresentation[0]);
73 Asset asset = createAsset(project, ElementTypeEnum.FAULT_TREE, null,
74 name, shortDescription, fullDescription, concern, viewpoint,
75 representations);
76 return new FaultTreeResult(asset);
77 }
78
79 /***
80 * @param assetVersion
81 */
82 protected FaultTreeResult(Asset asset) {
83 super(asset);
84 }
85
86
87
88
89 public FaultTreeModel getFaultTreeModel() {
90 return (FaultTreeModel) getRepresentation(RepresentationTypeEnum.FAULT_TREE_MODEL);
91 }
92
93
94
95
96 public void setFaultTreeModel(File faultTreeModelFile) throws LockRequiredException, IOException, XmlException {
97 FaultTreeModel newModel = RepresentationFactory.createFaultTreeModel(faultTreeModelFile);
98 setFaultTreeModel(newModel);
99 }
100
101
102
103
104 public void setFaultTreeModel(FaultTreeModel newModel) throws LockRequiredException {
105 FaultTreeModel oldModel = getFaultTreeModel();
106 removeRepresentation(oldModel);
107 addRepresentation(newModel);
108 }
109
110
111
112
113 public DiagramRepresentation getFaultTreeDiagram() {
114 CorasRepresentation representation = getRepresentation(RepresentationTypeEnum.IMAGE);
115
116 return (DiagramRepresentation) representation;
117 }
118
119
120
121
122 public void setFaultTreeDiagram(File faultTreeDiagramFile) throws IOException, LockRequiredException {
123 DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(faultTreeDiagramFile);
124 setFaultTreeDiagram(newDiagram);
125 }
126
127
128
129
130 public void setFaultTreeDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
131 DiagramRepresentation oldDiagram = getFaultTreeDiagram();
132 removeRepresentation(oldDiagram);
133 addRepresentation(newDiagram);
134 }
135
136 }