From: Erik Brakkee Date: Sat, 31 Jul 2010 14:26:29 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.7~127 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=3176eb654a388bda2eefced0debd6cf698fe5092;p=utils --- diff --git a/support/general/src/main/java/org/wamblee/reflection/ObjectTraversal.java b/support/general/src/main/java/org/wamblee/reflection/ObjectTraversal.java index d5955fc3..7b63729e 100644 --- a/support/general/src/main/java/org/wamblee/reflection/ObjectTraversal.java +++ b/support/general/src/main/java/org/wamblee/reflection/ObjectTraversal.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import java.util.logging.Level; +import java.util.logging.Logger; import org.wamblee.general.ObjectElem; @@ -47,6 +49,8 @@ import org.wamblee.general.ObjectElem; * @author Erik Brakkee */ public class ObjectTraversal { + + public static final Logger LOGGER = Logger.getLogger(ObjectTraversal.class.getName()); /** * Visitor interface to be implemented for object traversal. @@ -128,6 +132,7 @@ public class ObjectTraversal { boolean visitArray(Object aArray); } + private int level; private ObjectVisitor visitor; private List excluded; @@ -138,6 +143,7 @@ public class ObjectTraversal { * Visitor to use. */ public ObjectTraversal(ObjectVisitor aVisitor) { + level = 0; visitor = aVisitor; excluded = new ArrayList(); } @@ -151,6 +157,14 @@ public class ObjectTraversal { public void addExcludedObject(Object aObject) { excluded.add(new ObjectElem(aObject)); } + + private String indent() { + StringBuffer buf = new StringBuffer(); + for (int i = 1; i < level; i++) { + buf.append(" "); + } + return buf.toString(); + } public void accept(Object aObject) { if (aObject == null) { @@ -169,6 +183,10 @@ public class ObjectTraversal { if (alreadyProcessed(aObject)) { return; } + if ( LOGGER.isLoggable(Level.FINEST)) { + level++; + LOGGER.finest(indent() + "obj: " + aObject); + } if (aObject instanceof List) { if (visitor.visitList((List) aObject)) { @@ -207,6 +225,9 @@ public class ObjectTraversal { getter.getReturnType() != Void.class) { if (visitor.mustVisit(getter)) { + if ( LOGGER.isLoggable(Level.FINEST)) { + LOGGER.finest(indent() + "method: " + getter.getName()); + } acceptMethod(aObject, getter); } } @@ -219,6 +240,9 @@ public class ObjectTraversal { if (!Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) { field.setAccessible(true); if (visitor.mustVisit(field)) { + if ( LOGGER.isLoggable(Level.FINEST)) { + LOGGER.finest(indent() + "field: " + field.getName()); + } acceptField(aObject, field); } } diff --git a/support/general/src/test/java/org/wamblee/reflection/ObjectTraversalTest.java b/support/general/src/test/java/org/wamblee/reflection/ObjectTraversalTest.java index 8e00ca5a..a97c91f3 100644 --- a/support/general/src/test/java/org/wamblee/reflection/ObjectTraversalTest.java +++ b/support/general/src/test/java/org/wamblee/reflection/ObjectTraversalTest.java @@ -26,6 +26,9 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; import org.apache.derby.impl.sql.execute.OnceResultSet; import org.junit.Before; @@ -58,6 +61,10 @@ public class ObjectTraversalTest { when(visitor.visitMap(any(Map.class))).thenReturn(true); when(visitor.visitSet(any(Set.class))).thenReturn(true); + ObjectTraversal.LOGGER.setLevel(Level.FINEST); + ConsoleHandler handler = new ConsoleHandler(); + handler.setLevel(Level.FINEST); + ObjectTraversal.LOGGER.addHandler(handler); } public static class X1 {