View Javadoc

1   /*
2    *  Copyright (C) 2003-2005 SINTEF
3    *  Author:  Fredrik Vraalsen (fredrik dot vraalsen at sintef dot no)
4    *  Webpage: http://coras.sourceforge.net/
5    *
6    *  This program is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public License
8    *  as published by the Free Software Foundation; either version 2.1
9    *  of the License, or (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this program; if not, write to the Free
18   *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19   *  02111-1307 USA
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              XmiLightRepresentation xmiLight = RepresentationFactory.createXmiLight(xmiModel, subtype);
73              if (xmiLight != null) {
74                  representationList.add(xmiLight);
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      /* (non-Javadoc)
96       * @see coras.types.IUMLModel#getXmi()
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     /* (non-Javadoc)
110      * @see coras.types.IUMLModel#setXmi(java.io.File)
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 //        System.out.println("xmiLight: " + new String(XmlHelper.xmlToUtf8(xmiLight.getXmlContent())));
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         	if (result != null) {
134 				try {
135 					setXmiLight(result);
136 				} catch (LockRequiredException e) {
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     /* (non-Javadoc)
151      * @see coras.types.IUMLModel#getUMLDiagram()
152      */
153     public DiagramRepresentation getUMLDiagram() {
154         CorasRepresentation diagramRepresentation = getRepresentation(RepresentationTypeEnum.IMAGE);
155         // FIXME check object type
156         return (DiagramRepresentation) diagramRepresentation;
157     }
158 
159     /* (non-Javadoc)
160      * @see coras.types.IUMLModel#setUMLDiagram(java.io.File)
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 }