Author: jgbutler
Date: Sun Nov 30 05:49:27 2008
New Revision: 721812

URL: http://svn.apache.org/viewvc?rev=721812&view=rev
Log:
[ibator] Some API changes to aid the Eclipse plugin

Modified:
    ibatis/trunk/java/tools/ibator/core/build/version.properties
    ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html
    
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/GeneratedJavaFile.java
    
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java
    
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java
    
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ShellCallback.java
    
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/DefaultShellCallback.java

Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Sun Nov 30 
05:49:27 2008
@@ -1,4 +1,4 @@
 #ibator build version info
-#Wed Nov 12 13:18:01 CST 2008
+#Thu Nov 27 07:43:20 CST 2008
 version=1.2.0
-buildNum=639
+buildNum=642

Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html 
(original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/reference/extending.html Sun 
Nov 30 05:49:27 2008
@@ -68,6 +68,26 @@
 a primary key).  The base <code>IntrospectedTable</code> class holds an 
instance
 of <code>org.apache.ibatis.ibator.internal.rules.IbatorRules</code> that can 
be queried
 to determine many of the rules for code generation.</p>
+<p>Ibator supplies two implementations of introspected table.  The 
implementation is chosen
+bases on the value of the <code>targetRuntime</code> attribute of the
+<code>&lt;ibatorContext&gt;</code> element.  In many cases it will be fer 
simpler
+to extend one of the built in implementations, rather than creating an 
implementation
+from scratch.  The following table shows the built in implementations:</p>
+<table cellspacing="0" cellpadding="5" border="1">
+  <tr>
+    <th>TargetRuntime</th>
+    <th>Implementation</th>
+  </tr>
+  <tr>
+    <td>Ibatis2Java2 (default)</td>
+    
<td><code>org.apache.ibatis.ibator.generator.ibatis2.IntrospectedTableIbatis2Java2Impl</code></td>
+  </tr>
+  <tr>
+    <td>Ibatis2Java5</td>
+    
<td><code>org.apache.ibatis.ibator.generator.ibatis2.IntrospectedTableIbatis2Java5Impl</code></td>
+  </tr>
+</table>
+
 <p>If you choose to implement this extension point, specify the fully qualified
 class name of your implementation with the <code>targetRuntime</code>
 attribute of the <code>&lt;ibatorContext&gt;</code> element.</p>

Modified: 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/GeneratedJavaFile.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/GeneratedJavaFile.java?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/GeneratedJavaFile.java
 (original)
+++ 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/GeneratedJavaFile.java
 Sun Nov 30 05:49:27 2008
@@ -66,14 +66,14 @@
      * Java merge function, you may return null from this method. 
      * 
      * @return the CompilationUnit associated with this file, or
-     *   null if the file is not mergable.
+     *   null if the file is not mergeable.
      */
     public CompilationUnit getCompilationUnit() {
         return compilationUnit;
     }
 
     /**
-     * A Java file is mergable if the getCompilationUnit() method
+     * A Java file is mergeable if the getCompilationUnit() method
      * returns a valid compilation unit.
      * 
      */

Modified: 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java
 (original)
+++ 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/Ibator.java
 Sun Nov 30 05:49:27 2008
