1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.reuse;
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 class FaultTreeExperience extends Experience implements IFaultTree {
49
50 /***
51 * @param experiencePackage
52 * @param subtype
53 * @param name
54 * @param description
55 * @param concern
56 * @param viewpoint
57 * @return
58 * @throws LockException
59 */
60 protected static FaultTreeExperience create(
61 ExperiencePackage experiencePackage, String name,
62 String shortDescription, String fullDescription,
63 CategoryEnum category, String domain, ConcernEnum concern,
64 ViewpointEnum[] viewpoints, FaultTreeModel faultTreeModel,
65 DiagramRepresentation diagram) throws LockException {
66 List representationList = new ArrayList();
67 if (faultTreeModel != null) {
68 representationList.add(faultTreeModel);
69 }
70 if (diagram != null) {
71 representationList.add(diagram);
72 }
73 CorasRepresentation[] representations = (CorasRepresentation[]) representationList.toArray(new CorasRepresentation[0]);
74 Asset asset = createAsset(experiencePackage,
75 ElementTypeEnum.FAULT_TREE, null, name, shortDescription,
76 fullDescription, category, domain, concern, viewpoints,
77 representations);
78 return new FaultTreeExperience(asset);
79 }
80
81 /***
82 * @param asset
83 */
84 protected FaultTreeExperience(Asset asset) {
85 super(asset);
86 }
87
88
89
90
91 public FaultTreeModel getFaultTreeModel() {
92 return (FaultTreeModel) getRepresentation(RepresentationTypeEnum.FAULT_TREE_MODEL);
93 }
94
95
96
97
98 public void setFaultTreeModel(File faultTreeModelFile) throws LockRequiredException, IOException, XmlException {
99 FaultTreeModel newModel = RepresentationFactory.createFaultTreeModel(faultTreeModelFile);
100 setFaultTreeModel(newModel);
101 }
102
103
104
105
106 public void setFaultTreeModel(FaultTreeModel newModel) throws LockRequiredException {
107 FaultTreeModel oldModel = getFaultTreeModel();
108 removeRepresentation(oldModel);
109 addRepresentation(newModel);
110 }
111
112
113
114
115 public DiagramRepresentation getFaultTreeDiagram() {
116 CorasRepresentation representation = getRepresentation(RepresentationTypeEnum.IMAGE);
117
118 return (DiagramRepresentation) representation;
119 }
120
121
122
123
124 public void setFaultTreeDiagram(File faultTreeDiagramFile) throws IOException, LockRequiredException {
125 DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(faultTreeDiagramFile);
126 setFaultTreeDiagram(newDiagram);
127 }
128
129
130
131
132 public void setFaultTreeDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
133 DiagramRepresentation oldDiagram = getFaultTreeDiagram();
134 removeRepresentation(oldDiagram);
135 addRepresentation(newDiagram);
136 }
137
138 }