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.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 final class FaultTreeResult extends RiskAnalysisResult implements IFaultTree {
49  
50      /***
51       * @param project
52       * @param subtype
53       * @param name
54       * @param description
55       * @param concern
56       * @param viewpoint
57       * @return
58       * @throws LockException
59       */
60      protected static FaultTreeResult create(RiskAnalysisProject project,
61              String name, String shortDescription, String fullDescription,
62              ConcernEnum concern, ViewpointEnum viewpoint,
63              FaultTreeModel faultTreeModel, DiagramRepresentation diagram)
64              throws LockException {
65          List representationList = new ArrayList();
66          if (faultTreeModel != null) {
67              representationList.add(faultTreeModel);
68          }
69          if (diagram != null) {
70              representationList.add(diagram);
71          }
72          CorasRepresentation[] representations = (CorasRepresentation[]) representationList.toArray(new CorasRepresentation[0]);
73          Asset asset = createAsset(project, ElementTypeEnum.FAULT_TREE, null,
74                  name, shortDescription, fullDescription, concern, viewpoint,
75                  representations);
76          return new FaultTreeResult(asset);
77      }
78  
79      /***
80       * @param assetVersion
81       */
82      protected FaultTreeResult(Asset asset) {
83          super(asset);
84      }
85  
86      /* (non-Javadoc)
87       * @see coras.types.IFaultTree#getFaultTreeModel()
88       */
89      public FaultTreeModel getFaultTreeModel() {
90          return (FaultTreeModel) getRepresentation(RepresentationTypeEnum.FAULT_TREE_MODEL);
91      }
92  
93      /* (non-Javadoc)
94       * @see coras.types.IFaultTree#setFaultTreeModel(java.io.File)
95       */
96      public void setFaultTreeModel(File faultTreeModelFile) throws LockRequiredException, IOException, XmlException {
97          FaultTreeModel newModel = RepresentationFactory.createFaultTreeModel(faultTreeModelFile);
98          setFaultTreeModel(newModel);
99      }
100 
101     /* (non-Javadoc)
102      * @see coras.types.IFaultTree#setFaultTreeModel(coras.representations.FaultTreeModel)
103      */
104     public void setFaultTreeModel(FaultTreeModel newModel) throws LockRequiredException {
105         FaultTreeModel oldModel = getFaultTreeModel();
106         removeRepresentation(oldModel);
107         addRepresentation(newModel);
108     }
109 
110     /* (non-Javadoc)
111      * @see coras.types.IFaultTree#getFaultTreeDiagram()
112      */
113     public DiagramRepresentation getFaultTreeDiagram() {
114         CorasRepresentation representation = getRepresentation(RepresentationTypeEnum.IMAGE);
115         // FIXME check object type
116         return (DiagramRepresentation) representation;
117     }
118 
119     /* (non-Javadoc)
120      * @see coras.types.IFaultTree#setFaultTreeDiagram(java.io.File)
121      */
122     public void setFaultTreeDiagram(File faultTreeDiagramFile) throws IOException, LockRequiredException {
123         DiagramRepresentation newDiagram = RepresentationFactory.createDiagram(faultTreeDiagramFile);
124         setFaultTreeDiagram(newDiagram);
125     }
126 
127     /* (non-Javadoc)
128      * @see coras.types.IFaultTree#setFaultTreeDiagram(coras.representations.Diagram)
129      */
130     public void setFaultTreeDiagram(DiagramRepresentation newDiagram) throws LockRequiredException {
131         DiagramRepresentation oldDiagram = getFaultTreeDiagram();
132         removeRepresentation(oldDiagram);
133         addRepresentation(newDiagram);
134     }
135 
136 }