Anonymous avatar Anonymous committed d562d19

- avoid NPE in XworkException
- executeAndWait interceptor is smarter now (works with validation). it's still ugly, but much better
- console doesn't spit out the full URL w/ params
- some fixes left over from refactoring in quickstart

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk/src@1019 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

java/com/opensymphony/xwork/XworkException.java

         if (msg == null && getCause() != null) {
             msg = getCause().getMessage();
         }
-        
-        if (msg != null) {
-            return msg + " - " + location.toString();
+
+        if (location != null) {
+            if (msg != null) {
+                return msg + " - " + location.toString();
+            } else {
+                return location.toString();
+            }
         } else {
-            return location.toString();
+            return msg;
         }
     }
-}
+}

java/com/opensymphony/xwork/util/CompoundRootAccessor.java

 import org.apache.commons.logging.LogFactory;
 
 import java.beans.IntrospectionException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.beans.PropertyDescriptor;
+import java.util.*;
 
 
 /**
     public Object callMethod(Map context, Object target, String name, Object[] objects) throws MethodFailedException {
         CompoundRoot root = (CompoundRoot) target;
 
+        if ("describe".equals(name)) {
+            Object v;
+            if (objects != null && objects.length == 1) {
+                v = objects[0];
+            } else {
+                v = root.get(0);
+            }
+
+
+            if (v instanceof Collection || v instanceof Map || v.getClass().isArray()) {
+                return v.toString();
+            }
+
+            try {
+                Map descriptors = OgnlRuntime.getPropertyDescriptors(v.getClass());
+
+                int maxSize = 0;
+                for (Iterator iterator = descriptors.keySet().iterator(); iterator.hasNext();) {
+                    String pdName = (String) iterator.next();
+                    if (pdName.length() > maxSize) {
+                        maxSize = pdName.length();
+                    }
+                }
+
+                SortedSet set = new TreeSet();
+                StringBuffer sb = new StringBuffer();
+                for (Iterator iterator = descriptors.values().iterator(); iterator.hasNext();) {
+                    PropertyDescriptor pd = (PropertyDescriptor) iterator.next();
+
+                    sb.append(pd.getName()).append(": ");
+                    int padding = maxSize - pd.getName().length();
+                    for (int i = 0; i < padding; i++) {
+                        sb.append(" ");
+                    }
+                    sb.append(pd.getPropertyType().getName());
+                    set.add(sb.toString());
+
+                    sb = new StringBuffer();
+                }
+
+                sb = new StringBuffer();
+                for (Iterator iterator = set.iterator(); iterator.hasNext();) {
+                    String s = (String) iterator.next();
+                    sb.append(s).append("\n");
+                }
+                
+                return sb.toString();
+            } catch (IntrospectionException e) {
+                e.printStackTrace();
+            } catch (OgnlException e) {
+                e.printStackTrace();
+            }
+
+            return null;
+        }
+
         for (Iterator iterator = root.iterator(); iterator.hasNext();) {
             Object o = iterator.next();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.