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  
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 class DocumentExperience extends Experience implements IDocument {
45  
46      /***
47       * @param experiencePackage
48       * @param name
49       * @param description
50       * @param concern
51       * @param viewpoint
52       * @return
53       * @throws LockException
54       */
55      protected static DocumentExperience create(
56              ExperiencePackage experiencePackage, String name,
57              String shortDescription, String fullDescription,
58              CategoryEnum category, String domain, ConcernEnum concern,
59              ViewpointEnum[] viewpoints, DocumentRepresentation content)
60              throws LockException {
61          CorasRepresentation[] representations = content != null ? new CorasRepresentation[] { content } : new CorasRepresentation[0]; 
62          Asset asset = createAsset(experiencePackage, ElementTypeEnum.DOCUMENT,
63                  null, name, shortDescription, fullDescription, category,
64                  domain, concern, viewpoints, representations);
65          return new DocumentExperience(asset);
66      }
67  
68      /***
69       * @param asset
70       */
71      protected DocumentExperience(Asset asset) {
72          super(asset);
73      }
74  
75      /* (non-Javadoc)
76       * @see coras.types.IDocument#getDocumentContent()
77       */
78      public DocumentRepresentation getDocumentContent() {
79          return (DocumentRepresentation) getRepresentation(RepresentationTypeEnum.DOCUMENT);
80      }
81  
82      /* (non-Javadoc)
83       * @see coras.types.IDocument#setDocumentContent(java.io.File)
84       */
85      public void setDocumentContent(File documentFile) throws IOException, LockRequiredException {
86          DocumentRepresentation newDocument = RepresentationFactory.createDocument(documentFile);
87          setDocumentContent(newDocument);
88      }
89  
90      /* (non-Javadoc)
91       * @see coras.types.IDocument#setDocumentContent(coras.representations.Document)
92       */
93      public void setDocumentContent(DocumentRepresentation newDocument) throws LockRequiredException {
94          DocumentRepresentation oldDocument = getDocumentContent();
95          removeRepresentation(oldDocument);
96          addRepresentation(newDocument);
97      }
98  
99  }