You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by cs...@apache.org on 2005/11/28 21:57:12 UTC

svn commit: r349503 - in /beehive/trunk/system-controls: src/jdbc/ src/jdbc/org/apache/beehive/controls/system/jdbc/ src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ test/src/jdbc/controls/

Author: cschoett
Date: Mon Nov 28 12:57:04 2005
New Revision: 349503

URL: http://svn.apache.org/viewcvs?rev=349503&view=rev
Log:
Fix for BEEHIVE-966, removed all hardcoded strings from jdbc control's checker and placed them in property files.  Also some minor build file cleanup.

Added:
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties   (with props)
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties   (with props)
Modified:
    beehive/trunk/system-controls/src/jdbc/build.xml
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlChecker.java
    beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java
    beehive/trunk/system-controls/test/src/jdbc/controls/build.xml

Modified: beehive/trunk/system-controls/src/jdbc/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/build.xml?rev=349503&r1=349502&r2=349503&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/build.xml (original)
+++ beehive/trunk/system-controls/src/jdbc/build.xml Mon Nov 28 12:57:04 2005
@@ -36,8 +36,13 @@
 
         <build-controls srcdir="${module.dir}" 
                         destdir="${classes.dir}/${module.name}"
-                        tempdir="${gen.src.dir}/${module.name}" 
+                        tempdir="${gen.src.dir}/${module.name}"
                         classpathref="module.classpath"/>
+
+        <!-- Copy property files into the build -->
+        <copy todir="${classes.dir}/${module.name}" overwrite="true">
+            <fileset dir="${module.dir}" includes="**/*.properties"/>
+        </copy>
 
         <control-jar destfile="${build.lib.dir}/${jdbccontrol.jar.name}" basedir="${classes.dir}/${module.name}">
           <manifest>

Modified: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlChecker.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlChecker.java?rev=349503&r1=349502&r2=349503&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlChecker.java (original)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/JdbcControlChecker.java Mon Nov 28 12:57:04 2005
@@ -37,13 +37,17 @@
 import org.apache.beehive.controls.system.jdbc.parser.SqlStatement;
 
 import java.util.Collection;
