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 no.sintef.assetrepository.Asset;
24  import no.sintef.lock.LockException;
25  import no.sintef.lock.LockRequiredException;
26  import coras.common.AssetTypeEnum;
27  import coras.common.CorasElement;
28  import coras.common.CorasRepresentation;
29  import coras.structure.ConcernEnum;
30  import coras.structure.ViewpointEnum;
31  import coras.types.ElementTypeEnum;
32  import coras.types.SubtypeEnum;
33  
34  /***
35   * @author fvr
36   *
37   * TODO To change the template for this generated type comment go to
38   * Window - Preferences - Java - Code Style - Code Templates
39   */
40  public abstract class RiskAnalysisResult extends CorasElement {
41  
42      protected static Asset createAsset(RiskAnalysisProject project,
43              ElementTypeEnum type, SubtypeEnum subtype, String name,
44              String shortDescription, String fullDescription,
45              ConcernEnum concern, ViewpointEnum viewpoint,
46              CorasRepresentation[] representations) throws LockException {
47          ViewpointEnum[] viewpoints = (viewpoint != null ? new ViewpointEnum[] { viewpoint } : new ViewpointEnum[0]);
48          return createAsset(project, AssetTypeEnum.RISK_ANALYSIS_RESULT, type,
49                  subtype, name, shortDescription, fullDescription, concern,
50                  viewpoints, representations);
51      }
52  
53      /***
54       * @param assetVersion
55       */
56      protected RiskAnalysisResult(Asset asset) {
57          super(asset);
58      }
59  
60      /* (non-Javadoc)
61       * @see coras.common.CorasElement#setViewpoints(coras.structure.ViewpointEnum[])
62       */
63      public void setViewpoints(ViewpointEnum[] viewpoints) throws LockRequiredException {
64          if (viewpoints != null && viewpoints.length > 1) {
65              throw new IllegalArgumentException("RiskAnalysisResult can only belong to one viewpoint");
66          }
67          super.setViewpoints(viewpoints);
68      }
69      
70      public ViewpointEnum getViewpoint() {
71          ViewpointEnum[] viewpoints = getViewpoints();
72          if (viewpoints == null || viewpoints.length == 0) {
73              return null;
74          } else {
75              return viewpoints[0];
76          }
77      }
78      public void setViewpoint(ViewpointEnum viewpoint) throws LockRequiredException {
79          setViewpoints(viewpoint != null ? new ViewpointEnum[] { viewpoint } : new ViewpointEnum[0]);
80      }
81  
82      protected static ElementTypeEnum getType(Asset asset) {
83          return CorasElement.getType(asset);
84      }
85  
86  }