View Javadoc

1   /**
2    * Copyright 2005-2007 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.artifact;
16  
17  import org.figure8.join.core.EntityObject;
18  
19  import java.text.MessageFormat;
20  /**
21   * Entity representing a component type. Such a type helps
22   * categorizing software components into your project.
23   * <br/>
24   * A component type will help by knowing how to generate unique keys for
25   * component artifacts. (see the <code>generateComponentKey()</code> method)
26   * 
27   * @author  <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28   * @version $Revision: 1.3 $
29   *
30   * @hibernate.class table="join_comptypes"
31   * @hibernate.cache usage="read-write"
32   *
33   * @hibernate.query name="join.comptype_findByKey" query="from ComponentType type where type.key = :typeKey"
34   */
35  public class ComponentType extends EntityObject{
36     
37     // Attributes ---------------------------------------------------------------
38     
39     /** The component type key */
40     private String key;
41     /** The component type label */
42     private String label;
43     /** The component type keyTemplate */
44     private String keyTemplate;
45     /** The component type description */
46     private String description;
47     
48     
49     // Constructors -------------------------------------------------------------
50     
51     /** Creates a new instance of ComponentType */
52     public ComponentType(){
53     }
54     
55     /**
56      * Creates a new instance of ComponentType with mandatory attributes
57      * @param key This component type key
58      * @param label This component type label for display
59      * @param keyTemplate This type template fopr generating component keys
60      * @param description The description of this component type
61      */
62     public ComponentType(String key, String label, String keyTemplate, String description){
63        this.key = key;
64        this.label = label;
65        this.keyTemplate = keyTemplate;
66        this.description = description;  
67     }
68  
69  
70     // Public -------------------------------------------------------------------
71     
72     /**
73      * @hibernate.property column="s_key"
74      *    lenght="10" not-nul="true"
75      *    unique="true" update="false"
76      * @return This deliverable type key
77      */
78     public String getKey(){
79        return key;
80     }
81     /** @param key This component type key */
82     public void setKey(String key){
83        this.key = key;
84     }
85     
86     /**
87      * @hibernate.property column="s_label"
88      *    length="40" not-null="true"
89      *    unique="true"
90      * @return This type label for display
91      */
92     public String getLabel(){
93        return label;
94     }
95     /** @param label This type label for display */
96     public void setLabel(String label){
97        this.label = label;
98     }
99     
100    /**
101     * @hibernate.property column="s_keytemplate"
102     *    length="40" not-null="true"
103     *    unique="true"
104     * @return The template used for generating component keys
105     */
106    public String getKeyTemplate(){
107       return keyTemplate;
108    }
109    /**
110     * The template used for component key generation. This template
111     * should be a string representing a <code>MessageFormat</code> with
112     * 2 arguments. (ex: myComponent_r{0}_v{0})
113     * @param keyTemplate MessageFormat template
114     * @see java.text.MessageFormat
115     */
116    public void setKeyTemplate(String keyTemplate){
117       this.keyTemplate = keyTemplate;
118    }
119    
120    /**
121     * @hibernate.property column="s_description" length="100"
122     * @return This component type description
123     */
124    public String getDescription(){
125       return description;
126    }
127    /** @param description The description of this component type */
128    public void setDescription(String description){
129       this.description = description;
130    }
131    
132    /**
133     * Generate a unique key for a compoent. Such a key has to be unique as
134     * specified by the <code>Artifact</code>. So this implementation is using
135     * the given <b>keyTemplate</b> as a java.text.MessageFormat using 2 arguments
136     * that are the component release name (unique for a relase) and the component
137     * version infos (unique for a component within a release).
138     * @param component Component for whom a key should be generated
139     * @return A unique key corresponding to this component. The key is not
140     *    assigned to component.
141     * @see java.text.MessageFormat
142     * @see org.figure8.join.businessobjects.artifact.Artifact
143     */
144    public String generateComponentKey(Component component){
145       // Instantiate a message format.
146       MessageFormat template = new MessageFormat(keyTemplate);
147       // Prepare and format arguments array.
148       Object[] args = new Object[]{component.getVersionInfo()};
149       return template.format(args);
150    }
151 }