1 package org.apache.torque.generator.control.existingtargetstrategy;
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 java.io.File;
23
24 import org.apache.torque.generator.configuration.UnitConfiguration;
25 import org.apache.torque.generator.control.ControllerHelper;
26
27 /**
28 * A handler which implements the strategy to skip existing target files.
29 *
30 * @version $Id: SkipExistingTargetFileStrategy.java 1368426 2012-08-02 11:46:37Z tfischer $
31 */
32 public class SkipExistingTargetFileStrategy extends ReplaceTargetFileStrategy
33 {
34 /** The strategy name "skip". */
35 public static final String STRATEGY_NAME = "skip";
36
37 /**
38 * Will be called before the generation is started and decides whether
39 * the generation process for this file should proceed.
40 *
41 * @param outputDirKey the key for the output directory
42 * into which the generated file should be written,
43 * null for the default output directory.
44 * @param outputPath the path to which the output should be written,
45 * relative to the output base directory.
46 * @param unitConfiguration the configuration of the current configuration
47 * unit, not null.
48 *
49 * @return true if the target file does not exist, false otherwise.
50 */
51 @Override
52 public boolean beforeGeneration(
53 String outputDirKey,
54 String outputPath,
55 String encoding,
56 UnitConfiguration unitConfiguration)
57 {
58 File outputFile = ControllerHelper.getOutputFile(
59 outputDirKey,
60 outputPath,
61 unitConfiguration);
62 return !outputFile.exists();
63 }
64
65 /**
66 * Returns the name of the existing target strategy.
67 *
68 * @return "skip"
69 */
70 public String getStrategyName()
71 {
72 return STRATEGY_NAME;
73 }
74 }