org.apache.ibatis.ibator.api
Interface ShellCallback

All Known Implementing Classes:
DefaultShellCallback

public interface ShellCallback

This interface defines methods that a shell should support to enable ibator to work. A "shell" is defined as the ibator execution environment (i.e. an Eclipse plugin, and Ant task, a NetBeans plugin, etc.) ibator provides a default ShellCallback that is very low function and does not support the merging of Java files. The default shell callback is only appropriate for use in well controlled environments where no changes are ever made to generated Java files.

Author:
Jeff Butler

Method Summary
 java.io.File getDirectory(java.lang.String targetProject, java.lang.String targetPackage)
          ibator will call this method 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 ibator should overwrite an existing file if one exists.
 java.lang.String mergeJavaFile(java.lang.String newFileSource, java.lang.String existingFileFullPath, java.lang.String[] javadocTags)
          ibator will call this method if a newly generated Java file would overwrite an existing file.
 void refreshProject(java.lang.String project)
          After all files are saved to the file system, ibator will call this method once for each unique project that was affected by the generation run.
 

Method Detail

getDirectory

java.io.File getDirectory(java.lang.String targetProject,
                          java.lang.String targetPackage)
                          throws ShellException
ibator will call this method to ask the shell to resolve a project/package combination into a directory on the file system. ibator 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: ibator default shell callback interprets both values as directories and simply concatenates the two values to generate the default directory.

Parameters:
targetProject -
targetPackage -
Returns:
the directory (must exist)
Throws:
ShellException - if the project/package cannot be resolved into a directory on the file system. In this case, ibator will not save the file it is currently working on. ibator will add the exception message to the list of warnings automatically.

mergeJavaFile

java.lang.String mergeJavaFile(java.lang.String newFileSource,
                               java.lang.String existingFileFullPath,
                               java.lang.String[] javadocTags)
                               throws ShellException
ibator will call this method if a newly generated Java file would overwrite an existing file. This method should return the merged source (formatted). ibator 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
Ibator will only call this method if you return true from isMergeSupported().

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)
Returns:
the merged source, properly formatted. ibator 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, ibator will not save anything and the existing file will remain undisturbed. ibator will add the exception message to the list of warnings automatically.

refreshProject

void refreshProject(java.lang.String project)
After all files are saved to the file system, ibator will call this method 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 using ibator outside of an IDE, your implementation need not do anything in this method.

Parameters:
project - the project to be refreshed

isMergeSupported

boolean isMergeSupported()
Return true if the callback supports Java merging, otherwise false. ibator will only call the mergeJavaFile() method if this method returns true.

Returns:
a boolean specifying whether Java merge is supported or not

isOverwriteEnabled

boolean isOverwriteEnabled()
Return true if ibator should overwrite an existing file if one exists. Ibator will only call this method if isMergeSupported() returns false and a file exists that would be overwritten by a generated file. If you return true, then ibator will log a warning specifying what file was overwritten.

Returns:
true if you want ibator to overwrite existing files