Search in sources :

Example 1 with ModelDriverException

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;
}
Also used : AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) AnnotationDefinitionResponse(org.kie.workbench.common.services.datamodeller.driver.model.AnnotationDefinitionResponse) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 2 with ModelDriverException

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;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) Type(org.jboss.forge.roaster.model.Type) JavaType(org.jboss.forge.roaster.model.JavaType) ElementType(org.kie.workbench.common.services.datamodeller.core.ElementType) AnnotationSource(org.jboss.forge.roaster.model.source.AnnotationSource) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility) List(java.util.List) ArrayList(java.util.ArrayList) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)

Example 3 with ModelDriverException

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);
}
Also used : ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Example 4 with ModelDriverException

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);
    }
}
Also used : JavaClass(org.jboss.forge.roaster.model.JavaClass) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)

Example 5 with ModelDriverException

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;
}
Also used : ParserException(org.jboss.forge.roaster.ParserException) JavaTypeInfoImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaTypeInfoImpl) TypeInfoResult(org.kie.workbench.common.services.datamodeller.driver.TypeInfoResult) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) ModelDriverException(org.kie.workbench.common.services.datamodeller.driver.ModelDriverException) IOException(java.io.IOException) ParserException(org.jboss.forge.roaster.ParserException) DriverError(org.kie.workbench.common.services.datamodeller.driver.model.DriverError)

Aggregations

ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)9 ArrayList (java.util.ArrayList)5 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)5 IOException (java.io.IOException)3 List (java.util.List)3 ParserException (org.jboss.forge.roaster.ParserException)3 AnnotationSource (org.jboss.forge.roaster.model.source.AnnotationSource)2 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)2 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)2 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)2 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)2 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 Visibility (org.kie.workbench.common.services.datamodeller.core.Visibility)2 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)2 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)2 JavaClass (org.jboss.forge.roaster.model.JavaClass)1 JavaType (org.jboss.forge.roaster.model.JavaType)1 Method (org.jboss.forge.roaster.model.Method)1 Type (org.jboss.forge.roaster.model.Type)1 FieldSource (org.jboss.forge.roaster.model.source.FieldSource)1