You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by aw...@apache.org on 2006/08/09 22:59:45 UTC

svn commit: r430146 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java

Author: awhite
Date: Wed Aug  9 13:59:45 2006
New Revision: 430146

URL: http://svn.apache.org/viewvc?rev=430146&view=rev
Log:
Make Localizer.Message a static class.  Fix implicit type of query path 
traversal terminating in byte[], char[] fields.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=430146&r1=430145&r2=430146&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java Wed Aug  9 13:59:45 2006
@@ -306,11 +306,17 @@
 
         if (fld != null) {
             switch (fld.getDeclaredTypeCode()) {
+                case JavaTypes.ARRAY:
+                    if (fld.getDeclaredType() == byte[].class
+                        || fld.getDeclaredType() == Byte[].class
+                        || fld.getDeclaredType() == char[].class
+                        || fld.getDeclaredType() == Character[].class)
+                        return fld.getDeclaredType();
+                    return fld.getElement().getDeclaredType();
                 case JavaTypes.MAP:
                     if (key)
                         return fld.getKey().getDeclaredType();
-                    // no break
-                case JavaTypes.ARRAY:
+                    return fld.getElement().getDeclaredType();
                 case JavaTypes.COLLECTION:
                     return fld.getElement().getDeclaredType();
                 default:

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java?rev=430146&r1=430145&r2=430146&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java Wed Aug  9 13:59:45 2006
@@ -207,7 +207,7 @@
      * @see #get(String)
      */
     public Message get(String key, Object[] subs) {
-        return new Message(key, subs, false);
+        return new Message(_package, _bundle, key, subs, false);
     }
 
     /**
@@ -219,7 +219,7 @@
      * @see #getFatal(String)
      */
     public Message getFatal(String key, Object[] subs) {
-        return new Message(key, subs, true);
+        return new Message(_package, _bundle, key, subs, true);
     }
 
     /**
@@ -227,34 +227,35 @@
      * {@link #getMessage} method call, and can also provide the original key,
      * package, and substitution array that were used to assemble the message.
      */
-    public class Message {
+    public static class Message {
 
-        private final String key;
-        private final Object[] subs;
-        private String localizedMessage;
-        private boolean messageFound = false;
-
-        private Message(String key, Object[] subs, boolean fatal) {
-            this.key = key;
-            this.subs = subs;
-
-            if (_bundle == null) {
-                if (fatal)
-                    throw new MissingResourceException(key, key, key);
-                else {
-                    localizedMessage = key;
-                    messageFound = false;
-                }
+        private final Package _package;
+        private final String _key;
+        private final Object[] _subs;
+        private final String _localizedMessage;
+        private final boolean _messageFound;
+
+        private Message(Package pkg, ResourceBundle bundle, String key, 
+            Object[] subs, boolean fatal) {
+            if (bundle == null && fatal)
+                throw new MissingResourceException(key, key, key);
+
+            _package = pkg;
+            _key = key;
+            _subs = subs;
+            if (bundle == null) {
+                _localizedMessage = key;
+                _messageFound = false;
             } else {
+                String localized = null;
                 try {
-                    localizedMessage = _bundle.getString(key);
-                    messageFound = true;
+                    localized = bundle.getString(key);
                 } catch (MissingResourceException mre) {
-                    if (!fatal)
-                        localizedMessage = key;
-                    else
+                    if (fatal)
                         throw mre;
                 }
+                _localizedMessage = (localized == null) ? key : localized;
+                _messageFound = localized != null;
             }
         }
 
@@ -262,20 +263,26 @@
          * The localized message.
          */
         public String getMessage() {
-            if (messageFound)
-                return MessageFormat.format(localizedMessage, subs);
-            else
-                return key;
+            return MessageFormat.format(_localizedMessage, _subs);
         }
 
+        /**
+         * The unique key for the localized message.
+         */
         public String getKey() {
-            return key;
+            return _key;
         }
 
+        /**
+         * Substitutions inserted into the message.
+         */
         public Object[] getSubstitutions() {
-            return subs;
+            return _subs;
         }
 
+        /**
+         * Package containing localized resource for this message.
+         */
         public Package getPackage() {
             return _package;
         }