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.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      /* (non-Javadoc)
89       * @see coras.types.IFaultTree#getFaultTreeModel()
90       */
91      public FaultTreeModel getFaultTreeModel() {
92          return (FaultTreeModel) getRepresentation(RepresentationTypeEnum.FAULT_TREE_MODEL);
93      }
94  
95      /* (non-Javadoc)
96       * @see coras.types.IFaultTree#setFaultTreeModel(java.io.File)
97       */
98      public void setFaultTreeModel(File faultTreeModelFile) throws LockRequiredException, IOException, XmlException {
99          FaultTreeModel newModel = RepresentationFactory.createFaultTreeModel(faultTreeModelFile);
100         setFaultTreeModel(newModel);
101     }
102 
103     /* (non-Javadoc)
104      * @see coras.types.IFaultTree#setFaultTreeModel(coras.representations.FaultTreeModel)
105      */
106     public void setFaultTreeModel(FaultTreeModel newModel) throws LockRequiredException {
107         FaultTreeModel oldModel = getFaultTreeModel();
108         removeRepresentation(oldModel);
109         addRepresentation(newModel);
110     }
111 
112     /* (non-Javadoc)
113      * @see coras.types.IFaultTree#getFaultTreeDiagram()
114      */
115     public DiagramRepresentation getFaultTreeDiagram() {
116         CorasRepresentation representation = getRepresentation(RepresentationTypeEnum.IMAGE);
117         // FIXME check object type
118         return (DiagramRepresentation) representation;
119     }
120 
121     /* (non-Javadoc)
122      * @see coras.types.IFaultTree#setFaultTreeDiagram(java.io.File)
123      */
124     public void setFaultTreeDiagram(File faultTreeDiagramFile) throws IOException, LockRequiredException {
125         DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(faultTreeDiagramFile);
126         setFaultTreeDiagram(newDiagram);
127     }
128 
129     /* (non-Javadoc)
130      * @see coras.types.IFaultTree#setFaultTreeDiagram(coras.representations.Diagram)
131      */
132     public void setFaultTreeDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
133         DiagramRepresentation oldDiagram = getFaultTreeDiagram();
134         removeRepresentation(oldDiagram);
135         addRepresentation(newDiagram);
136     }
137 
138 }