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.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      /* (non-Javadoc)
91       * @see coras.types.IUMLModel#getXmi()
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     /* (non-Javadoc)
105      * @see coras.types.IUMLModel#setXmi(java.io.File)
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 //        System.out.println("xmiLight: " + new String(XmlHelper.xmlToUtf8(xmiLight.getXmlContent(), true)));
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         	if (result != null) {
129 				try {
130 					setXmiLight(result);
131 				} catch (LockRequiredException e) {
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     /* (non-Javadoc)
146      * @see coras.types.IUMLModel#getUMLDiagram()
147      */
148     public DiagramRepresentation getUMLDiagram() {
149         CorasRepresentation diagramRepresentation = getRepresentation(RepresentationTypeEnum.IMAGE);
150         return (DiagramRepresentation) diagramRepresentation;
151     }
152 
153     /* (non-Javadoc)
154      * @see coras.types.IUMLModel#setUMLDiagram(java.io.File)
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 }