-import java.sql.SQLException;
+import java.util.ResourceBundle;
+import java.util.Locale;
+import java.text.MessageFormat;
 
 /**
  * Annotation checker for the JdbcControl.  Invoked at compile time by the controls framework.
  */
 public class JdbcControlChecker implements ControlChecker {
 
+    private Locale _locale;
+
     /**
      * Invoked by the control build-time infrastructure to process a declaration of
      * a control extension (ie, an interface annotated with @ControlExtension), or
@@ -51,14 +55,9 @@
      */
     public void check(Declaration decl, AnnotationProcessorEnvironment env) {
 
-        if (decl instanceof TypeDeclaration) {
+        _locale = Locale.getDefault();
 
-            //
-            // Check class annotations
-            //
-            checkConnectionDataSource((TypeDeclaration) decl, env);
-            checkConnectionDriver((TypeDeclaration) decl, env);
-            checkConnectionOptions((TypeDeclaration) decl, env);
+        if (decl instanceof TypeDeclaration) {
 
             //
             // Check method annotations
@@ -82,62 +81,10 @@
     }
 
     /**
-     * Check the ConnectionDataSource annotation.
-     *
-     * @param decl
-     * @param env
-     */
-    private void checkConnectionDataSource(TypeDeclaration decl, AnnotationProcessorEnvironment env) {
-        final JdbcControl.ConnectionDataSource cds =
-                decl.getAnnotation(JdbcControl.ConnectionDataSource.class);
-        if (cds == null) {
-            return;
-        }
-
-        //
-        // NOOP
-        //
-    }
-
-    /**
-     * Check the ConnectionDriver annotation.
-     *
-     * @param decl
-     * @param env
-     */
-    private void checkConnectionDriver(TypeDeclaration decl, AnnotationProcessorEnvironment env) {
-        final JdbcControl.ConnectionDriver cd = decl.getAnnotation(JdbcControl.ConnectionDriver.class);
-        if (cd == null) {
-            return;
-        }
-
-        //
-        // NOOP
-        //
-    }
-
-    /**
-     * Check the ConnectionOptions annotation.
-     *
-     * @param decl
-     * @param env
-     */
-    private void checkConnectionOptions(TypeDeclaration decl, AnnotationProcessorEnvironment env) {
-        final JdbcControl.ConnectionOptions co = decl.getAnnotation(JdbcControl.ConnectionOptions.class);
-        if (co == null) {
-            return;
-        }
-
-        //
-        // NOOP
-        //
-    }
-
-    /**
      * Check the SQL method annotation.  Lots to check here, stop checking as soon as an error is found.
      *
-     * @param method
-     * @param env
+     * @param method Method to check.
+     * @param env Processor env.
      */
     private void checkSQL(MethodDeclaration method, AnnotationProcessorEnvironment env) {
 
@@ -150,8 +97,8 @@
         // check for empty SQL statement member
         //
         if (methodSQL.statement() == null || methodSQL.statement().length() == 0) {
-            env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                               + " contains an empty statement member.");
+            env.getMessager().printError(method.getPosition(),
+                                         getResourceString("jdbccontrol.empty.statement", method.getSimpleName()));
             return;
         }
 
@@ -160,8 +107,8 @@
         //
         int maxRows = methodSQL.maxRows();
         if (maxRows < JdbcControl.MAXROWS_ALL) {
-            env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                               + " maxRows set to invalid value: " + maxRows);
+            env.getMessager().printError(method.getPosition(),
+                                         getResourceString("jdbccontrol.bad.maxrows", method.getSimpleName(),maxRows));
             return;
         }
 
@@ -170,24 +117,24 @@
         //
         int arrayMax = methodSQL.arrayMaxLength();
         if (arrayMax < 1) {
-            env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                               + " arrayMaxLength set to invalid value (must be greater than 0): "
-                                                               + arrayMax);
+            env.getMessager().printError(method.getPosition(), getResourceString("jdbccontrol.bad.arraymaxlength",
+                                                                                 method.getSimpleName(), arrayMax));
             return;
         }
 
-
         //
         //
         // parse the SQL
         //
         //
         SqlParser _p = new SqlParser();
-        SqlStatement _statement = null;
+        SqlStatement _statement;
         try {
             _statement = _p.parse(methodSQL.statement());
         } catch (ControlException ce) {
-            env.getMessager().printError(method.getPosition(), "Error parsing SQL statment on method: " + method.getSimpleName() + ": " + ce.toString());
+            env.getMessager().printError(method.getPosition(),  getResourceString("jdbccontrol.bad.parse",
+                                                                                  method.getSimpleName(),
+                                                                                  ce.toString()));
             return;
         }
 
@@ -210,17 +157,18 @@
         final boolean getGeneratedKeys = methodSQL.getGeneratedKeys();
         final String[] generatedKeyColumnNames = methodSQL.generatedKeyColumnNames();
         final int[] generatedKeyIndexes = methodSQL.generatedKeyColumnIndexes();
-        if (getGeneratedKeys == false && (generatedKeyColumnNames.length != 0 || generatedKeyIndexes.length != 0)) {
-            env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                               + " getGeneratedKeys must be set to true in order to specify generatedKeyColumnNames or generatedKeyColumnIndexes.");
+        if (!getGeneratedKeys && (generatedKeyColumnNames.length != 0 || generatedKeyIndexes.length != 0)) {
+            env.getMessager().printError(method.getPosition(),
+                                         getResourceString("jdbccontrol.genkeys", method.getSimpleName()));
             return;
         }
 
         //
         // check that both generatedKeyColumnNames and generatedKeyColumnIndexes are not set
+        //
         if (generatedKeyColumnNames.length > 0 && generatedKeyIndexes.length > 0) {
-            env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                               + " only one of generatedKeyColumnNames or generatedKeyColumnIndexes may be set in the method annotation.");
+            env.getMessager().printError(method.getPosition(),
+                                         getResourceString("jdbccontrol.genkeycolumns", method.getSimpleName()));
 
             return;
         }
