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  
26  import no.sintef.assetrepository.Asset;
27  import no.sintef.lock.LockException;
28  import no.sintef.lock.LockRequiredException;
29  import coras.common.CorasRepresentation;
30  import coras.representations.DocumentRepresentation;
31  import coras.representations.RepresentationFactory;
32  import coras.representations.RepresentationTypeEnum;
33  import coras.structure.ConcernEnum;
34  import coras.structure.ViewpointEnum;
35  import coras.types.ElementTypeEnum;
36  import coras.types.IDocument;
37  
38  /***
39   * @author fvr
40   *
41   * TODO To change the template for this generated type comment go to
42   * Window - Preferences - Java - Code Style - Code Templates
43   */
44  public final class DocumentResult extends RiskAnalysisResult implements IDocument {
45  
46      /***
47       * @param project
48       * @param name
49       * @param description
50       * @param concern
51       * @param viewpoint
52       * @return
53       * @throws LockException
54       */
55      protected static DocumentResult create(RiskAnalysisProject project,
56              String name, String shortDescription, String fullDescription,
57              ConcernEnum concern, ViewpointEnum viewpoint, DocumentRepresentation content)
58              throws LockException {
59          CorasRepresentation[] representations = content != null ? new CorasRepresentation[] { content } : new CorasRepresentation[0]; 
60          Asset asset = createAsset(project, ElementTypeEnum.DOCUMENT, null,
61                  name, shortDescription, fullDescription, concern, viewpoint,
62                  representations);
63          return new DocumentResult(asset);
64      }
65  
66      /***
67       * @param assetVersion
68       */
69      protected DocumentResult(Asset asset) {
70          super(asset);
71      }
72  
73      /* (non-Javadoc)
74       * @see coras.types.IDocument#getDocumentContent()
75       */
76      public DocumentRepresentation getDocumentContent() {
77          return (DocumentRepresentation) getRepresentation(RepresentationTypeEnum.DOCUMENT);
78      }
79  
80      /* (non-Javadoc)
81       * @see coras.types.IDocument#setDocumentContent(java.io.File)
82       */
83      public void setDocumentContent(File documentFile) throws IOException, LockRequiredException {
84          DocumentRepresentation newDocument = RepresentationFactory.createDocument(documentFile);
85          setDocumentContent(newDocument);
86      }
87  
88      /* (non-Javadoc)
89       * @see coras.types.IDocument#setDocumentContent(coras.representations.Document)
90       */
91      public void setDocumentContent(DocumentRepresentation newDocument) throws LockRequiredException {
92          DocumentRepresentation oldDocument = getDocumentContent();
93          removeRepresentation(oldDocument);
94          addRepresentation(newDocument);
95      }
96  
97  }