import edu.neu.ccs.demeter.dj.*; import java.util.*; class tvisitor extends Visitor { // holds the path of traversed objects. private Hashtable path=new Hashtable(); // holds the number of time an object exists in the path. private Hashtable objCount=new Hashtable(); // return the hashtable that holds the path of the traversed objects. public Hashtable getObjPath() { return path; } public Object getLastObj(String className) { Integer iVal; if((iVal=(Integer)objCount.get(className)) == null) return null; else return path.get(new String(className+iVal.intValue())); } public int getNumObj(String className) { Integer iVal; if((iVal=(Integer)objCount.get(className)) == null) return 0; else return iVal.intValue(); } public Hashtable getObjCountSet() { return objCount; } public void before(Object obj, Class cl) { // to do: put the object in the path hashtable // update the objectCount Hashtable Integer iVal; int i; String className=cl.getName(); if((iVal=(Integer)objCount.get(className)) == null) i=1; else i=iVal.intValue()+1; //System.out.println("inserting to objCount: "+i); objCount.put(className,new Integer(i)); String newObjType=className+i; System.out.println("inserting to path: "+newObjType); path.put(newObjType,obj); // should this line be after inserting the object to the hashtable? invokeMethod("before", obj, cl); } public void after(Object obj, Class cl) { // to do: take out the object from the path hashtable // update the objectCount Hashtable int i; String className=cl.getName(); if((i=((Integer)objCount.get(className)).intValue())==1) objCount.remove(className); else objCount.put(className,new Integer(i--)); System.out.println("Removing from path: "+className); path.remove(new String(className+i)); // should this line be before taking out the obkects from the hash? invokeMethod("after", obj, cl); } public String toString(){ //System.out.println("test: "+this.getClass().getName()); return super.toString() + " MyVisitor"; } }