Fixing BaseDumpDirective so it does not attempt do dump methods defined in the java.lang and sun packages

This commit is contained in:
briancaruso 2011-11-17 00:08:37 +00:00
parent 02023bb2e1
commit 012c5dc43b
2 changed files with 27 additions and 6 deletions

View file

@ -44,7 +44,8 @@ public class UrlBuilder {
VISUALIZATION("/visualization"), VISUALIZATION("/visualization"),
VISUALIZATION_SHORT("/vis"), VISUALIZATION_SHORT("/vis"),
VISUALIZATION_AJAX("/visualizationAjax"), VISUALIZATION_AJAX("/visualizationAjax"),
VISUALIZATION_DATA("/visualizationData"); VISUALIZATION_DATA("/visualizationData"),
EDIT_REQUEST_DISPATCH("/editRequestDispatch");
private final String path; private final String path;

View file

@ -344,10 +344,12 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
} }
private Map<String, Object> getObjectDump(TemplateHashModelEx model, Object object) throws TemplateModelException { private Map<String, Object> getObjectDump(TemplateHashModelEx model, Object object) throws TemplateModelException {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put(Key.TYPE.toString(), object.getClass().getName()); map.put(Key.TYPE.toString(), object.getClass().getName());
if( object instanceof java.lang.reflect.Method)
return map;
// Compile the collections of properties and methods available to the template // Compile the collections of properties and methods available to the template
SortedMap<String, Object> properties = new TreeMap<String, Object>(); SortedMap<String, Object> properties = new TreeMap<String, Object>();
SortedMap<String, Object> methods = new TreeMap<String, Object>(); SortedMap<String, Object> methods = new TreeMap<String, Object>();
@ -376,11 +378,25 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
// like name/getName - we'll keep only the first form. // like name/getName - we'll keep only the first form.
for ( Method method : classMethods ) { for ( Method method : classMethods ) {
if( "declaringClass".equals( method.getName() ))
continue;
// Eliminate methods declared on Object // Eliminate methods declared on Object
Class<?> c = method.getDeclaringClass(); Class<?> c = method.getDeclaringClass();
if (c.equals(java.lang.Object.class)) {
if (c.equals(java.lang.Object.class) ||
c.equals(java.lang.reflect.Constructor.class) ||
c.equals(java.lang.reflect.Field.class ) )
continue; continue;
}
if(
c.getPackage().getName().startsWith("sun.") ||
c.getPackage().getName().startsWith("java.lang") ||
c.getPackage().getName().startsWith("java.security") )
continue;
log.error("decalring class of method " + method.getName() + " is " + c.getName());
// Eliminate deprecated methods // Eliminate deprecated methods
if (method.isAnnotationPresent(Deprecated.class)) { if (method.isAnnotationPresent(Deprecated.class)) {
@ -399,8 +415,12 @@ public abstract class BaseDumpDirective implements TemplateDirectiveModel {
// The method is available as a property // The method is available as a property
if (keySet.contains(propertyName)) { if (keySet.contains(propertyName)) {
try{
TemplateModel value = model.get(propertyName); TemplateModel value = model.get(propertyName);
properties.put(propertyName, getDump(value)); properties.put(propertyName, getDump(value));
}catch(Throwable th){
log.error("problem dumping " + propertyName + " on " + object.getClass().getName(), th);
}
continue; continue;
} }
} }