Search in sources :

Example 6 with DefaultComponentLocation

use of org.mule.runtime.dsl.api.component.config.DefaultComponentLocation in project mule by mulesoft.

the class ComponentLocationVisitor method accept.

/**
 * For every {@link ComponentModel} in the configuration, sets the {@link DefaultComponentLocation} associated within an
 * annotation under the key {@link AbstractComponent#LOCATION_KEY}.
 *
 * @param componentModel the component model that will be assign it's {@link DefaultComponentLocation}.
 */
@Override
public void accept(ComponentModel componentModel) {
    if (componentModel.getParent() == null) {
        // do not process root element
        return;
    }
    DefaultComponentLocation componentLocation;
    Optional<TypedComponentIdentifier> typedComponentIdentifier = of(builder().identifier(componentModel.getIdentifier()).type(componentModel.getComponentType().orElse(UNKNOWN)).build());
    if (componentModel.isRoot()) {
        String componentModelNameAttribute = componentModel.getNameAttribute();
        ImmutableList<DefaultLocationPart> parts = ImmutableList.<DefaultLocationPart>builder().add(new DefaultLocationPart(componentModelNameAttribute, typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber())).build();
        componentLocation = new DefaultComponentLocation(ofNullable(componentModelNameAttribute), parts);
    } else if (existsWithinRootContainer(componentModel)) {
        ComponentModel parentComponentModel = componentModel.getParent();
        DefaultComponentLocation parentComponentLocation = parentComponentModel.getComponentLocation();
        if (isHttpProxyPart(componentModel)) {
            componentLocation = parentComponentLocation.appendLocationPart(componentModel.getIdentifier().getName(), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
        } else if (isRootProcessorScope(parentComponentModel)) {
            componentLocation = processFlowDirectChild(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (isMunitFlowIdentifier(parentComponentModel)) {
            componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
        } else if (isErrorHandler(componentModel)) {
            componentLocation = processErrorHandlerComponent(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (isTemplateOnErrorHandler(componentModel)) {
            componentLocation = processOnErrorModel(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (parentComponentIsRouter(componentModel)) {
            if (isRoute(componentModel)) {
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(SCOPE).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else if (isProcessor(componentModel)) {
                // this is the case of the routes directly inside the router as with scatter-gather
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findProcessorPath(componentModel), empty(), empty(), empty()).appendProcessorsPart().appendLocationPart("0", typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else {
                // this is the case of the when element inside the choice
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), empty(), empty());
            }
        } else if (isProcessor(componentModel)) {
            if (isModuleOperation(componentModel.getParent())) {
                final Optional<TypedComponentIdentifier> operationTypedIdentifier = ApplicationModel.MODULE_OPERATION_CHAIN.equals(typedComponentIdentifier.get().getIdentifier()) ? getModuleOperationTypeComponentIdentifier(componentModel) : typedComponentIdentifier;
                componentLocation = processModuleOperationChildren(componentModel, operationTypedIdentifier);
            } else {
                componentLocation = parentComponentLocation.appendProcessorsPart().appendLocationPart(findProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            }
        } else {
            if (isBatchAggregator(componentModel)) {
                componentLocation = parentComponentLocation.appendLocationPart(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER.getName(), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else {
                componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            }
        }
    } else {
        DefaultComponentLocation parentComponentLocation = componentModel.getParent().getComponentLocation();
        componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
    }
    componentModel.setComponentLocation(componentLocation);
}
Also used : DefaultLocationPart(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart) Optional(java.util.Optional) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)

Aggregations

DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)6 TypedComponentIdentifier (org.mule.runtime.api.component.TypedComponentIdentifier)3 Optional (java.util.Optional)2 Component (org.mule.runtime.api.component.Component)2 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)2 Joiner.on (com.google.common.base.Joiner.on)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional.empty (java.util.Optional.empty)1