View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.issue.config;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import de.smartics.util.lang.Arguments;
22  import de.smartics.util.lang.NullArgumentException;
23  
24  /**
25   * Provides access to configurations for the Bugzilla plugin.
26   */
27  public final class Configuration
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    // --- members --------------------------------------------------------------
34  
35    /**
36     * The identifier of the configuration.
37     */
38    private String id;
39  
40    /**
41     * The list of default components to a product stored on a Bugzilla server.
42     */
43    private final List<Component> defaultComponents = new ArrayList<Component>();
44  
45    // ****************************** Initializer *******************************
46  
47    // ****************************** Constructors ******************************
48  
49    /**
50     * Loader constructor.
51     */
52    public Configuration()
53    {
54    }
55  
56    /**
57     * Default constructor.
58     *
59     * @param id the identifier of the configuration.
60     */
61    public Configuration(final String id)
62    {
63      this.id = id;
64    }
65  
66    // ****************************** Inner Classes *****************************
67  
68    // ********************************* Methods ********************************
69  
70    // --- init -----------------------------------------------------------------
71  
72    // --- factory --------------------------------------------------------------
73  
74    // --- get&set --------------------------------------------------------------
75  
76    /**
77     * Returns the identifier of the configuration.
78     *
79     * @return the identifier of the configuration.
80     */
81    public String getId()
82    {
83      return id;
84    }
85  
86    /**
87     * Returns the list of default components to a product stored on a Bugzilla
88     * server.
89     *
90     * @return the list of default components to a product stored on a Bugzilla
91     *         server.
92     */
93    public List<Component> getDefaultComponents()
94    {
95      return defaultComponents;
96    }
97  
98    // --- business -------------------------------------------------------------
99  
100   /**
101    * Adds a default component.
102    *
103    * @param component the component to be added.
104    * @throws NullArgumentException if {@code component} is <code>null</code>.
105    */
106   public void addDefaultComponent(final Component component)
107     throws NullArgumentException
108   {
109     Arguments.checkNotNull("component", component);
110 
111     defaultComponents.add(component);
112   }
113 
114   // --- object basics --------------------------------------------------------
115 
116   /**
117    * Returns the string representation of the object.
118    *
119    * @return the string representation of the object.
120    */
121   @Override
122   public String toString()
123   {
124     final StringBuilder buffer = new StringBuilder();
125 
126     buffer.append(id);
127     for (final Component component : defaultComponents)
128     {
129       buffer.append("\n  ").append(component);
130     }
131 
132     return buffer.toString();
133   }
134 
135 }