org.apache.ibatis.abator.internal
Class DefaultShellCallback

java.lang.Object
  extended byorg.apache.ibatis.abator.internal.DefaultShellCallback
All Implemented Interfaces:
ShellCallback

public class DefaultShellCallback
extends java.lang.Object
implements ShellCallback

Author:
Jeff Butler

Constructor Summary
DefaultShellCallback(boolean overwrite)
           
 
Method Summary
 java.io.File getDirectory(java.lang.String targetProject, java.lang.String targetPackage, java.util.List warnings)
          Abator will call this method to ask the shell to resolve a project/package combination into a directory on the file system.
 java.lang.String mergeJavaFile(GeneratedJavaFile newFile, java.lang.String javadocTag, java.util.List warnings)
          Abator will call this method if a newly generated Java file would overwrite an existing file.
 boolean mergeSupported()
          Return true if the callback supports Java merging, otherwise false.
 void refreshProject(java.lang.String project)
          After all files are saved to the file system, Abator will call this method 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 java.io.File getDirectory(java.lang.String targetProject,
                                 java.lang.String targetPackage,
                                 java.util.List warnings)
                          throws ShellException
Description copied from interface: ShellCallback
Abator will call this method to ask the shell to resolve a project/package combination into a directory on the file system. Abator will call this method repeatedly (once for each generated file), so it would be wise for an implementing class to cache results. The returned java.io.File object: Abator's 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
Parameters:
targetProject -
targetPackage -
warnings -
Returns:
the directory (must exist)
Throws:
ShellException - if the project/package cannot be resolved into a directory on the file system. In this case, Abator will not save the file it is currently working on. Abator will add the exception message to the list of warnings automatically.

mergeJavaFile

public java.lang.String mergeJavaFile(GeneratedJavaFile newFile,
                                      java.lang.String javadocTag,
                                      java.util.List warnings)
                               throws ShellException
Description copied from interface: ShellCallback
Abator will call this method if a newly generated Java file would overwrite an existing file. This method should return the merged source (formatted). Abator 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 es 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
If you do not want to support merging in your shell, simply return newFile.getFormattedContent(). However, this will overwrite any modifications to the generated files.

Specified by:
mergeJavaFile in interface ShellCallback
Parameters:
newFile - the newly generated Java file
javadocTag - the JavaDoc tag that denotes which methods and fields in the old file to delete (all new methods and fields will also include this tag)
warnings - Any warning strings during the merge can be added to this list. Adding a warning will not stop Abator from saving the resulting source.
Returns:
the merged source, properly formatted. Abator will save the source exactly as returned from this method.
Throws:
ShellException - if the file cannot be merged for some reason. If this exception is thrown, Abator will not save anything and the existing file will remain undisturbed. Abator will add the exception message to the list of warnings automatically.

refreshProject

public void refreshProject(java.lang.String project)
Description copied from interface: ShellCallback
After all files are saved to the file system, Abator will call this method once for each unique project that was affected by the generation run. This method is usefull if your IDE needs to be informed that file system objects have been created or updated. If you are using Abator 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

mergeSupported

public boolean mergeSupported()
Description copied from interface: ShellCallback
Return true if the callback supports Java merging, otherwise false. Abator will only call the mergeJavaFile method if this method returns true;

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