Search in sources :

Example 6 with ImportedTypeModel

use of org.mule.runtime.api.meta.model.ImportedTypeModel 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

ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)6 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)4 ObjectType (org.mule.metadata.api.model.ObjectType)4 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)3 Reference (org.mule.runtime.api.util.Reference)3 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)3 List (java.util.List)2 Optional (java.util.Optional)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 MetadataTypeUtils.getTypeId (org.mule.metadata.api.utils.MetadataTypeUtils.getTypeId)2 NOT_SUPPORTED (org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)2 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)2 ObjectStore (org.mule.runtime.api.store.ObjectStore)2 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)2 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional.empty (java.util.Optional.empty)1