openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1063823 - in /openjpa/trunk/openjpa-lib/src/main: java/org/apache/openjpa/lib/util/Options.java resources/org/apache/openjpa/lib/util/localizer.properties
Date Wed, 26 Jan 2011 18:43:07 GMT
Author: ppoddar
Date: Wed Jan 26 18:43:06 2011
New Revision: 1063823

URL: http://svn.apache.org/viewvc?rev=1063823&view=rev
Log:
Add exception message for configuration error

Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
    openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/util/localizer.properties

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java?rev=1063823&r1=1063822&r2=1063823&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java (original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java Wed Jan
26 18:43:06 2011
@@ -33,6 +33,7 @@ import java.util.Properties;
 import java.util.TreeSet;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.util.UserException;
 
 import serp.util.Strings;
 
@@ -69,6 +70,8 @@ public class Options extends TypedProper
         { int.class, Integer.class, Integer.valueOf(0) },
         { long.class, Long.class, Long.valueOf(0L) },
         { short.class, Short.class, Short.valueOf((short) 0) }, };
+    
+    private static Localizer _loc = Localizer.forPackage(Options.class);
 
     /**
      * Default constructor.
@@ -105,7 +108,7 @@ public class Options extends TypedProper
 
         String key = null;
         String value = null;
-        List remainder = new LinkedList();
+        List<String> remainder = new LinkedList<String>();
         for (int i = 0; i < args.length + 1; i++) {
             if (i == args.length || args[i].startsWith("-")) {
                 key = trimQuote(key);
@@ -129,7 +132,7 @@ public class Options extends TypedProper
                 remainder.add(args[i]);
         }
 
-        return (String[]) remainder.toArray(new String[remainder.size()]);
+        return remainder.toArray(new String[remainder.size()]);
     }
 
     /**
@@ -175,8 +178,7 @@ public class Options extends TypedProper
         // set all defaults that have no explicit value
         Map.Entry entry = null;
         if (defaults != null) {
-            for (Iterator itr = defaults.entrySet().iterator(); itr.hasNext();)
-            {
+            for (Iterator itr = defaults.entrySet().iterator(); itr.hasNext();) {
                 entry = (Map.Entry) itr.next();
                 if (!containsKey(entry.getKey()))
                     setInto(obj, entry);
@@ -235,8 +237,7 @@ public class Options extends TypedProper
             invoke(match[0], match[1], values);
             return true;
         } catch (Throwable t) {
-            throw new ParseException(obj + "." + entry.getKey()
-                + " = " + entry.getValue(), t);
+            throw new ParseException(obj + "." + entry.getKey() + " = " + entry.getValue(),
t);
         }
     }
 
@@ -302,7 +303,7 @@ public class Options extends TypedProper
             return false;
 
         // unfortunately we can't use bean properties for setters; any
-        // setter with more than 1 arg is ignored; calc setter and getter
+        // setter with more than 1 argument is ignored; calculate setter and getter
         // name to look for
         String[] find = Strings.split(key, ".", 2);
         String base = StringUtils.capitalize(find[0]);
@@ -410,7 +411,7 @@ public class Options extends TypedProper
      * Converts the given string into an object of the given type, or its
      * wrapper type if it is primitive.
      */
-    private Object stringToObject(String str, Class type) throws Exception {
+    private Object stringToObject(String str, Class<?> type) throws Exception {
         // special case for null and for strings
         if (str == null || type == String.class)
             return str;
@@ -429,27 +430,27 @@ public class Options extends TypedProper
         if (type.isPrimitive())
             for (int i = 0; i < _primWrappers.length; i++)
                 if (type == _primWrappers[i][0])
-                    return stringToObject(str, (Class) _primWrappers[i][1]);
+                    return stringToObject(str, (Class<?>) _primWrappers[i][1]);
 
         // look for a string constructor
         Exception err = null;
         try {
-            Constructor cons = type.getConstructor
-                (new Class[]{ String.class });
+            Constructor<?> cons = type.getConstructor(new Class[]{ String.class });
             if (type == Boolean.class && "t".equalsIgnoreCase(str))
                 str = "true";
             return cons.newInstance(new Object[]{ str });
         } catch (Exception e) {
-            err = e;
+            err = new UserException(_loc.get("conf-no-constructor", str, type), e);
         }
 
-        // special case: the arg value is a subtype name and a new instance
+        // special case: the argument value is a subtype name and a new instance
         // of that type should be set as the object
-        Class subType = null;
+        Class<?> subType = null;
         try {
             subType = Class.forName(str);
         } catch (Exception e) {
-            throw err;
+            err = e;
+            throw new UserException(_loc.get("conf-no-type", str, type), e);
         }
         if (!type.isAssignableFrom(subType))
             throw err;

Modified: openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/util/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/util/localizer.properties?rev=1063823&r1=1063822&r2=1063823&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/util/localizer.properties
(original)
+++ openjpa/trunk/openjpa-lib/src/main/resources/org/apache/openjpa/lib/util/localizer.properties
Wed Jan 26 18:43:06 2011
@@ -19,3 +19,8 @@ dup-key: Duplicate keys are not allowed 
 	first value: {1}, second value: {2}.
 concurrent-initial: Illegal initial value of {0} specified.
 concurrent-load: Illegal load value of {0} specified.
+conf-no-constructor: Error initializing configuration. Failed to create an instance \
+	of {1} with a single string argument of "{0}". Make sure that {1} has a public \
+	constructor with a String argument.
+conf-no-type: Error initializing configuration. Failed to create an instance of {1} \
+	for plugin property {0}.	



Mime
View raw message