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.RepresentationFactory;
35 import coras.representations.RepresentationTypeEnum;
36 import coras.representations.UMLModelRepresentation;
37 import coras.representations.XmiLightRepresentation;
38 import coras.structure.ConcernEnum;
39 import coras.structure.ViewpointEnum;
40 import coras.types.ElementTypeEnum;
41 import coras.types.IUMLModel;
42 import coras.types.SubtypeEnum;
43
44 /***
45 * @author fvr
46 *
47 * TODO To change the template for this generated type comment go to
48 * Window - Preferences - Java - Code Style - Code Templates
49 */
50 public final class UMLModelResult extends RiskAnalysisResult implements IUMLModel {
51
52 /***
53 * @param project
54 * @param subtype
55 * @param name
56 * @param description
57 * @param fullDescription
58 * @param concern
59 * @param viewpoint
60 * @return
61 * @throws LockException
62 */
63 protected static UMLModelResult create(RiskAnalysisProject project,
64 SubtypeEnum subtype, String name, String shortDescription,
65 String fullDescription, ConcernEnum concern,
66 ViewpointEnum viewpoint, UMLModelRepresentation umlModel, DiagramRepresentation diagram)
67 throws LockException {
68 List representationList = new ArrayList();
69 if (umlModel != null) {
70 representationList.add(umlModel);
71
72
73
74
75
76
77 }
78 if (diagram != null) {
79 representationList.add(diagram);
80 }
81 CorasRepresentation[] representations = (CorasRepresentation[]) representationList.toArray(new CorasRepresentation[0]);
82 Asset asset = createAsset(project, ElementTypeEnum.UML_MODEL, subtype,
83 name, shortDescription, fullDescription, concern, viewpoint,
84 representations);
85 return new UMLModelResult(asset);
86 }
87
88 /***
89 * @param assetVersion
90 */
91 protected UMLModelResult(Asset asset) {
92 super(asset);
93 }
94
95
96
97
98 public UMLModelRepresentation getUMLModel() {
99 CorasRepresentation result = getRepresentation(RepresentationTypeEnum.DGM_MODEL);
100 if (result == null) {
101 result = getRepresentation(RepresentationTypeEnum.XMI_MODEL);
102 }
103 if (result == null) {
104 result = getRepresentation(RepresentationTypeEnum.ZUMLZARGO_MODEL);
105 }
106 return (UMLModelRepresentation) result;
107 }
108
109
110
111
112 public void setUMLModel(File umlFile) throws LockRequiredException, IOException, XmlException {
113 UMLModelRepresentation newModel = RepresentationFactory.createUMLModel(umlFile);
114 setUMLModel(newModel);
115 }
116
117 public void setUMLModel(UMLModelRepresentation newModel) throws LockRequiredException {
118 UMLModelRepresentation oldModel = getUMLModel();
119 removeRepresentation(oldModel);
120 addRepresentation(newModel);
121
122 XmiLightRepresentation xmiLight = RepresentationFactory.createXmiLight(this);
123
124 setXmiLight(xmiLight);
125 }
126
127 public XmiLightRepresentation getXmiLight() {
128 XmiLightRepresentation result =
129 (XmiLightRepresentation) getRepresentation(RepresentationTypeEnum.XMI_LIGHT);
130 if (result == null) {
131 result = RepresentationFactory.createXmiLight(this);
132
133
134
135
136
137
138
139
140 }
141 return result;
142 }
143
144 private void setXmiLight(XmiLightRepresentation newXmiLight) throws LockRequiredException {
145 XmiLightRepresentation oldXmiLight = getXmiLight();
146 removeRepresentation(oldXmiLight);
147 addRepresentation(newXmiLight);
148 }
149
150
151
152
153 public DiagramRepresentation getUMLDiagram() {
154 CorasRepresentation diagramRepresentation = getRepresentation(RepresentationTypeEnum.IMAGE);
155
156 return (DiagramRepresentation) diagramRepresentation;
157 }
158
159
160
161
162 public void setUMLDiagram(File umlDiagramFile) throws IOException, LockRequiredException {
163 DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(umlDiagramFile);
164 setUMLDiagram(newDiagram);
165 }
166
167 public void setUMLDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
168 DiagramRepresentation oldDiagram = getUMLDiagram();
169 removeRepresentation(oldDiagram);
170 addRepresentation(newDiagram);
171 }
172
173 }