1 package org.apache.torque.generator.configuration.controller; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.apache.torque.generator.control.existingtargetstrategy.ReplaceTargetFileStrategy; 23 import org.apache.torque.generator.outlet.Outlet; 24 import org.apache.torque.generator.qname.QualifiedName; 25 import org.apache.torque.generator.source.SourceProcessConfiguration; 26 import org.apache.torque.generator.source.SourceProvider; 27 28 /** 29 * The configuration for an output (typically one or more files). 30 */ 31 public class Output 32 { 33 /** 34 * The name by which this output can be identified. 35 */ 36 private QualifiedName name; 37 38 /** 39 * The source provider to access the input for generation. 40 */ 41 private SourceProvider sourceProvider; 42 43 /** 44 * The information on how to post-process the sources before generation. 45 */ 46 private SourceProcessConfiguration sourceProcessConfiguration; 47 48 /** 49 * The outlet which generates the content. 50 */ 51 private OutletReference contentOutlet; 52 53 /** 54 * The outlet which generates the filename, or null if the 55 * path to the generated file is explicitly given in <code>path</code>. 56 */ 57 private Outlet filenameOutlet; 58 59 /** 60 * The filename of the generated file, or null if the filename must 61 * still be generated using a filenameOutlet. 62 * This attribute is also used to store the generated filename 63 * if it was generated using the filenameOutlet. 64 */ 65 private String filename; 66 67 /** 68 * The strategy how existing target files should be handled. 69 */ 70 private String existingTargetStrategy 71 = ReplaceTargetFileStrategy.STRATEGY_NAME; 72 73 /** 74 * The key for the output directory into which the output is written, 75 * or null for the default output directory. 76 */ 77 private String outputDirKey; 78 79 /** 80 * The character encoding of the generated file, or null for the platform 81 * default encoding. 82 */ 83 private String encoding; 84 85 /** 86 * Constructor. 87 * 88 * @param name the name by which this output can be identified. 89 */ 90 public Output(QualifiedName name) 91 { 92 this.name = name; 93 } 94 95 /** 96 * Returns the name by which this output can be identified. 97 * 98 * @return the name by which this output can be identified, not null. 99 */ 100 public QualifiedName getName() 101 { 102 return name; 103 } 104 105 /** 106 * Returns the source provider which provides the input for generating the 107 * output file's contents. 108 * 109 * @return the source provider which provides the input for generation. 110 */ 111 public SourceProvider getSourceProvider() 112 { 113 return sourceProvider; 114 } 115 116 /** 117 * Sets the source provider which provides the input for generating the 118 * output file's contents. 119 * 120 * @param sourceProvider the source provider which provides the input for 121 * generation. 122 */ 123 public void setSourceProvider(SourceProvider sourceProvider) 124 { 125 this.sourceProvider = sourceProvider; 126 } 127 128 /** 129 * Returns how the sources should be post-processed before generation. 130 * 131 * @return the information about post-processing the sources. 132 */ 133 public SourceProcessConfiguration getSourceProcessConfiguration() 134 { 135 return sourceProcessConfiguration; 136 } 137 138 /** 139 * Sets how the sources should be post-processed before generation. 140 * 141 * @param sourceProcessConfiguration the information about 142 * post-processing the sources. 143 */ 144 public void setSourceProcessConfiguration( 145 SourceProcessConfiguration sourceProcessConfiguration) 146 { 147 this.sourceProcessConfiguration = sourceProcessConfiguration; 148 } 149 150 /** 151 * Sets the name of the file to generate. 152 * This is also used to store the generated filename 153 * if it was generated using the filenameOutlet. 154 * 155 * @param filename the name of the file to generate. 156 */ 157 public void setFilename(String filename) 158 { 159 this.filename = filename; 160 } 161 162 /** 163 * Returns the name of the file to generate. Either this name was 164 * given explicitly or it was set using the filenameOutlet. 165 * 166 * @return the name of the file to generate. 167 */ 168 public String getFilename() 169 { 170 return filename; 171 } 172 173 /** 174 * Returns the reference to the outlet which should produce the content. 175 * 176 * @return the reference to the outlet responsible for producing the 177 * content. 178 */ 179 public OutletReference getContentOutlet() 180 { 181 return contentOutlet; 182 } 183 184 /** 185 * Sets the reference to the outlet which should produce the content. 186 * 187 * @param contentOutlet the reference to the outlet responsible 188 * for producing the content. 189 */ 190 public void setContentOutlet(OutletReference contentOutlet) 191 { 192 this.contentOutlet = contentOutlet; 193 } 194 195 /** 196 * Returns the reference to the outlet which should produce 197 * the file name. If this attribute is set, it takes precedence over a 198 * set filename. 199 * 200 * @return the reference to the outlet responsible for producing the 201 * file name, or null if the file name is explicitly given. 202 */ 203 public Outlet getFilenameOutlet() 204 { 205 return filenameOutlet; 206 } 207 208 /** 209 * Sets the reference to the outlet which should produce 210 * the file name. 211 * 212 * @param filenameOutlet the reference to the outlet responsible 213 * for producing the file name. 214 */ 215 public void setFilenameOutlet(Outlet filenameOutlet) 216 { 217 this.filenameOutlet = filenameOutlet; 218 } 219 220 /** 221 * Returns the strategy how existing target files should be handled. 222 * 223 * @return the strategy name. 224 */ 225 public String getExistingTargetStrategy() 226 { 227 return existingTargetStrategy; 228 } 229 230 /** 231 * Sets the strategy how existing target files should be handled. 232 * 233 * @param existingTargetStrategy the strategy name. 234 */ 235 public void setExistingTargetStrategy(String existingTargetStrategy) 236 { 237 this.existingTargetStrategy = existingTargetStrategy; 238 } 239 240 /** 241 * Returns the key for the output directory into which the output is 242 * written. 243 * 244 * @return the key for the output directory, or null for the default 245 * output directory. 246 */ 247 public String getOutputDirKey() 248 { 249 return outputDirKey; 250 } 251 252 /** 253 * Sets the key for the output directory into which the output is 254 * written. 255 * 256 * @param outputKeyDir the key for the output directory, 257 * or null for the default output directory. 258 */ 259 public void setOutputDirKey(String outputKeyDir) 260 { 261 this.outputDirKey = outputKeyDir; 262 } 263 264 /** 265 * Returns the character encoding of the generated file(s). 266 * 267 * @return The character encoding of the generated file, 268 * or null for the platform default encoding. 269 */ 270 public String getEncoding() 271 { 272 return encoding; 273 } 274 275 /** 276 * Sets the character encoding of the generated file(s). 277 * 278 * @param encoding The character encoding of the generated file, 279 * or null for the platform default encoding. 280 */ 281 public void setEncoding(String encoding) 282 { 283 this.encoding = encoding; 284 } 285 286 /** 287 * {@inheritDoc} 288 */ 289 @Override 290 public String toString() 291 { 292 StringBuffer result = new StringBuffer(); 293 result.append("(OutputFile: sourceProvider=").append(sourceProvider) 294 .append(",existingTargetStrategy=") 295 .append(existingTargetStrategy) 296 .append(",encoding=") 297 .append(encoding) 298 .append(",filenameOutlet=") 299 .append(filenameOutlet) 300 .append(",contentOutlet=") 301 .append(contentOutlet).append(")"); 302 return result.toString(); 303 } 304 }