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