[Swift-commit] r6016 - trunk/src/org/griphyn/vdl/mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Fri Nov 9 23:23:08 CST 2012
Author: hategan
Date: 2012-11-09 23:23:08 -0600 (Fri, 09 Nov 2012)
New Revision: 6016
Modified:
trunk/src/org/griphyn/vdl/mapping/InvalidPathException.java
Log:
"Invalid path" is not very good wording. Changed exception to be specific. If an array index is invalid, then say so. If a struct field is invalid, then say so
Modified: trunk/src/org/griphyn/vdl/mapping/InvalidPathException.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/InvalidPathException.java 2012-11-10 05:21:45 UTC (rev 6015)
+++ trunk/src/org/griphyn/vdl/mapping/InvalidPathException.java 2012-11-10 05:23:08 UTC (rev 6016)
@@ -20,16 +20,45 @@
*/
package org.griphyn.vdl.mapping;
+
public class InvalidPathException extends Exception {
public InvalidPathException(String path, DSHandle source) {
- super("Invalid path (" + path + ") for "
- + source.toString());
+ super(getMessage(path, source));
}
- public InvalidPathException(Path path, DSHandle source) {
+ private static String getMessage(String path, DSHandle source) {
+ if (source.getType().isArray()) {
+ return "Array index '" + path + "' not found for " + getName(source) + " of size " + getSize(source);
+ }
+ else if (source.getType().isComposite()) {
+ return "Invalid field name '" + path + "' for " + getName(source) + " of type " + source.getType();
+ }
+ else {
+ return "Invalid path (" + path + ") for " + source.toString();
+ }
+ }
+
+ private static int getSize(DSHandle source) {
+ return source.getArrayValue().size();
+ }
+
+ private static String getName(DSHandle source) {
+ if (source instanceof AbstractDataNode) {
+ return ((AbstractDataNode) source).getDisplayableName();
+ }
+ else {
+ return source.toString();
+ }
+ }
+
+ public InvalidPathException(Path path, DSHandle source) {
this(path.toString(), source);
}
-
+
+ public InvalidPathException(Object path, DSHandle source) {
+ this(path.toString(), source);
+ }
+
public InvalidPathException(String string) {
super(string);
}
More information about the Swift-commit
mailing list