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.util.HashMap;
24  import java.util.Map;
25  
26  import no.sintef.assetrepository.Asset;
27  import no.sintef.lock.LockException;
28  import no.sintef.lock.LockRequiredException;
29  import coras.common.AssetTypeEnum;
30  import coras.common.CorasElement;
31  import coras.common.CorasRepresentation;
32  import coras.structure.ConcernEnum;
33  import coras.structure.ViewpointEnum;
34  import coras.types.ElementTypeEnum;
35  import coras.types.SubtypeEnum;
36  
37  /***
38   * @author fvr
39   *
40   * TODO To change the template for this generated type comment go to
41   * Window - Preferences - Java - Code Style - Code Templates
42   */
43  public abstract class Experience extends CorasElement {
44  
45      private static final String CATEGORY = "category";
46      private static final String DOMAIN = "domain";
47  
48      protected static Asset createAsset(ExperiencePackage experiencePackage,
49              ElementTypeEnum type, SubtypeEnum subtype, String name,
50              String shortDescription, String fullDescription,
51              CategoryEnum category, String domain, ConcernEnum concern,
52              ViewpointEnum[] viewpoints, CorasRepresentation[] representations)
53              throws LockException {
54          if (category == null) {
55              throw new IllegalArgumentException("Experience requires non-null category");
56          }
57          Map properties = new HashMap();
58          properties.put(CATEGORY, category.toString());
59          if (domain != null) properties.put(DOMAIN, domain);
60          return createAsset(experiencePackage, AssetTypeEnum.REUSABLE_ELEMENT,
61                  type, subtype, name, shortDescription, fullDescription,
62                  concern, viewpoints, properties, representations);
63      }
64  
65      /***
66       * @param asset
67       */
68      protected Experience(Asset asset) {
69          super(asset);
70      }
71  
72      // No setCategory - category cannot be changed!?
73      public CategoryEnum getCategory() {
74          return CategoryEnum.forName(getProperty(CATEGORY));
75      }
76  
77      /***
78       * @return
79       */
80      public String getDomain() {
81          return getProperty(DOMAIN);
82      }
83      
84      public void setDomain(String newDomain) throws LockRequiredException {
85          setProperty(DOMAIN, newDomain);
86      }
87      
88      protected static ElementTypeEnum getType(Asset asset) {
89          return CorasElement.getType(asset);
90      }
91  
92  }