use of org.mule.runtime.extension.api.exception.IllegalSourceModelDefinitionException in project mule by mulesoft.
the class SourceModelLoaderDelegate method declareMessageSource.
void declareMessageSource(ExtensionDeclarer extensionDeclarer, HasSourceDeclarer declarer, SourceElement sourceType, boolean supportsConfig) {
// TODO: MULE-9220 - Add a syntax validator which checks that the sourceType doesn't implement
if (isLifecycle(sourceType)) {
throw new IllegalSourceModelDefinitionException(format("Source class '%s' implements a lifecycle interface. Sources are not allowed to", sourceType.getName()));
}
final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(sourceType);
final Optional<ExtensionParameter> connectionParameter = loader.getConnectionParameter(sourceType);
if (loader.isInvalidConfigSupport(supportsConfig, configParameter, connectionParameter)) {
throw new IllegalSourceModelDefinitionException(format("Source '%s' is defined at the extension level but it requires a config parameter. " + "Remove such parameter or move the source to the proper config", sourceType.getName()));
}
HasSourceDeclarer actualDeclarer = (HasSourceDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) declarer, configParameter, connectionParameter);
SourceDeclarer existingDeclarer = sourceDeclarers.get(sourceType);
if (existingDeclarer != null) {
actualDeclarer.withMessageSource(existingDeclarer);
return;
}
SourceDeclarer sourceDeclarer = actualDeclarer.withMessageSource(sourceType.getAlias());
sourceDeclarer.withModelProperty(new ExtensionTypeDescriptorModelProperty(sourceType));
List<Type> sourceGenerics = sourceType.getSuperClassGenerics();
if (sourceGenerics.size() != 2) {
// TODO: MULE-9220: Add a syntax validator for this
throw new IllegalModelDefinitionException(format("Message source class '%s' was expected to have 2 generic types " + "(one for the Payload type and another for the Attributes type) but %d were found", sourceType.getName(), sourceGenerics.size()));
}
sourceDeclarer.hasResponse(sourceType.isAnnotatedWith(EmitsResponse.class)).requiresConnection(connectionParameter.isPresent());
sourceType.getDeclaringClass().ifPresent(clazz -> sourceDeclarer.withModelProperty(new SourceFactoryModelProperty(new DefaultSourceFactory((Class<? extends Source>) clazz))).withModelProperty(new ImplementingTypeModelProperty(clazz)));
processMimeType(sourceDeclarer, sourceType);
processComponentConnectivity(sourceDeclarer, sourceType, sourceType);
resolveOutputTypes(sourceDeclarer, sourceType);
loader.addExceptionEnricher(sourceType, sourceDeclarer);
declareSourceParameters(sourceType, sourceDeclarer);
declareSourceCallback(sourceType, sourceDeclarer);
sourceDeclarers.put(sourceType, sourceDeclarer);
}
use of org.mule.runtime.extension.api.exception.IllegalSourceModelDefinitionException in project mule by mulesoft.
the class SourceTypeWrapper method getMethodAnnotatedWith.
private Optional<MethodElement> getMethodAnnotatedWith(Class<? extends Annotation> annotationType) {
Class<?> searchClass = aClass;
Collection<Method> methods = null;
while (!Object.class.equals(searchClass)) {
methods = getMethodsAnnotatedWith(searchClass, annotationType, false);
if (methods.isEmpty()) {
searchClass = searchClass.getSuperclass();
} else {
break;
}
}
if (isEmpty(methods)) {
return empty();
} else if (methods.size() > 1) {
throw new IllegalSourceModelDefinitionException(format("Source declared in class '%s' declares more than one method annotated with '%s'", aClass.getName(), annotationType.getSimpleName()));
} else {
return of(new MethodWrapper(methods.iterator().next(), typeLoader));
}
}
Aggregations