@@ -219,7 +219,7 @@
             String source;
             try {
                 File directory = shellCallback.getDirectory(gxf
-                        .getTargetProject(), gxf.getTargetPackage(), warnings);
+                        .getTargetProject(), gxf.getTargetPackage());
                 targetFile = new File(directory, gxf.getFileName());
                 if (targetFile.exists()) {
                     if (gxf.isMergeable()) {
@@ -247,13 +247,17 @@
             String source;
             try {
                 File directory = shellCallback.getDirectory(gjf
-                        .getTargetProject(), gjf.getTargetPackage(), warnings);
+                        .getTargetProject(), gjf.getTargetPackage());
                 targetFile = new File(directory, gjf.getFileName());
                 if (targetFile.exists()) {
-                    if (shellCallback.mergeSupported() && gjf.isMergeable()) {
-                        source = shellCallback.mergeJavaFile(gjf,
-                                MergeConstants.OLD_JAVA_ELEMENT_TAGS,
-                                warnings);
+                    if (shellCallback.isMergeSupported()) {
+                        source = 
shellCallback.mergeJavaFile(gjf.getFormattedContent(),
+                                targetFile.getAbsolutePath(),
+                                MergeConstants.OLD_JAVA_ELEMENT_TAGS);
+                    } else if (shellCallback.isOverwriteEnabled()) { 
+                        source = gjf.getFormattedContent();
+                        warnings.add(Messages.getString("Warning.11", 
//$NON-NLS-1$
+                                targetFile.getAbsolutePath()));
                     } else {
                         source = gjf.getFormattedContent();
                         targetFile = getUniqueFileName(directory, 
gjf.getFileName());

Modified: 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java
 (original)
+++ 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ProgressCallback.java
 Sun Nov 30 05:49:27 2008
@@ -24,7 +24,7 @@
  * <code>setNumberOfSubTasks</code> method first, and then repeatedly call 
<code>startSubTask</code.
  * When the long running method is complete, ibator will call 
<code>finished</code>.
  * Periodically, ibator will call <code>checkCancel</code> to see if the 
method should
- * be cancelled.
+ * be canceled.
  * 
  * @author Jeff Butler
  */
@@ -54,7 +54,7 @@
     /**
      * ibator will call this method periodically during a long running method.
      * If the the implementation throws InterruptedException, then the method
-     * will be cancelled.  Any files that have already been saved will remain 
on
+     * will be canceled.  Any files that have already been saved will remain on
      * the file system.
      * 
      * @throws InterruptedException if the main task should finish

Modified: 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ShellCallback.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ShellCallback.java?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ShellCallback.java
 (original)
+++ 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/ShellCallback.java
 Sun Nov 30 05:49:27 2008
@@ -16,7 +16,6 @@
 package org.apache.ibatis.ibator.api;
 
 import java.io.File;
-import java.util.List;
 
 import org.apache.ibatis.ibator.exception.ShellException;
 
@@ -50,14 +49,13 @@
      * 
      * @param targetProject
      * @param targetPackage
-     * @param warnings
      * @return 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. 
      */
-    File getDirectory(String targetProject, String targetPackage, List<String> 
warnings) throws ShellException;
+    File getDirectory(String targetProject, String targetPackage) throws 
ShellException;
     
     /**
      * ibator will call this method if a newly generated Java file would 
overwrite an existing
@@ -75,18 +73,15 @@
      *   <li>Add all methods and fields from the new file into the existing 
file</li>
      *   <li>Format the resulting source string</li>
      * </ol>
+     *
+     * Ibator will only call this method if you return <code>true</code>
+     * from <code>isMergeSupported()</code>.
      * 
-     * If you do not want to support merging in your shell, simply return
-     * <code>newFile.getFormattedContent()</code>.
-     * However, this will overwrite any modifications to the generated files.
-     * 
-     * @param newFile the newly generated Java file
+     * @param newFileSource the source of the newly generated Java file
+     * @param existingFileFullPath the fully qualified path name of the 
existing Java file
      * @param 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)
-     * @param warninigs Any warning strings during the merge can be added to 
this list.
-     *                  Adding a warning will not stop ibator from saving the 
resulting
-     *                  source. 
      * @return 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
@@ -94,13 +89,12 @@
      *                        the existing file will remain undisturbed.  
ibator
      *                        will add the exception message to the list of 
warnings automatically.
      */
-    String mergeJavaFile(GeneratedJavaFile newFile, String[] javadocTags, 
List<String> warninigs)
-       throws ShellException;
+    String mergeJavaFile(String newFileSource, String existingFileFullPath, 
String[] javadocTags) throws ShellException;
     
     /**
      * 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 usefull if your IDE needs to be informed that file 
system objects
+     * 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.
      * 
@@ -110,10 +104,22 @@
 
     /**
      * Return true if the callback supports Java merging, otherwise false.
-     * ibator will only call the <code>mergeJavaFile</code> method if this 
method
-     * returns true;
+     * ibator will only call the <code>mergeJavaFile()</code> method if this
+     * method returns <code>true</code>.
      * 
      * @return a boolean specifying whether Java merge is supported or not
      */
-    boolean mergeSupported();
+    boolean isMergeSupported();
+    
+    /**
+     * Return true if ibator should overwrite an existing file if one
+     * exists.  Ibator will only call this method if 
+     * <code>isMergeSupported()</code> returns <code>false</code>
+     * and a file exists that would be overwritten by a generated
+     * file.  If you return <code>true</code>, then ibator will log
+     * a warning specifying what file was overwritten.
+     * 
+     * @return true if you want ibator to overwrite existing files
+     */
+    boolean isOverwriteEnabled();
 }

Modified: 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/DefaultShellCallback.java
URL: 
http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/DefaultShellCallback.java?rev=721812&r1=721811&r2=721812&view=diff
==============================================================================
--- 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/DefaultShellCallback.java
 (original)
+++ 
ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/DefaultShellCallback.java
 Sun Nov 30 05:49:27 2008
@@ -16,10 +16,8 @@
 package org.apache.ibatis.ibator.internal;
 
 import java.io.File;
-import java.util.List;
 import java.util.StringTokenizer;
 
-import org.apache.ibatis.ibator.api.GeneratedJavaFile;
 import org.apache.ibatis.ibator.api.ShellCallback;
 import org.apache.ibatis.ibator.exception.ShellException;
 import org.apache.ibatis.ibator.internal.util.messages.Messages;
@@ -40,10 +38,9 @@
 
     /*
      *  (non-Javadoc)
-     * @see 
org.apache.ibatis.ibator.api.ShellCallback#getDirectory(java.lang.String, 
java.lang.String, java.util.List)
+     * @see 
org.apache.ibatis.ibator.api.ShellCallback#getDirectory(java.lang.String, 
java.lang.String)
      */
-    public File getDirectory(String targetProject, String targetPackage,
-            List<String> warnings) throws ShellException {
+    public File getDirectory(String targetProject, String targetPackage) 
throws ShellException {
         // targetProject is interpreted as a directory that must exist
         //
         // targetPackage is interpreted as a sub directory, but in package
@@ -77,24 +74,6 @@
 
     /*
      *  (non-Javadoc)
-     * @see 
org.apache.ibatis.ibator.api.ShellCallback#mergeJavaFile(org.apache.ibatis.ibator.api.GeneratedJavaFile,
 java.lang.String, java.util.List)
-     */
-    public String mergeJavaFile(GeneratedJavaFile newFile, String[] 
javadocTags,
-            List<String> warnings) throws ShellException {
-        if (overwrite) {
-            File directory = getDirectory(newFile.getTargetProject(), 
newFile.getTargetPackage(), warnings);
-            File file = new File(directory, newFile.getFileName());
-            warnings.add(Messages.getString("Warning.11", //$NON-NLS-1$
-                    file.getAbsolutePath()));
-            
-            return newFile.getFormattedContent();
-        } else {
-            return null;
-        }
-    }
-
-    /*
-     *  (non-Javadoc)
      * @see 
org.apache.ibatis.ibator.api.ShellCallback#refreshProject(java.lang.String)
      */
     public void refreshProject(String project) {
@@ -102,9 +81,23 @@
     }
     
     /* (non-Javadoc)
-     * @see org.apache.ibatis.ibator.api.ShellCallback#mergeSupported()
+     * @see org.apache.ibatis.ibator.api.ShellCallback#isMergeSupported()
      */
-    public boolean mergeSupported() {
+    public boolean isMergeSupported() {
+        return false;
+    }
+
+    public boolean isOverwriteEnabled() {
         return overwrite;
     }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.ibatis.ibator.api.ShellCallback#mergeJavaFile(java.lang.String, 
java.lang.String, java.lang.String[])
+     */
+    public String mergeJavaFile(String newFileSource,
+            String existingFileFullPath, String[] javadocTags)
+            throws ShellException {
+        throw new UnsupportedOperationException();
+    }
 }


Reply via email to