public RecursiveReflectionToStringStyle(int maxDepth) { setUseShortClassName(true); setUseIdentityHashCode(true); this.maxDepth = maxDepth > MAX_DEPTH ? MAX_DEPTH : (maxDepth < 0 ? 0 : maxDepth); }
/** * Strips getter prefix from method name. * * @param methodName the name of the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method name has no getter prefix. */ public static String getFieldName(final String methodName) { if (isGetterMethod(methodName)) { return decapitalizeFirstCharOfString(stripGetterPrefix(methodName)); } return null; }
/** * Check if the passed instance is a {@link java.util.List} and contains only elements of the passed element types. * In that case it casts the passed instance to a List of the passed element type. * * @param instance * @return The instance cast to a List of the passed element type if the passed instance is a list and only contains * element of the passed element type, otherwise it return null. */ public static <T> List<T> getListOfType(Object instance, Class<T> elementType) { if (instance == null || elementType == null || !isListOfType(instance, elementType)) { return null; } try { return (List<T>) instance; } catch (ClassCastException e) { return null; } }
@Override public int compare(PassedContextDataElementWrapper o1, PassedContextDataElementWrapper o2) { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } else { if (o1.getOrder() == null && o2.getOrder() == null) { // must compare names return compareNames(o1.getNameObjectValuePair().getName(), o2.getNameObjectValuePair().getName()); } else if (o1.getOrder() == null) { return 1; } else if (o2.getOrder() == null) { return -1; } else { int orderCompareResult = o1.getOrder().compareTo(o2.getOrder()); if (orderCompareResult == 0) { // must compare names return compareNames(o1.getNameObjectValuePair().getName(), o2.getNameObjectValuePair().getName()); } else { return orderCompareResult; } } } }
/** * selects the best macthing serialization depending on value type. * * @param nameObjectValuePair * @return */ private Object getValueOfNameObjectValuePair(final NameObjectValuePair nameObjectValuePair) { if (nameObjectValuePair != null && nameObjectValuePair.getValue() != null) { if (TraceeContextLogAnnotationUtilities.getAnnotationFromType(nameObjectValuePair.getValue()) != null) { return nameObjectValuePair.getValue(); } else if (!shouldBeIgnoreAtDeSerialization(nameObjectValuePair.getValue())) { return ReflectionToStringBuilder.reflectionToString(nameObjectValuePair.getValue(), new RecursiveReflectionToStringStyle()); } else { // not null value - but type is in IGNORED_AT_DESERIALIZATION set return nameObjectValuePair.getValue().toString(); } } else { return null; } }
/** * Strips getter prefix from method name. * * @param method the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method is null or if the method name has no getter prefix. */ public static String getFieldName(final Method method) { if (method != null) { return getFieldName(method.getName()); } else { return null; } }
/** * Checks whether the method name starts with a getter prefix. * * @param method the method to check for * @return true if the method name starts with eiher one of values stored in GETTER_PREFIXES */ public static boolean isGetterMethod(final Method method) { if (method != null) { return isGetterMethod(method.getName()); } else { return false; } }
public PassedContextDataElementWrapper(NameObjectValuePair nameObjectValuePair) { this.nameObjectValuePair = nameObjectValuePair; TraceeContextLogProvider annotation = TraceeContextLogAnnotationUtilities.getAnnotationFromType(nameObjectValuePair.getValue()); if (annotation != null) { order = annotation.order(); } else { order = null; } }
@SuppressWarnings("unused") @TraceeContextProviderMethod(displayName = "serialized-target-instance", order = 50) public final String getSerializedTargetInstance() { if (proceedingJoinPoint != null) { // output invoked instance String deSerializedInstance; Object targetInstance = proceedingJoinPoint.getTarget(); if (targetInstance != null) { deSerializedInstance = ReflectionToStringBuilder.reflectionToString(targetInstance, new RecursiveReflectionToStringStyle()); } else { deSerializedInstance = null; } return deSerializedInstance; } return null; }
/** * Strips getter prefix from method name. * * @param methodName the name of the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method name has no getter prefix. */ public static String getFieldName(final String methodName) { if (isGetterMethod(methodName)) { return decapitalizeFirstCharOfString(stripGetterPrefix(methodName)); } return null; }
@Override public int compare(PassedContextDataElementWrapper o1, PassedContextDataElementWrapper o2) { if (o1 == null && o2 == null) { return 0; } else if (o1 == null) { return -1; } else if (o2 == null) { return 1; } else { if (o1.getOrder() == null && o2.getOrder() == null) { // must compare names return compareNames(o1.getNameObjectValuePair().getName(), o2.getNameObjectValuePair().getName()); } else if (o1.getOrder() == null) { return 1; } else if (o2.getOrder() == null) { return -1; } else { int orderCompareResult = o1.getOrder().compareTo(o2.getOrder()); if (orderCompareResult == 0) { // must compare names return compareNames(o1.getNameObjectValuePair().getName(), o2.getNameObjectValuePair().getName()); } else { return orderCompareResult; } } } }
public RecursiveReflectionToStringStyle(int maxDepth) { setUseShortClassName(true); setUseIdentityHashCode(true); this.maxDepth = maxDepth > MAX_DEPTH ? MAX_DEPTH : (maxDepth < 0 ? 0 : maxDepth); }
/** * selects the best macthing serialization depending on value type. * * @param nameObjectValuePair * @return */ private Object getValueOfNameObjectValuePair(final NameObjectValuePair nameObjectValuePair) { if (nameObjectValuePair != null && nameObjectValuePair.getValue() != null) { if (TraceeContextLogAnnotationUtilities.getAnnotationFromType(nameObjectValuePair.getValue()) != null) { return nameObjectValuePair.getValue(); } else if (!shouldBeIgnoreAtDeSerialization(nameObjectValuePair.getValue())) { return ReflectionToStringBuilder.reflectionToString(nameObjectValuePair.getValue(), new RecursiveReflectionToStringStyle()); } else { // not null value - but type is in IGNORED_AT_DESERIALIZATION set return nameObjectValuePair.getValue().toString(); } } else { return null; } }
/** * Check if the passed instance is a {@link java.util.List} and contains only elements of the passed element types. * In that case it casts the passed instance to a List of the passed element type. * * @param instance * @return The instance cast to a List of the passed element type if the passed instance is a list and only contains * element of the passed element type, otherwise it return null. */ public static <T> List<T> getListOfType(Object instance, Class<T> elementType) { if (instance == null || elementType == null || !isListOfType(instance, elementType)) { return null; } try { return (List<T>) instance; } catch (ClassCastException e) { return null; } }
/** * Strips getter prefix from method name. * * @param method the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method is null or if the method name has no getter prefix. */ public static String getFieldName(final Method method) { if (method != null) { return getFieldName(method.getName()); } else { return null; } }
/** * Checks whether the method name starts with a getter prefix. * * @param method the method to check for * @return true if the method name starts with eiher one of values stored in GETTER_PREFIXES */ public static boolean isGetterMethod(final Method method) { if (method != null) { return isGetterMethod(method.getName()); } else { return false; } }
public PassedContextDataElementWrapper(NameObjectValuePair nameObjectValuePair) { this.nameObjectValuePair = nameObjectValuePair; TraceeContextProvider annotation = TraceeContextLogAnnotationUtilities.getAnnotationFromType(nameObjectValuePair.getValue()); if (annotation != null) { order = annotation.order(); } else { order = null; } }
@TraceeContextLogProviderMethod(displayName = "deserialized.targetInstance", propertyName = ProfilePropertyNames.EJB_INVOCATION_CONTEXT_TARGET_INSTANCE, order = 30) public final String getTargetInstance() { String result = null; if (this.invocationContext != null) { Object targetInstance = this.invocationContext.getTarget(); if (targetInstance != null) { result = ReflectionToStringBuilder.reflectionToString(targetInstance, new RecursiveReflectionToStringStyle()); } else { result = null; } } return result; }
/** * Check if the passed instance is a {@link java.util.List} and contains only elements of the passed element types. * In that case it casts the passed instance to a List of the passed element type. * @param instance * @return The instance cast to a List of the passed element type if the passed instance is a list and only contains * element of the passed element type, otherwise it return null. */ public static <T> List<T> getListOfType(Object instance, Class<T> elementType) { if (instance == null || elementType == null || !isListOfType(instance, elementType)) { return null; } try { return (List<T>) instance; } catch (ClassCastException e) { return null; } }
/** * Helper method for getting a corresponsing field for a method * * @param type the type to search the field in * @param method the getter method to search the field for * @return the Field or null if the field for the passed method doesn't exists */ Field getCorrespondingField(Class type, Method method) { try { return type.getDeclaredField(GetterUtilities.getFieldName(method)); } catch (NoSuchFieldException e) { return null; } }