org.mybatis.generator.internal
Class DefaultShellCallback

java.lang.Object
  extended by org.mybatis.generator.internal.DefaultShellCallback
All Implemented Interfaces:
ShellCallback

public class DefaultShellCallback
extends Object
implements ShellCallback

Author:
Jeff Butler

Constructor Summary
DefaultShellCallback(boolean overwrite)
           
 
Method Summary
 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, String existingFileFullPath, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultShellCallback

public DefaultShellCallback(boolean overwrite)
Method Detail

getDirectory

public File getDirectory(String targetProject,
                         String targetPackage)
                  throws ShellException
Description copied from interface: ShellCallback
This method is called to ask the shell to resolve a project/package combination into a directory on the file system. This method is called repeatedly (once for each generated file), so it would be wise for an implementing class to cache results. 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.

Specified by:
getDirectory in interface ShellCallback
Returns:
the directory (must exist)
Throws:
ShellException - 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.

refreshProject

public void refreshProject(String project)
Description copied from interface: ShellCallback
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. This method is useful if your IDE needs to be informed that file system objects have been created or updated. If you are running outside of an IDE, your implementation need not do anything in this method.

Specified by:
refreshProject in interface ShellCallback
Parameters:
project - the project to be refreshed

isMergeSupported

public boolean isMergeSupported()
Description copied from interface: ShellCallback
Return true if the callback supports Java merging, otherwise false. The mergeJavaFile() method will be called only if this method returns true.

Specified by:
isMergeSupported in interface ShellCallback
Returns:
a boolean specifying whether Java merge is supported or not

isOverwriteEnabled

public boolean isOverwriteEnabled()
Description copied from interface: ShellCallback
Return true if the generator should overwrite an existing file if one exists. This method will be called only if 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.

Specified by:
isOverwriteEnabled in interface ShellCallback
Returns:
true if you want to overwrite existing files

mergeJavaFile

public String mergeJavaFile(String newFileSource,
                            String existingFileFullPath,
                            String[] javadocTags,
                            String fileEncoding)
                     throws ShellException
Description copied from interface: ShellCallback
This method is called if a newly generated Java file would overwrite an existing file. This method should return the merged source (formatted). The generator will write the merged source as-is to the file system. A merge typically follows these steps:
  1. Delete any methods/fields in the existing file that have the specified JavaDoc tag
  2. Add any new super interfaces from the new file into the existing file
  3. Make sure that the existing file's super class matches the new file
  4. Make sure that the existing file is of the same type as the existing file (either interface or class)
  5. Add any new imports from the new file into the existing file
  6. Add all methods and fields from the new file into the existing file
  7. Format the resulting source string
This method is called only if you return true from isMergeSupported().

Specified by:
mergeJavaFile in interface ShellCallback
Parameters:
newFileSource - the source of the newly generated Java file
existingFileFullPath - the fully qualified path name of the existing Java file
javadocTags - 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.
Returns:
the merged source, properly formatted. The source will be saved exactly as returned from this method.
Throws:
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 © 2010-2012 MyBatis.org. All Rights Reserved.