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;
* @author Erik Brakkee
*/
public class ObjectTraversal {
+
+ public static final Logger LOGGER = Logger.getLogger(ObjectTraversal.class.getName());
/**
* Visitor interface to be implemented for object traversal.
boolean visitArray(Object aArray);
}
+ private int level;
private ObjectVisitor visitor;
private List<ObjectElem> excluded;
* Visitor to use.
*/
public ObjectTraversal(ObjectVisitor aVisitor) {
+ level = 0;
visitor = aVisitor;
excluded = new ArrayList<ObjectElem>();
}
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) {
if (alreadyProcessed(aObject)) {
return;
}
+ if ( LOGGER.isLoggable(Level.FINEST)) {
+ level++;
+ LOGGER.finest(indent() + "obj: " + aObject);
+ }
if (aObject instanceof List) {
if (visitor.visitList((List) aObject)) {
getter.getReturnType() != Void.class) {
if (visitor.mustVisit(getter)) {
+ if ( LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest(indent() + "method: " + getter.getName());
+ }
acceptMethod(aObject, getter);
}
}
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);
}
}
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;
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 {