@@ -231,17 +179,17 @@
         final boolean batchUpdate = methodSQL.batchUpdate();
         final TypeMirror returnType = method.getReturnType();
         if (batchUpdate) {
-            if (returnType instanceof ArrayType == true) {
+            if (returnType instanceof ArrayType) {
                 final TypeMirror aType = ((ArrayType) returnType).getComponentType();
-                if (aType instanceof PrimitiveType == false || ((PrimitiveType) aType).getKind() != PrimitiveType.Kind.INT) {
-                    env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                                       + " if batchUpdate is set to true, method must return void or an array of integers.");
+                if (aType instanceof PrimitiveType == false
+                        || ((PrimitiveType) aType).getKind() != PrimitiveType.Kind.INT) {
+                    env.getMessager().printError(method.getPosition(),
+                                                 getResourceString("jdbccontrol.batchupdate", method.getSimpleName()));
                     return;
                 }
             } else if (returnType instanceof VoidType == false) {
-                env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                                   + " if batchUpdate is set to true, method must return void or an array of integers.");
-
+                env.getMessager().printError(method.getPosition(),
+                                             getResourceString("jdbccontrol.batchupdate", method.getSimpleName()));
                 return;
             }
 
@@ -262,10 +210,10 @@
                 }
 
                 if ("org.apache.beehive.controls.system.jdbc.JdbcControl.UndefinedIteratorType".equals(iteratorClassName)) {
-                    env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                                       + " iteratorElementType must be specified if method returns an Iterator.");
+                    env.getMessager().printError(method.getPosition(),
+                                                 getResourceString("jdbccontrol.iterator.returntype",
+                                                                   method.getSimpleName()));
                     return;
-
                 }
             }
         }
@@ -285,14 +233,24 @@
                     typeName = ((DeclaredType) returnType).getDeclaration().getQualifiedName();
                 }
 
-                if (typeName == null || "java.sql.ResultSet".equals(typeName) == false) {
-                    env.getMessager().printError(method.getPosition(), "@SQL annotation on method: " + method.getSimpleName()
-                                                                       + " element scrollableResultSet specified but method does not return a ResultSet.");
-                    break;
+                if (typeName == null || !"java.sql.ResultSet".equals(typeName)) {
+                    env.getMessager().printError(method.getPosition(),
+                                                 getResourceString("jdbccontrol.scrollresultset",
+                                                                   method.getSimpleName()));
+                    return;
                 }
             case FORWARD_ONLY:
             default:
                 break;
         }
+
+        return;
     } // checkSQL
+
+    private String getResourceString( String id, Object... args )
+    {
+        ResourceBundle rb = ResourceBundle.getBundle(this.getClass().getPackage().getName() + ".strings", _locale );
+        String pattern = rb.getString(id);
+        return MessageFormat.format(pattern, args);
+    }
 }

Modified: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java?rev=349503&r1=349502&r2=349503&view=diff
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java (original)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/ParameterChecker.java Mon Nov 28 12:57:04 2005
@@ -30,6 +30,9 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.ResourceBundle;
+import java.util.Locale;
+import java.text.MessageFormat;
 
 /**
  * Does compile-time checking of reflection parameteres in the SQL annotations's statement
@@ -177,20 +180,16 @@
     }
 
     /**
-     * build the error message for this module.
+     * Build the error message for this module.
      * 
      * @param parameterName
      * @param methodName
-     * @return
+     * @return The generated messge.
      */
     private static String buildMessage(String parameterName, String methodName) {
-        StringBuilder message = new StringBuilder();
-        message.append("Unable to map the parameter in SQL statement ");
-        message.append(parameterName);
-        message.append(" to a parameter of the method ");
-        message.append(methodName);
-        message.append(". Mapping is accomplished by matching a method parameter name to ");
-        message.append("a value delimited by '{' and '}' in the statement element.");
-        return message.toString();
+
+        ResourceBundle rb = ResourceBundle.getBundle("org.apache.beehive.controls.system.jdbc.parser.strings", Locale.getDefault() );
+        String pattern = rb.getString("jdbccontrol.invalid.param");
+        return MessageFormat.format(pattern, parameterName, methodName);
     }
 }

