Search in sources :

Example 26 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class ImportedTypesDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
    ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
    final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    if (!extensionType.isPresent()) {
        return;
    }
    Type type = extensionType.get().getType();
    final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
    if (!importTypes.isEmpty()) {
        if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
            throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
        }
        importTypes.forEach(imported -> {
            MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
            if (!(importedType instanceof ObjectType)) {
                throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
            }
            extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
        });
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectType(org.mule.metadata.api.model.ObjectType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) AnnotationValueFetcher(org.mule.runtime.module.extension.api.loader.java.type.AnnotationValueFetcher)

Aggregations

Type (org.mule.runtime.module.extension.api.loader.java.type.Type)26 MetadataType (org.mule.metadata.api.model.MetadataType)20 ObjectType (org.mule.metadata.api.model.ObjectType)16 ArrayType (org.mule.metadata.api.model.ArrayType)15 AnyType (org.mule.metadata.api.model.AnyType)13 StringType (org.mule.metadata.api.model.StringType)11 VoidType (org.mule.metadata.api.model.VoidType)11 DataType (org.mule.runtime.api.metadata.DataType)11 ResolvableType (org.springframework.core.ResolvableType)11 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)9 TypeGeneric (org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric)9 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)9 ParameterizedType (java.lang.reflect.ParameterizedType)8 Optional (java.util.Optional)8 DeclaredType (javax.lang.model.type.DeclaredType)8 MetadataTypeUtils.isObjectType (org.mule.metadata.api.utils.MetadataTypeUtils.isObjectType)8 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)8 String.format (java.lang.String.format)7 Field (java.lang.reflect.Field)6 Map (java.util.Map)6