
com.sdl.dxa.tridion.annotations.impl.ValueAnnotationLogger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dxa-common Show documentation
Show all versions of dxa-common Show documentation
DXA Common project contains framework common classes shared between all other artifacts
package com.sdl.dxa.tridion.annotations.impl;
import com.sdl.dxa.tridion.annotations.AnnotationFetcherForValue;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
@Component
public class ValueAnnotationLogger implements AnnotationFetcherForValue {
@Override
public String fetchAllValues(InitializingBean bean) throws Exception {
if (bean == null) return "";
Field[] declaredFields = bean.getClass().getDeclaredFields();
StringBuilder result = new StringBuilder(bean.getClass().getCanonicalName() + " has ");
if (declaredFields.length == 0) result.append(" no @Value annotations");
for (Field field : declaredFields){
Value valueAnnotation = field.getAnnotation(Value.class);
if (valueAnnotation != null) {
field.setAccessible(true);
result.append("\t@Value(\"" + valueAnnotation.value() + "\")\n\t" + field.getGenericType().getTypeName());
result.append(" " + field.getName() + " = ");
result.append(" " + field.get(bean));
result.append("\n");
}
}
return result.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy