use of org.kie.workbench.common.services.datamodeller.driver.ModelDriverException in project kie-wb-common by kiegroup.
the class DataModelerServiceImpl method resolveDefinitionRequest.
@Override
public AnnotationDefinitionResponse resolveDefinitionRequest(AnnotationDefinitionRequest definitionRequest, KieModule kieModule) {
JavaRoasterModelDriver modelDriver = new JavaRoasterModelDriver();
ClassLoader classLoader = classLoaderHelper.getModuleClassLoader(kieModule);
ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(classLoader);
AnnotationDefinitionResponse definitionResponse = new AnnotationDefinitionResponse();
try {
AnnotationDefinition annotationDefinition = modelDriver.buildAnnotationDefinition(definitionRequest.getClassName(), classTypeResolver);
definitionResponse.withAnnotationDefinition(annotationDefinition);
} catch (ModelDriverException e) {
DriverError driverError = new DriverError(e.getMessage());
definitionResponse.addError(driverError);
}
return definitionResponse;
}
use of org.kie.workbench.common.services.datamodeller.driver.ModelDriverException in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method parseProperty.
public ObjectProperty parseProperty(FieldSource<JavaClassSource> field, ClassTypeResolver classTypeResolver) throws ModelDriverException {
Type type;
boolean multiple = false;
String className;
String bag = null;
ObjectProperty property;
Visibility visibility = DriverUtils.buildVisibility(field.getVisibility());
try {
type = field.getType();
if (type.isPrimitive()) {
className = type.getName();
} else {
if (DriverUtils.isSimpleClass(type)) {
className = resolveTypeName(classTypeResolver, type.getName());
} else {
// if this point was reached, we know it's a Collection. Managed type check was done previous to adding the property.
multiple = true;
@SuppressWarnings("unchecked") Type elementsType = ((List<Type>) type.getTypeArguments()).get(0);
className = resolveTypeName(classTypeResolver, elementsType.getName());
bag = resolveTypeName(classTypeResolver, type.getName());
}
}
property = new ObjectPropertyImpl(field.getName(), className, multiple, bag, visibility, field.isStatic(), field.isFinal());
List<AnnotationSource<JavaClassSource>> annotations = field.getAnnotations();
if (annotations != null) {
for (AnnotationSource annotation : annotations) {
addPropertyAnnotation(property, annotation, classTypeResolver);
}
}
} catch (ClassNotFoundException e) {
logger.error(errorMessage(DATA_OBJECT_FIELD_LOAD_ERROR, field.getName(), field.getOrigin().getName()), e);
throw new ModelDriverException(errorMessage(DATA_OBJECT_FIELD_LOAD_ERROR, field.getName(), field.getOrigin().getName()), e);
}
return property;
}
use of org.kie.workbench.common.services.datamodeller.driver.ModelDriverException in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method addModelDriverError.
private void addModelDriverError(ModelDriverResult result, Path file, ModelDriverException e) {
DriverError error;
StringBuilder message = new StringBuilder();
message.append(e.getMessage());
Throwable cause = e.getCause();
while (cause != null) {
message.append(" : ");
message.append(cause.getMessage());
if (cause instanceof ModelDriverException) {
cause = cause.getCause();
} else {
cause = null;
}
}
error = new DriverError(message.toString(), Paths.convert(file));
result.addError(error);
}
use of org.kie.workbench.common.services.datamodeller.driver.ModelDriverException in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method buildAnnotationDefinition.
public AnnotationDefinition buildAnnotationDefinition(String annotationClassName, ClassTypeResolver classTypeResolver) throws ModelDriverException {
try {
String resolvedClassName = resolveTypeName(classTypeResolver, annotationClassName);
Class annotationClass = classTypeResolver.resolveType(resolvedClassName);
return DriverUtils.buildAnnotationDefinition(annotationClass);
} catch (ClassNotFoundException e) {
logger.error(errorMessage(ANNOTATION_LOAD_ERROR, annotationClassName), e);
throw new ModelDriverException(errorMessage(ANNOTATION_LOAD_ERROR, annotationClassName), e);
}
}
use of org.kie.workbench.common.services.datamodeller.driver.ModelDriverException in project kie-wb-common by kiegroup.
the class JavaRoasterModelDriver method loadJavaTypeInfo.
public TypeInfoResult loadJavaTypeInfo(final String source) throws ModelDriverException {
TypeInfoResult result = new TypeInfoResult();
if (source == null || "".equals(source)) {
logger.debug("source: " + source + " is empty.");
result.addError(new DriverError("Source is empty"));
return result;
}
try {
JavaType<?> javaType = Roaster.parse(source);
if (javaType.getSyntaxErrors() != null && !javaType.getSyntaxErrors().isEmpty()) {
addSyntaxErrors(result, null, javaType.getSyntaxErrors());
} else {
JavaTypeInfoImpl typeInfo = new JavaTypeInfoImpl();
result.setTypeInfo(typeInfo);
typeInfo.setName(javaType.getName());
typeInfo.setPackageName(javaType.getPackage());
typeInfo.setAnnotation(javaType.isAnnotation());
typeInfo.setClass(javaType.isClass());
typeInfo.setEnum(javaType.isEnum());
typeInfo.setInterface(javaType.isInterface());
typeInfo.setPackagePrivate(javaType.isPackagePrivate());
typeInfo.setPrivate(javaType.isPrivate());
typeInfo.setProtected(javaType.isProtected());
typeInfo.setPublic(javaType.isPublic());
}
} catch (ParserException e) {
result.addError(new DriverError(e.getMessage()));
} catch (Exception e) {
// Unexpected parsing o model loading exception.
logger.error(errorMessage(GENERIC_ERROR, e));
throw new ModelDriverException(errorMessage(MODEL_LOAD_GENERIC_ERROR), e);
}
return result;
}
Aggregations