@SuppressWarnings("unchecked") private void useLoggingInfoInsertValue( LoggingInfo loggingInfo, Object target, Annotation annotation, Method method) { if (annotation instanceof UseLoggingInfoConvertor) { UseLoggingInfoConvertor useLoggingInfo = (UseLoggingInfoConvertor) annotation; boolean f = false; for (PublisherType publisherType : useLoggingInfo.publisherTypes()) { if (publisherType.equals(loggingInfo.getPublisherType())) { f = true; break; } } if (f) { Class<? extends LoggingInfoConvertor<?>> convertorClass = useLoggingInfo.convertor(); LoggingInfoConvertor<Object> convertor = null; try { convertor = (LoggingInfoConvertor<Object>) convertorClass.newInstance(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("LoggingInfo convertor instantiation was failed!", e); } return; } if (convertor != null) { Object convertedValue = null; try { convertedValue = convertor.convert(loggingInfo); } catch (Exception e) { if (log.isErrorEnabled()) { log.error( "LoggingInfo convertation was failed! Null value used as convertation result!", e); } convertedValue = null; } try { method.invoke(target, convertedValue); } catch (Exception e) { if (log.isErrorEnabled()) { log.error( "Method invoke was failed! Please, check that method '" + method.toGenericString() + "' annotated correctly!", e); } } } } } }
@SuppressWarnings("unchecked") private void insertValue( LoggingInfo loggingInfo, Object target, Annotation annotation, Method method, Object value) { boolean f = false; try { Method publisherTypeMethod = annotation.annotationType().getMethod("publisherTypes", new Class<?>[] {}); PublisherType[] publisherTypes = (PublisherType[]) publisherTypeMethod.invoke(annotation); for (PublisherType publisherType : publisherTypes) { if (publisherType.equals(loggingInfo.getPublisherType())) { f = true; break; } } } catch (Exception e) { f = false; if (log.isErrorEnabled()) { log.error("Invalid annotation!", e); } } if (f) { Class<? extends TypeConvertor<?, ?>> typeConvertorClass = null; try { Method convertorMethod = annotation.annotationType().getMethod("convertor", new Class<?>[] {}); typeConvertorClass = (Class<? extends TypeConvertor<?, ?>>) convertorMethod.invoke(annotation); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Invalid annotation!", e); } return; } if (!(DefaultTypeConvertor.class.equals(typeConvertorClass) || DefaultStringConvertor.class.equals(typeConvertorClass) || DefaultNumberConvertor.class.equals(typeConvertorClass) || DefaultDateConvertor.class.equals(typeConvertorClass))) { TypeConvertor<Object, Object> convertor = null; try { convertor = (TypeConvertor<Object, Object>) typeConvertorClass.newInstance(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error( "Type convertor instantiation was failed! Null value used as result value!", e); } value = null; } if (convertor != null) { try { value = convertor.convert(value); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Type convertation was failed! Null value used as result value!", e); } value = null; } } } try { method.invoke(target, value); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Method invoke was failed! Please, check that method annotated correctly!", e); } } } }