private void addClassAttributes(Method method, JoinPoint joinPoint, Map<String, Object> attributes) { Class<?> declaringClass = method.getDeclaringClass(); if (method.isAnnotationPresent(TrackableAttribute.class) && Trackable.class.isAssignableFrom(declaringClass)) { Trackable trackable = (Trackable) joinPoint.getThis(); if (trackable.getTrackableAttributes() != null) { attributes.putAll(trackable.getTrackableAttributes()); } } while (declaringClass != null) { addFixedAttribute(declaringClass.getAnnotation(FixedAttribute.class), attributes); addFixedAttributes(declaringClass.getAnnotation(FixedAttributes.class), attributes); declaringClass = declaringClass.getEnclosingClass(); } declaringClass = joinPoint.getThis().getClass(); addFixedAttribute(declaringClass.getAnnotation(FixedAttribute.class), attributes); addFixedAttributes(declaringClass.getAnnotation(FixedAttributes.class), attributes); }
private void addMethodAttributes(Method method, Object returnValue, Map<String, Object> attributes, Map<Integer, String> transformMap) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Attribute) { addAttribute((Attribute) annotation, returnValue, attributes); } if (annotation instanceof FixedAttribute) { addFixedAttribute((FixedAttribute) annotation, attributes); } if (annotation instanceof FixedAttributes) { addFixedAttributes((FixedAttributes) annotation, attributes); } if (annotation instanceof TransformAttributeMap) { TransformAttributeMap transformAttributeMap = (TransformAttributeMap) annotation; int[] keys = transformAttributeMap.keys(); String[] values = transformAttributeMap.values(); if (keys.length != values.length) { throw new IllegalStateException("TransformAttributeMap keys and values must have same length"); } for (int i = 0; i < keys.length; i++) { transformMap.put(keys[i], values[i]); } } if (annotation instanceof TransformAttribute) { addTransformAttribute((TransformAttribute) annotation, returnValue, transformMap, attributes); } } }