public class DefaultShellCallback extends Object implements ShellCallback
Constructor and Description |
---|
DefaultShellCallback(boolean overwrite)
Instantiates a new default shell callback.
|
Modifier and Type | Method and Description |
---|---|
File |
getDirectory(String targetProject,
String targetPackage)
This method is called to ask the shell to resolve a project/package combination into a directory on the file
system.
|
boolean |
isMergeSupported()
Return true if the callback supports Java merging, otherwise false.
|
boolean |
isOverwriteEnabled()
Return true if the generator should overwrite an existing file if one exists.
|
String |
mergeJavaFile(String newFileSource,
File existingFile,
String[] javadocTags,
String fileEncoding)
This method is called if a newly generated Java file would
overwrite an existing file.
|
void |
refreshProject(String project)
After all files are saved to the file system, this method is called
once for each unique project that was affected by the generation
run.
|
public DefaultShellCallback(boolean overwrite)
overwrite
- the overwritepublic File getDirectory(String targetProject, String targetPackage) throws ShellException
ShellCallback
The returned java.io.File
object:
The default shell callback interprets both values as directories and simply concatenates the two values to generate the default directory.
getDirectory
in interface ShellCallback
targetProject
- the target projecttargetPackage
- the target packageShellException
- if the project/package cannot be resolved into a directory on the file system. In this case, the
generator will not save the file it is currently working on. The generator will add the exception
message to the list of warnings automatically.public void refreshProject(String project)
ShellCallback
refreshProject
in interface ShellCallback
project
- the project to be refreshedpublic boolean isMergeSupported()
ShellCallback
mergeJavaFile()
method will be called only if this
method returns true
.isMergeSupported
in interface ShellCallback
public boolean isOverwriteEnabled()
ShellCallback
isMergeSupported()
returns false
and a file exists that would be overwritten by
a generated file. If you return true
, then we will log a
warning specifying what file was overwritten.isOverwriteEnabled
in interface ShellCallback
public String mergeJavaFile(String newFileSource, File existingFile, String[] javadocTags, String fileEncoding) throws ShellException
ShellCallback
A merge typically follows these steps:
This method is called only if you return true
from
isMergeSupported()
.
mergeJavaFile
in interface ShellCallback
newFileSource
- the source of the newly generated Java fileexistingFile
- the existing Java filejavadocTags
- the JavaDoc tags that denotes which methods and fields in the
old file to delete (if the Java element has any of these tags,
the element is eligible for merge)fileEncoding
- the file encoding for reading existing Java files. Can be null,
in which case the platform default encoding will be used.ShellException
- if the file cannot be merged for some reason. If this
exception is thrown, nothing will be saved and the
existing file will remain undisturbed. The generator will add the
exception message to the list of warnings automatically.Copyright © 2006–2018 MyBatis.org. All rights reserved.