View Javadoc

1   /*
2    * Copyright 2013 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.properties.config.transfer.templatestream;
17  
18  import de.smartics.util.lang.Arg;
19  
20  /**
21   * Descriptor for table and column names to store property values.
22   */
23  public final class TableDescriptor
24  {
25    // ********************************* Fields *********************************
26  
27    // --- constants ------------------------------------------------------------
28  
29    // --- members --------------------------------------------------------------
30  
31    /**
32     * The name of the configuration table.
33     */
34    private final String table;
35  
36    /**
37     * The name of the configuration key column.
38     */
39    private final String configColumn;
40  
41    /**
42     * The name of the property name column.
43     */
44    private final String nameColumn;
45  
46    /**
47     * The name of the property value column.
48     */
49    private final String valueColumn;
50  
51    // ****************************** Initializer *******************************
52  
53    // ****************************** Constructors ******************************
54  
55    private TableDescriptor(final Builder builder)
56    {
57      this.table = builder.table;
58      this.configColumn = builder.configColumn;
59      this.nameColumn = builder.nameColumn;
60      this.valueColumn = builder.valueColumn;
61    }
62  
63    // ****************************** Inner Classes *****************************
64  
65    /**
66     * The builder of descriptor instances.
67     */
68    public static final class Builder
69    {
70      // ******************************** Fields ********************************
71  
72      // --- constants ----------------------------------------------------------
73  
74      // --- members ------------------------------------------------------------
75  
76      /**
77       * The name of the configuration table.
78       */
79      private String table = "config";
80  
81      /**
82       * The name of the configuration key column.
83       */
84      private String configColumn = "config";
85  
86      /**
87       * The name of the property name column.
88       */
89      private String nameColumn = "name";
90  
91      /**
92       * The name of the property value column.
93       */
94      private String valueColumn = "value";
95  
96      // ***************************** Initializer ******************************
97  
98      // ***************************** Constructors *****************************
99  
100     // ***************************** Inner Classes ****************************
101 
102     // ******************************** Methods *******************************
103 
104     // --- init ---------------------------------------------------------------
105 
106     // --- get&set ------------------------------------------------------------
107 
108     /**
109      * Sets the name of the configuration table.
110      *
111      * @param table the name of the configuration table.
112      * @throws NullPointerException if {@code table} is <code>null</code>.
113      * @throws IllegalArgumentException if {@code table} is blank.
114      */
115     public void setTable(final String table) throws NullPointerException,
116       IllegalArgumentException
117     {
118       this.table = Arg.checkNotBlank("table", table);
119     }
120 
121     /**
122      * Sets the name of the optional configuration key column.
123      *
124      * @param configColumn the name of the optional configuration key column.
125      * @throws NullPointerException if {@code configColumn} is <code>null</code>
126      *           .
127      * @throws IllegalArgumentException if {@code configColumn} is blank.
128      */
129     public void setConfigColumn(final String configColumn)
130       throws NullPointerException, IllegalArgumentException
131     {
132       this.configColumn = Arg.checkNotBlank("configColumn", configColumn);
133     }
134 
135     /**
136      * Sets the name of the property name column.
137      *
138      * @param nameColumn the name of the property name column.
139      * @throws NullPointerException if {@code nameColumn} is <code>null</code>.
140      * @throws IllegalArgumentException if {@code nameColumn} is blank.
141      */
142     public void setNameColumn(final String nameColumn)
143       throws NullPointerException, IllegalArgumentException
144     {
145       this.nameColumn = Arg.checkNotBlank("nameColumn", nameColumn);
146     }
147 
148     /**
149      * Sets the name of the property value column.
150      *
151      * @param valueColumn the name of the property value column.
152      * @throws NullPointerException if {@code valueColumn} is <code>null</code>.
153      * @throws IllegalArgumentException if {@code valueColumn} is blank.
154      */
155     public void setValueColumn(final String valueColumn)
156       throws NullPointerException, IllegalArgumentException
157     {
158       this.valueColumn = Arg.checkNotBlank("valueColumn", valueColumn);
159     }
160 
161     // --- business -----------------------------------------------------------
162 
163     /**
164      * Builds an instance of the descriptor.
165      *
166      * @return an instance of the descriptor.
167      */
168     public TableDescriptor build()
169     {
170       return new TableDescriptor(this);
171     }
172 
173     // --- object basics ------------------------------------------------------
174 
175   }
176 
177   // ********************************* Methods ********************************
178 
179   // --- init -----------------------------------------------------------------
180 
181   // --- get&set --------------------------------------------------------------
182 
183   /**
184    * Returns the name of the configuration table.
185    *
186    * @return the name of the configuration table.
187    */
188   public String getTable()
189   {
190     return table;
191   }
192 
193   /**
194    * Returns the name of the configuration key column.
195    *
196    * @return the name of the configuration key column.
197    */
198   public String getConfigColumn()
199   {
200     return configColumn;
201   }
202 
203   /**
204    * Returns the name of the property name column.
205    *
206    * @return the name of the property name column.
207    */
208   public String getNameColumn()
209   {
210     return nameColumn;
211   }
212 
213   /**
214    * Returns the name of the property value column.
215    *
216    * @return the name of the property value column.
217    */
218   public String getValueColumn()
219   {
220     return valueColumn;
221   }
222 
223   // --- business -------------------------------------------------------------
224 
225   // --- object basics --------------------------------------------------------
226 
227 }