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.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 class UMLModelExperience extends Experience implements IUMLModel {
51
52 /***
53 * @param experiencePackage
54 * @param subtype
55 * @param name
56 * @param shortDescription
57 * @param concern
58 * @param viewpoint
59 * @return
60 * @throws LockException
61 */
62 protected static UMLModelExperience create(
63 ExperiencePackage experiencePackage, SubtypeEnum subtype,
64 String name, String shortDescription, String fullDescription,
65 CategoryEnum category, String domain, ConcernEnum concern,
66 ViewpointEnum[] viewpoints, UMLModelRepresentation umlModel,
67 DiagramRepresentation diagram) throws LockException {
68 List representationList = new ArrayList();
69 if (umlModel != null) {
70 representationList.add(umlModel);
71 }
72 if (diagram != null) {
73 representationList.add(diagram);
74 }
75 CorasRepresentation[] representations = (CorasRepresentation[]) representationList.toArray(new CorasRepresentation[0]);
76 Asset asset = createAsset(experiencePackage, ElementTypeEnum.UML_MODEL,
77 subtype, name, shortDescription, fullDescription, category,
78 domain, concern, viewpoints, representations);
79 return new UMLModelExperience(asset);
80 }
81
82
83 /***
84 * @param asset
85 */
86 protected UMLModelExperience(Asset asset) {
87 super(asset);
88 }
89
90
91
92
93 public UMLModelRepresentation getUMLModel() {
94 CorasRepresentation result = getRepresentation(RepresentationTypeEnum.DGM_MODEL);
95 if (result == null) {
96 result = getRepresentation(RepresentationTypeEnum.XMI_MODEL);
97 }
98 if (result == null) {
99 result = getRepresentation(RepresentationTypeEnum.ZUMLZARGO_MODEL);
100 }
101 return (UMLModelRepresentation) result;
102 }
103
104
105
106
107 public void setUMLModel(File umlFile) throws LockRequiredException, IOException, XmlException {
108 UMLModelRepresentation newModel = RepresentationFactory.createUMLModel(umlFile);
109 setUMLModel(newModel);
110 }
111
112 public void setUMLModel(UMLModelRepresentation newModel) throws LockRequiredException {
113 UMLModelRepresentation oldModel = getUMLModel();
114 removeRepresentation(oldModel);
115 addRepresentation(newModel);
116
117 XmiLightRepresentation xmiLight = RepresentationFactory.createXmiLight(this);
118
119 setXmiLight(xmiLight);
120 }
121
122 public XmiLightRepresentation getXmiLight() {
123 XmiLightRepresentation result =
124 (XmiLightRepresentation) getRepresentation(RepresentationTypeEnum.XMI_LIGHT);
125 if (result == null) {
126 result = RepresentationFactory.createXmiLight(this);
127
128
129
130
131
132
133
134
135 }
136 return result;
137 }
138
139 private void setXmiLight(XmiLightRepresentation newXmiLight) throws LockRequiredException {
140 XmiLightRepresentation oldXmiLight = getXmiLight();
141 removeRepresentation(oldXmiLight);
142 addRepresentation(newXmiLight);
143 }
144
145
146
147
148 public DiagramRepresentation getUMLDiagram() {
149 CorasRepresentation diagramRepresentation = getRepresentation(RepresentationTypeEnum.IMAGE);
150 return (DiagramRepresentation) diagramRepresentation;
151 }
152
153
154
155
156 public void setUMLDiagram(File umlDiagramFile) throws IOException, LockRequiredException {
157 DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(umlDiagramFile);
158 setUMLDiagram(newDiagram);
159 }
160
161 public void setUMLDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
162 DiagramRepresentation oldDiagram = getUMLDiagram();
163 removeRepresentation(oldDiagram);
164 addRepresentation(newDiagram);
165 }
166
167 }