1 /* 2 * Copyright 2006-2023 the original author or authors. 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 * https://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 org.mybatis.generator.api; 17 18 /** 19 * Abstract class that holds information common to all generated files. 20 * 21 * @author Jeff Butler 22 */ 23 public abstract class GeneratedFile { 24 25 protected final String targetProject; 26 27 protected GeneratedFile(String targetProject) { 28 this.targetProject = targetProject; 29 } 30 31 /** 32 * Returns the entire contents of the generated file. Clients 33 * can simply save the value returned from this method as the file contents. 34 * Subclasses such as @see org.mybatis.generator.api.GeneratedJavaFile offer 35 * more fine grained access to file parts, but still implement this method 36 * in the event that the entire contents are desired. 37 * 38 * @return Returns the content. 39 */ 40 public abstract String getFormattedContent(); 41 42 /** 43 * Get the file name (without any path). Clients should use this method to 44 * determine how to save the results. 45 * 46 * @return Returns the file name. 47 */ 48 public abstract String getFileName(); 49 50 /** 51 * Gets the target project. Clients can call this method to determine how to 52 * save the results. 53 * 54 * @return the target project 55 */ 56 public String getTargetProject() { 57 return targetProject; 58 } 59 60 /** 61 * Get the target package for the file. Clients should use this method to 62 * determine how to save the results. 63 * 64 * @return Returns the target project. 65 */ 66 public abstract String getTargetPackage(); 67 68 /* 69 * (non-Javadoc) 70 * @see java.lang.Object#toString() 71 */ 72 @Override 73 public String toString() { 74 return getFileName(); 75 } 76 77 /** 78 * Checks if is mergeable. 79 * 80 * @return true, if is mergeable 81 */ 82 public abstract boolean isMergeable(); 83 84 public abstract String getFileEncoding(); 85 }