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;
}
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");
}
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();
});
}
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);
}
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));
});
}
}
Aggregations