Search in sources :

Example 1 with JavaTypeInfoImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.JavaTypeInfoImpl in project kie-wb-common by kiegroup.

the class DataModelerScreenPresenter method checkDirtyAndSaveFile.

private void checkDirtyAndSaveFile() {
    final JavaTypeInfoImpl newTypeInfo = new JavaTypeInfoImpl();
    if (isDirty()) {
        if (context.isEditorChanged()) {
            newTypeInfo.setPackageName(context.getDataObject().getPackageName());
            newTypeInfo.setName(context.getDataObject().getName());
            saveFile(newTypeInfo);
        } else {
            view.showLoading();
            modelerService.call(new RemoteCallback<TypeInfoResult>() {

                @Override
                public void callback(TypeInfoResult typeInfoResult) {
                    view.hideBusyIndicator();
                    if (!typeInfoResult.hasErrors() && typeInfoResult.getJavaTypeInfo() != null) {
                        newTypeInfo.setPackageName(typeInfoResult.getJavaTypeInfo().getPackageName());
                        newTypeInfo.setName(typeInfoResult.getJavaTypeInfo().getName());
                        saveFile(newTypeInfo);
                    } else {
                        saveFile(null);
                    }
                }
            }).loadJavaTypeInfo(getSource());
        }
    } else {
        saveFile(null);
    }
}
Also used : JavaTypeInfoImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaTypeInfoImpl) TypeInfoResult(org.kie.workbench.common.screens.datamodeller.model.TypeInfoResult) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 2 with JavaTypeInfoImpl

use of org.kie.workbench.common.services.datamodeller.core.impl.JavaTypeInfoImpl 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

JavaTypeInfoImpl (org.kie.workbench.common.services.datamodeller.core.impl.JavaTypeInfoImpl)2 IOException (java.io.IOException)1 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)1 ParserException (org.jboss.forge.roaster.ParserException)1 TypeInfoResult (org.kie.workbench.common.screens.datamodeller.model.TypeInfoResult)1 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)1 TypeInfoResult (org.kie.workbench.common.services.datamodeller.driver.TypeInfoResult)1 DriverError (org.kie.workbench.common.services.datamodeller.driver.model.DriverError)1