use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class MuleArtifactContext method createApplicationComponents.
/**
* Creates te definition for all the objects to be created form the enabled components in the {@code applicationModel}.
*
* @param beanFactory the bean factory in which definition must be created.
* @param applicationModel the artifact application model.
* @param mustBeRoot if the component must be root to be created.
* @return an order list of the created bean names. The order must be respected for the creation of the objects.
*/
protected List<String> createApplicationComponents(DefaultListableBeanFactory beanFactory, ApplicationModel applicationModel, boolean mustBeRoot) {
// This should only be done once at the initial application model creation, called from Spring
List<Pair<ComponentModel, Optional<String>>> objectProvidersByName = lookObjectProvidersComponentModels(applicationModel);
List<String> createdComponentModels = new ArrayList<>();
applicationModel.executeOnEveryMuleComponentTree(cm -> {
SpringComponentModel componentModel = (SpringComponentModel) cm;
if (!mustBeRoot || componentModel.isRoot()) {
if (componentModel.getIdentifier().equals(MULE_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_DOMAIN_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_EE_DOMAIN_IDENTIFIER)) {
return;
}
SpringComponentModel parentComponentModel = componentModel.getParent() != null ? (SpringComponentModel) componentModel.getParent() : (SpringComponentModel) applicationModel.getRootComponentModel();
if (componentModel.isEnabled()) {
if (componentModel.getNameAttribute() != null && componentModel.isRoot()) {
createdComponentModels.add(componentModel.getNameAttribute());
}
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, (resolvedComponentModel, registry) -> {
SpringComponentModel resolvedSpringComponentModel = (SpringComponentModel) resolvedComponentModel;
if (resolvedComponentModel.isRoot()) {
String nameAttribute = resolvedComponentModel.getNameAttribute();
if (resolvedComponentModel.getIdentifier().equals(CONFIGURATION_IDENTIFIER)) {
nameAttribute = OBJECT_MULE_CONFIGURATION;
} else if (nameAttribute == null) {
// This may be a configuration that does not requires a name.
nameAttribute = uniqueValue(resolvedSpringComponentModel.getBeanDefinition().getBeanClassName());
}
registry.registerBeanDefinition(nameAttribute, resolvedSpringComponentModel.getBeanDefinition());
postProcessBeanDefinition(componentModel, registry, nameAttribute);
}
}, null, componentLocator);
} else {
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, null, null, componentLocator);
}
componentLocator.addComponentLocation(cm.getComponentLocation());
}
});
this.objectProviders.addAll(objectProvidersByName.stream().map(pair -> (ConfigurableObjectProvider) pair.getFirst().getObjectInstance()).collect(toList()));
registerObjectFromObjectProviders(beanFactory);
Set<String> alwaysEnabledComponents = dependencyResolver.resolveAlwaysEnabledComponents().stream().map(dependencyNode -> dependencyNode.getComponentName()).collect(toSet());
Set<String> objectProviderNames = objectProvidersByName.stream().map(Pair::getSecond).filter(Optional::isPresent).map(Optional::get).collect(toSet());
// Put object providers first, then always enabled components, then the rest
createdComponentModels.sort(Comparator.comparing(beanName -> {
if (objectProviderNames.contains(beanName)) {
return 1;
} else if (alwaysEnabledComponents.contains(beanName)) {
return 2;
} else {
return 3;
}
}));
return createdComponentModels;
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class ServerNotificationManagerConfigurator method populateNotificationTypeMappings.
public ServerNotificationManager populateNotificationTypeMappings(Map<String, Class<? extends Notification>> eventMap, Map<String, Class<? extends NotificationListener>> interfaceMap) throws InitialisationException {
Map<String, NotificationsProvider> providersMap = new HashMap<>();
for (NotificationsProvider provider : registry.lookupAllByType(NotificationsProvider.class)) {
for (Entry<String, Pair<Class<? extends Notification>, Class<? extends NotificationListener>>> entry : provider.getEventListenerMapping().entrySet()) {
final String notificationType = entry.getKey();
if (!notificationType.matches("[a-zA-Z]+:[A-Z\\-]+")) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' doesn't comply with the '[artifactID]:[NOTIFICATION-ID]' format", notificationType, provider.toString()), this);
}
if (eventMap.containsKey(notificationType)) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' is already declared for another artifact in provider '%s'.", notificationType, provider.toString(), eventMap.get(notificationType)), this);
}
eventMap.put(notificationType, entry.getValue().getFirst());
interfaceMap.put(notificationType, entry.getValue().getSecond());
providersMap.put(notificationType, provider);
}
}
ServerNotificationManager notificationManager = muleContext.getNotificationManager();
if (dynamic != null) {
notificationManager.setNotificationDynamic(dynamic.booleanValue());
}
return notificationManager;
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class IntrospectionUtils method getPagingProviderTypes.
/**
* Introspects a {@link PagingProvider} type and returns their generics.
*
* @param pagingProvider {@link PagingProvider} to introspect
* @return The {@link PagingProvider} generics.
*/
public static Pair<ResolvableType, ResolvableType> getPagingProviderTypes(ResolvableType pagingProvider) {
if (!PagingProvider.class.isAssignableFrom(pagingProvider.getRawClass())) {
throw new IllegalArgumentException("The given OutputType is not a PagingProvider");
}
ResolvableType[] generics = pagingProvider.getGenerics();
ResolvableType connectionType = null;
ResolvableType returnType = null;
if (generics.length == 0) {
for (ResolvableType resolvableType : pagingProvider.getInterfaces()) {
if (resolvableType.getRawClass().equals(PagingProvider.class)) {
connectionType = resolvableType.getGeneric(0);
returnType = resolvableType.getGeneric(1);
}
}
} else {
connectionType = generics[0];
returnType = generics[1];
}
return new Pair<>(connectionType, returnType);
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class ErrorsDeclarationEnricher method collectErrorOperations.
private List<Pair<ComponentDeclaration, MethodElement>> collectErrorOperations(ExtensionDeclaration declaration) {
List<Pair<ComponentDeclaration, MethodElement>> operations = new LinkedList<>();
new IdempotentDeclarationWalker() {
@Override
public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
addComponent(declaration);
}
@Override
protected void onConstruct(ConstructDeclaration declaration) {
addComponent(declaration);
}
private void addComponent(ComponentDeclaration<?> declaration) {
declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class).ifPresent(implementingMethodModelProperty -> operations.add(new Pair<>(declaration, implementingMethodModelProperty.getOperationMethod())));
}
}.walk(declaration);
return operations;
}
use of org.mule.runtime.api.util.Pair 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);
}
}
}
Aggregations