use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.
the class SubTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer declarer = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = declarer.getDeclaration();
Optional<ExtensionTypeDescriptorModelProperty> implementingType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!implementingType.isPresent()) {
return;
}
Type type = implementingType.get().getType();
List<AnnotationValueFetcher<SubTypeMapping>> typeMappings = parseRepeatableAnnotation(type, SubTypeMapping.class, c -> ((SubTypesMapping) c).value());
if (!typeMappings.isEmpty()) {
declareSubTypesMapping(declarer, typeMappings, extensionDeclaration.getName());
}
}
use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.
the class BackPressureDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration sourceDeclaration) {
BackPressureStrategyModelProperty property;
Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (extensionTypeDescriptorModelProperty.isPresent()) {
Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
sourceDeclaration.addModelProperty(property);
if (property.getSupportedModes().size() > 1) {
addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
}
}
}
}.walk(extensionDeclaration);
}
use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.
the class DefaultJavaModelLoaderDelegate method declare.
/**
* {@inheritDoc}
*/
@Override
public ExtensionDeclarer declare(ExtensionLoadingContext context) {
ExtensionDeclarer declarer = context.getExtensionDeclarer().named(extensionElement.getName()).onVersion(version).fromVendor(extensionElement.getVendor()).withCategory(extensionElement.getCategory()).withModelProperty(new ExtensionTypeDescriptorModelProperty(extensionElement));
// TODO MULE-14517: This workaround should be replaced for a better and more complete mechanism
context.getParameter("COMPILATION_MODE").ifPresent(m -> declarer.withModelProperty(new CompileTimeModelProperty()));
extensionElement.getDeclaringClass().ifPresent(extensionClass -> declarer.withModelProperty(new ImplementingTypeModelProperty(extensionClass)));
processLicenseRequirements(declarer);
parseExternalLibs(extensionElement, declarer);
addExceptionEnricher(extensionElement, declarer);
configLoaderDelegate.declareConfigurations(declarer, extensionElement);
connectionProviderModelLoaderDelegate.declareConnectionProviders(declarer, extensionElement);
if (!isEmpty(extensionElement.getConfigurations())) {
operationLoaderDelegate.declareOperations(declarer, declarer, null, extensionElement.getOperations(), false);
functionModelLoaderDelegate.declareFunctions(declarer, declarer, null, extensionElement.getFunctions());
extensionElement.getSources().forEach(source -> sourceModelLoaderDelegate.declareMessageSource(declarer, declarer, source, false));
}
return declarer;
}
use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty in project mule by mulesoft.
the class ErrorsDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
String extensionNamespace = getExtensionsNamespace(declaration);
Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
Type extensionElement = implementingType.get().getType();
Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
if (errorAnnotation.isPresent()) {
ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
if (errorTypes.length > 0) {
ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
} else {
handleNoErrorTypes(extensionElement, errorOperations);
}
} else {
handleNoErrorTypes(extensionElement, errorOperations);
}
}
}
use of org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty 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