Added: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties?rev=349503&view=auto
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties (added)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties Mon Nov 28 12:57:04 2005
@@ -0,0 +1,5 @@
+
+jdbccontrol.invalid.param=\
+  Unable to map the parameter in SQL statement {0} to a parameter of the method \
+  {1}. Mapping is accomplished by matching a method parameter name to \
+   a value delimited by '{' and '}' in the statement element.

Propchange: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/parser/strings.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties?rev=349503&view=auto
==============================================================================
--- beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties (added)
+++ beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties Mon Nov 28 12:57:04 2005
@@ -0,0 +1,29 @@
+
+jdbccontrol.bad.arraymaxlength=\
+  SQL annotation on method: {0} : arrayMaxLength set to invalid value (must be greater than 0): {1}
+
+jdbccontrol.empty.statement=\
+  SQL annotation on method: {0} : Contains an empty statement member.
+
+jdbccontrol.bad.maxrows=\
+  SQL annotation on method: {0} : maxRows set to invalid value: {1}
+
+jdbccontrol.bad.parse=\
+  Error parsing SQL statment on method: {0} : {1}
+
+jdbccontrol.genkeys=\
+  SQL annotation on method: {0} : getGeneratedKeys must be set to \
+  true in order to specify generatedKeyColumnNames or generatedKeyColumnIndexes.
+
+jdbccontrol.genkeycolumns=\
+  SQL annotation on method: {0} : Only one of generatedKeyColumnNames or \
+  generatedKeyColumnIndexes may be set in the method annotation.
+
+jdbccontrol.batchupdate=\
+  SQL annotation on method: {0} : If batchUpdate is set to true, method must return void or an array of integers.
+
+jdbccontrol.iterator.returntype=\
+  SQL annotation on method: {0} : iteratorElementType must be specified if method returns an Iterator.
+
+jdbccontrol.scollresultset=\
+  SQL annotation on method: {0} : Element scrollableResultSet specified but method does not return a ResultSet.

Propchange: beehive/trunk/system-controls/src/jdbc/org/apache/beehive/controls/system/jdbc/strings.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/system-controls/test/src/jdbc/controls/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/system-controls/test/src/jdbc/controls/build.xml?rev=349503&r1=349502&r2=349503&view=diff
==============================================================================
--- beehive/trunk/system-controls/test/src/jdbc/controls/build.xml (original)
+++ beehive/trunk/system-controls/test/src/jdbc/controls/build.xml Mon Nov 28 12:57:04 2005
@@ -43,15 +43,10 @@
 
         <echo message="** Phase One **"/>
 
-        <apt srcdir="${module.dir}"
-            gendir="${module.gensrc.dir}"
-            destdir="${module.classes.dir}"
-            classpathref="testcontrols.classpath"
-            compileByExtension="true"
-            debug="${compiler.debug}"
-            nowarn="${compiler.nowarn}"
-            srcExtensions="*.jcx,*.jcs,*.java">
-        </apt>
+        <build-controls srcdir="${module.dir}"
+                        destdir="${module.classes.dir}"
+                        tempdir="${module.gensrc.dir}"
+                        classpathref="testcontrols.classpath"/>
 
         <control-jar destfile="${module.jar}" basedir="${module.classes.dir}"/>
     </target>