1 /* 2 * Copyright 2012-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.impl.config.ds; 17 18 import de.smartics.properties.api.config.ds.DataSourceConfiguration; 19 import de.smartics.util.lang.BlankArgumentException; 20 21 /** 22 * Helper to create instances of {@link DataSourceConfiguration}. 23 */ 24 public final class DataSourceConfigurationBuilder 25 { // NOPMD 26 // ********************************* Fields ********************************* 27 28 // --- constants ------------------------------------------------------------ 29 30 // --- members -------------------------------------------------------------- 31 32 /** 33 * The source of the data source configuration. 34 * 35 * @serial 36 */ 37 private String configSourceId; 38 39 /** 40 * The name of the data source to lookup in a JNDI context. 41 * 42 * @serial 43 */ 44 private String jndiName; 45 46 /** 47 * The flag to drop the configuration table if set to <code>true</code>. 48 * 49 * @serial 50 */ 51 private boolean dropTable; 52 53 /** 54 * The flag to create the configuration if set to <code>true</code>. 55 * 56 * @serial 57 */ 58 private boolean createTable; 59 60 // ****************************** Initializer ******************************* 61 62 // ****************************** Constructors ****************************** 63 64 // ****************************** Inner Classes ***************************** 65 66 // ********************************* Methods ******************************** 67 68 // --- init ----------------------------------------------------------------- 69 70 // --- get&set -------------------------------------------------------------- 71 72 /** 73 * Returns the source of the data source configuration. 74 * 75 * @return the source of the data source configuration. 76 */ 77 public String getConfigSourceId() 78 { 79 return configSourceId; 80 } 81 82 /** 83 * Sets the source of the data source configuration. 84 * 85 * @param configSourceId the source of the data source configuration. 86 */ 87 public void setConfigSourceId(final String configSourceId) 88 { 89 this.configSourceId = configSourceId; 90 } 91 92 /** 93 * Sets the name of the data source to lookup in a JNDI context. 94 * 95 * @param jndiName the name of the data source to lookup in a JNDI context. 96 */ 97 public void setJndiName(final String jndiName) 98 { 99 this.jndiName = jndiName; 100 } 101 102 /** 103 * Sets the flag to drop the configuration table if set to <code>true</code>. 104 * 105 * @param dropTable the flag to drop the configuration table if set to 106 * <code>true</code>. 107 */ 108 public void setDropTable(final boolean dropTable) 109 { 110 this.dropTable = dropTable; 111 } 112 113 /** 114 * Sets the flag to create the configuration if set to <code>true</code>. 115 * 116 * @param createTable the flag to create the configuration if set to 117 * <code>true</code>. 118 */ 119 public void setCreateTable(final boolean createTable) 120 { 121 this.createTable = createTable; 122 } 123 124 /** 125 * Returns the name of the data source to lookup in a JNDI context. 126 * 127 * @return the name of the data source to lookup in a JNDI context. 128 */ 129 public String getJndiName() 130 { 131 return jndiName; 132 } 133 134 /** 135 * Returns the flag to drop the configuration table if set to 136 * <code>true</code>. 137 * 138 * @return the flag to drop the configuration table if set to 139 * <code>true</code>. 140 */ 141 public boolean isDropTable() 142 { 143 return dropTable; 144 } 145 146 /** 147 * Returns the flag to create the configuration if set to <code>true</code>. 148 * 149 * @return the flag to create the configuration if set to <code>true</code>. 150 */ 151 public boolean isCreateTable() 152 { 153 return createTable; 154 } 155 156 // --- business ------------------------------------------------------------- 157 158 /** 159 * Creates an {@link DataSourceConfiguration} instance. 160 * 161 * @return an {@link DataSourceConfiguration} instance. 162 * @throws BlankArgumentException if the {@code jndiName}, {@code createTable} 163 * or {@code dropTable} are blank. 164 */ 165 public DataSourceConfiguration build() throws BlankArgumentException 166 { 167 return new DataSourceConfiguration(configSourceId, jndiName, dropTable, 168 createTable); 169 } 170 171 // --- object basics -------------------------------------------------------- 172 173 }