X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Freflection%2FObjectTraversal.java;h=ded641fefe79c9b4f43915cba671ff6944b0ff8f;hb=000f82cd33c37ef7d16b4d3f6d01eb78519991e3;hp=d5955fc34d1c71b11cda7460a42eb147efe0bb9e;hpb=c40599263bad4b81597fc6be3733275e6361e4ce;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..ded641fe 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;
@@ -40,7 +42,7 @@ import org.wamblee.general.ObjectElem;
*
*
* - All fields and methods of the {@link Object} class.
- * - All fields and methods of collecation classes (List, Map, Set), and of
+ *
- All fields and methods of collection classes (List, Map, Set), and of
* arrays.
*
*
@@ -48,6 +50,9 @@ import org.wamblee.general.ObjectElem;
*/
public class ObjectTraversal {
+ public static final Logger LOGGER = Logger.getLogger(ObjectTraversal.class
+ .getName());
+
/**
* Visitor interface to be implemented for object traversal.
*
@@ -128,6 +133,7 @@ public class ObjectTraversal {
boolean visitArray(Object aArray);
}
+ private int level;
private ObjectVisitor visitor;
private List excluded;
@@ -138,6 +144,7 @@ public class ObjectTraversal {
* Visitor to use.
*/
public ObjectTraversal(ObjectVisitor aVisitor) {
+ level = 0;
visitor = aVisitor;
excluded = new ArrayList();
}
@@ -152,6 +159,14 @@ public class ObjectTraversal {
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) {
return;
@@ -169,6 +184,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 +226,10 @@ 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 +242,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);
}
}
@@ -251,18 +277,18 @@ public class ObjectTraversal {
}
}
- private void acceptPlainOrCollection(Object value) {
- if (value instanceof Set) {
- visitor.visitSet((Set) value);
- processSet((Set) value);
- } else if (value instanceof List) {
- processList((List) value);
- } else if (value instanceof Map) {
- processMap((Map, ?>) value);
- } else if (value.getClass().isArray()) {
- processArray(value);
+ private void acceptPlainOrCollection(Object aValue) {
+ if (aValue instanceof Set) {
+ visitor.visitSet((Set) aValue);
+ processSet((Set) aValue);
+ } else if (aValue instanceof List) {
+ processList((List) aValue);
+ } else if (aValue instanceof Map) {
+ processMap((Map, ?>) aValue);
+ } else if (aValue.getClass().isArray()) {
+ processArray(aValue);
} else {
- accept(value);
+ accept(aValue);
}
}