1 18 19 package org.objectweb.kilim.model.mapping; 20 21 import java.util.Stack ; 22 23 import org.objectweb.kilim.KilimException; 24 import org.objectweb.kilim.tools.KilimTraceTreeModel; 25 26 29 public class TreeModelMapper implements Mapper { 30 31 public static final int SOURCE = 0; 32 33 public static final int ACTION = 1; 34 35 private Mapper wrappedMapper; 36 private KilimTraceTreeModel treeModel; 37 private int seqNumber = 0; 38 39 43 public TreeModelMapper(Mapper aMapper) { 44 wrappedMapper = aMapper; 45 treeModel = new KilimTraceTreeModel(); 46 } 47 48 51 public TreeModelMapper() { 52 this(null); 53 } 54 55 59 public KilimTraceTreeModel getTraceTree() { 60 return treeModel; 61 } 62 63 66 public void enterContext(MappingContext aContext) throws KilimException { 67 Stack stk = aContext.getCallStack(); 68 int index = stk.size(); 69 Object parent = (index >= 2) ? stk.get(index - 2) : null; 70 Object child = (index >= 1) ? stk.get(index - 1) : null; 71 treeModel.addChild(parent, child); 72 } 73 74 77 public void leaveContext(MappingContext aContext) throws KilimException { } 78 79 private void setSeqNumberAndMode(MappingContext aContext, int aMode) { 80 Stack stk = aContext.getCallStack(); 81 int index = stk.size(); 82 Object object = (index >= 1) ? stk.get(index - 1) : null; 83 treeModel.setSeqNumberAndMode(object, seqNumber, aMode); 84 seqNumber++; 85 } 86 89 public Object getGetterValue (Object aSupport, boolean isStatic, String fieldName, MappingContext aContext) throws KilimException { 90 Object resultValue = null; 91 setSeqNumberAndMode(aContext, SOURCE); 92 if (wrappedMapper != null) { 93 resultValue = wrappedMapper.getGetterValue (aSupport, isStatic, fieldName, aContext); 94 } 95 return resultValue; 96 } 97 98 101 public void executeSetter(Object aSupport, boolean isStatic, String fieldName, Object toBeSet, MappingContext aContext) throws KilimException { 102 setSeqNumberAndMode(aContext, ACTION); 103 if (wrappedMapper != null) { 104 wrappedMapper.executeSetter(aSupport, isStatic, fieldName, toBeSet, aContext); 105 } 106 } 107 108 111 public Object getMethodValue(Object aSupport, boolean isStatic, String aMethodName, Object [] paramObjects, String [] typeNames, MappingContext aContext) throws KilimException { 112 Object resultValue = null; 113 setSeqNumberAndMode(aContext, SOURCE); 114 if (wrappedMapper != null) { 115 resultValue = wrappedMapper.getMethodValue (aSupport, isStatic, aMethodName, paramObjects, typeNames, aContext); 116 } 117 return resultValue; 118 } 119 120 123 public void executeMethod(Object aSupport, boolean isStatic, String aMethodName, Object [] paramObjects, String [] typeNames, MappingContext aContext) throws KilimException { 124 setSeqNumberAndMode(aContext, ACTION); 125 if (wrappedMapper != null) { 126 wrappedMapper.executeMethod (aSupport, isStatic, aMethodName, paramObjects, typeNames, aContext); 127 } 128 129 } 130 131 134 public Object getConstructorValue(Class aClass, Object [] paramObjects, String [] typeNames, MappingContext aContext) throws KilimException { 135 Object resultValue = null; 136 setSeqNumberAndMode(aContext, SOURCE); 137 if (wrappedMapper != null) { 138 resultValue = wrappedMapper.getConstructorValue(aClass, paramObjects, typeNames, aContext); 139 } 140 return resultValue; 141 } 142 143 146 public void executeConstructor(Class aClass, Object [] paramObjects, String [] typeNames, MappingContext aContext) throws KilimException { 147 setSeqNumberAndMode(aContext, ACTION); 148 if (wrappedMapper != null) { 149 wrappedMapper.executeConstructor(aClass, paramObjects, typeNames, aContext); 150 } 151 } 152 153 156 public Object getExternalValue(Object aValue, MappingContext aContext) throws KilimException { 157 Object resultValue = null; 158 setSeqNumberAndMode(aContext, SOURCE); 159 if (wrappedMapper != null) { 160 resultValue = wrappedMapper.getExternalValue(aValue, aContext); 161 } 162 return resultValue; 163 } 164 165 168 public Object getPropertyValue(Object aValue, MappingContext aContext) throws KilimException { 169 Object resultValue = null; 170 setSeqNumberAndMode(aContext, SOURCE); 171 if (wrappedMapper != null) { 172 resultValue = wrappedMapper.getPropertyValue(aValue, aContext); 173 } 174 return resultValue; 175 } 176 177 180 public Object getClassValue(String aClassName, MappingContext aContext) throws KilimException { 181 Object resultValue = null; 182 setSeqNumberAndMode(aContext, SOURCE); 183 if (wrappedMapper != null) { 184 resultValue = wrappedMapper.getClassValue(aClassName, aContext); 185 } 186 return resultValue; 187 } 188 189 192 public Object getEventSourceValue(MappingContext aContext) throws KilimException { 193 Object resultValue = null; 194 setSeqNumberAndMode(aContext, SOURCE); 195 if (wrappedMapper != null) { 196 resultValue = wrappedMapper.getEventSourceValue(aContext); 197 } 198 return resultValue; 199 } 200 201 204 public Object getNullElementValue(MappingContext aContext) throws KilimException { 205 Object resultValue = null; 206 setSeqNumberAndMode(aContext, SOURCE); 207 if (wrappedMapper != null) { 208 resultValue = wrappedMapper.getNullElementValue(aContext); 209 } 210 return resultValue; 211 212 } 213 214 217 public void executeNullElement(MappingContext aContext) throws KilimException { 218 setSeqNumberAndMode(aContext, ACTION); 219 if (wrappedMapper != null) { 220 wrappedMapper.executeNullElement(aContext); 221 } 222 223 } 224 } | Popular Tags |