Search in sources :

Example 6 with IllegalModelDefinitionException

use of org.mule.runtime.extension.api.exception.IllegalModelDefinitionException in project mule by mulesoft.

the class ExtensionsTestUtils method validate.

public static ProblemsReporter validate(ExtensionModel model, ExtensionModelValidator validator) {
    ProblemsReporter problemsReporter = new ProblemsReporter(model);
    validator.validate(model, problemsReporter);
    if (problemsReporter.hasErrors()) {
        throw new IllegalModelDefinitionException(problemsReporter.toString());
    }
    return problemsReporter;
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter)

Example 7 with IllegalModelDefinitionException

use of org.mule.runtime.extension.api.exception.IllegalModelDefinitionException in project mule by mulesoft.

the class MetadataScopeAdapter method getCategoryName.

private String getCategoryName(Supplier<? extends OutputTypeResolver> outputResolver, Supplier<? extends AttributesTypeResolver> attributesResolver, Map<String, Supplier<? extends InputTypeResolver>> inputResolvers) {
    OutputTypeResolver outputTypeResolver = outputResolver.get();
    if (!(outputTypeResolver instanceof NullMetadataResolver)) {
        return outputTypeResolver.getCategoryName();
    }
    AttributesTypeResolver attributesTypeResolver = attributesResolver.get();
    if (!(attributesTypeResolver instanceof NullMetadataResolver)) {
        return attributesTypeResolver.getCategoryName();
    }
    for (Supplier<? extends InputTypeResolver> supplier : inputResolvers.values()) {
        InputTypeResolver inputTypeResolver = supplier.get();
        if (!(inputTypeResolver instanceof NullMetadataResolver)) {
            return inputTypeResolver.getCategoryName();
        }
    }
    throw new IllegalModelDefinitionException("Unable to create Keys Resolver. A Keys Resolver is being defined " + "without defining an Output Resolver, Input Resolver nor Attributes Resolver");
}
Also used : NullMetadataResolver(org.mule.runtime.extension.api.metadata.NullMetadataResolver) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) OutputTypeResolver(org.mule.runtime.api.metadata.resolving.OutputTypeResolver) InputTypeResolver(org.mule.runtime.api.metadata.resolving.InputTypeResolver) AttributesTypeResolver(org.mule.runtime.api.metadata.resolving.AttributesTypeResolver)

Example 8 with IllegalModelDefinitionException

use of org.mule.runtime.extension.api.exception.IllegalModelDefinitionException in project mule by mulesoft.

the class StereotypeResolver method getStereotype.

protected static StereotypeModel getStereotype(StereotypeDefinition stereotypeDefinition, String namespace, Map<StereotypeDefinition, StereotypeModel> stereotypesCache) {
    return stereotypesCache.computeIfAbsent(stereotypeDefinition, definition -> {
        if (!isValidStereotype(stereotypeDefinition, namespace)) {
            throw new IllegalModelDefinitionException(format("Stereotype '%s' defines namespace '%s' which doesn't match extension stereotype '%s'. No extension can define " + "stereotypes on namespaces other than its own", stereotypeDefinition.getName(), stereotypeDefinition.getNamespace(), namespace));
        }
        final StereotypeModelBuilder builder = newStereotype(stereotypeDefinition.getName(), namespace);
        stereotypeDefinition.getParent().ifPresent(parent -> {
            String parentNamespace = parent.getNamespace();
            if (isBlank(parentNamespace)) {
                parentNamespace = namespace;
            }
            builder.withParent(getStereotype(parent, parentNamespace, stereotypesCache));
        });
        return builder.build();
    });
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) StereotypeModelBuilder(org.mule.runtime.api.meta.model.stereotype.StereotypeModelBuilder)

Example 9 with IllegalModelDefinitionException

use of org.mule.runtime.extension.api.exception.IllegalModelDefinitionException in project mule by mulesoft.

the class IntrospectionUtils method injectFieldOfType.

private static void injectFieldOfType(Object target, Object value, Class<?> fieldType) {
    final Class<?> type = target.getClass();
    List<Field> fields = getFieldsOfType(type, fieldType);
    if (fields.isEmpty()) {
        return;
    } else if (fields.size() > 1) {
        throw new IllegalModelDefinitionException(format("Class '%s' has %d fields of type with @%s. Only one field of that type was expected", type.getName(), fields.size(), fieldType));
    }
    new FieldSetter<>(fields.get(0)).set(target, value);
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) RequireNameField(org.mule.runtime.module.extension.internal.loader.java.property.RequireNameField) Field(java.lang.reflect.Field)

Example 10 with IllegalModelDefinitionException

use of org.mule.runtime.extension.api.exception.IllegalModelDefinitionException 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

IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)10 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)4 Optional (java.util.Optional)3 MetadataType (org.mule.metadata.api.model.MetadataType)3 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)3 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)3 String.format (java.lang.String.format)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)2 ParameterDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer)2 ParameterizedDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer)2 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)2 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableMap (com.google.common.collect.ImmutableMap)1