use of com.blazebit.persistence.view.StaticBuilder in project blaze-persistence by Blazebit.
the class EntityViewManagerImpl method initializeStaticBuilder.
private static void initializeStaticBuilder(Set<String> errors, ManagedViewType<?> managedView, Map<ViewBuilderKey, Constructor<? extends EntityViewBuilder<?>>> viewBuilderConstructors) {
Class<?> javaType = managedView.getJavaType();
Class<?> builderClass;
try {
builderClass = javaType.getClassLoader().loadClass(getBuilderClassName(javaType));
StaticBuilder annotation = builderClass.getAnnotation(StaticBuilder.class);
if (annotation != null) {
if (annotation.value() != javaType) {
errors.add("The static builder class '" + builderClass.getName() + "' was expected to be defined for the entity view type '" + javaType.getName() + "' but was defined for: " + annotation.value().getName());
return;
}
}
} catch (ClassNotFoundException e) {
// Ignore
return;
}
try {
int size = managedView.getConstructors().size();
if (size == 0) {
Class<?> constructorClass = javaType.getClassLoader().loadClass(builderClass.getName() + "$Init");
viewBuilderConstructors.put(new ViewBuilderKey(managedView, null), (Constructor<? extends EntityViewBuilder<?>>) constructorClass.getDeclaredConstructor(Map.class));
} else if (size == 1) {
MappingConstructor<?> constructor = managedView.getConstructors().iterator().next();
Class<?> constructorClass = javaType.getClassLoader().loadClass(builderClass.getName() + "$" + Character.toUpperCase(constructor.getName().charAt(0)) + constructor.getName().substring(1));
viewBuilderConstructors.put(new ViewBuilderKey(managedView, null), (Constructor<? extends EntityViewBuilder<?>>) constructorClass.getDeclaredConstructor(Map.class));
viewBuilderConstructors.put(new ViewBuilderKey(managedView, constructor), (Constructor<? extends EntityViewBuilder<?>>) constructorClass.getDeclaredConstructor(Map.class));
} else {
for (MappingConstructor<?> constructor : managedView.getConstructors()) {
Class<?> constructorClass = javaType.getClassLoader().loadClass(builderClass.getName() + "$" + Character.toUpperCase(constructor.getName().charAt(0)) + constructor.getName().substring(1));
viewBuilderConstructors.put(new ViewBuilderKey(managedView, constructor), (Constructor<? extends EntityViewBuilder<?>>) constructorClass.getDeclaredConstructor(Map.class));
}
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
errors.add("The initialization of the static builder class '" + builderClass.getName() + "' failed: " + sw.toString());
}
}
Aggregations