use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class ApplicationModel method getConfigurationPropertiesProvidersFromComponents.
private List<ConfigurationPropertiesProvider> getConfigurationPropertiesProvidersFromComponents(ArtifactConfig artifactConfig, ConfigurationPropertiesResolver localResolver) {
Map<ComponentIdentifier, ConfigurationPropertiesProviderFactory> providerFactoriesMap = new HashMap<>();
ServiceLoader<ConfigurationPropertiesProviderFactory> providerFactories = java.util.ServiceLoader.load(ConfigurationPropertiesProviderFactory.class);
providerFactories.forEach(service -> {
ComponentIdentifier componentIdentifier = service.getSupportedComponentIdentifier();
if (providerFactoriesMap.containsKey(componentIdentifier)) {
throw new MuleRuntimeException(createStaticMessage("Multiple configuration providers for component: " + componentIdentifier));
}
providerFactoriesMap.put(componentIdentifier, service);
});
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = new ArrayList<>();
artifactConfig.getConfigFiles().stream().forEach(configFile -> configFile.getConfigLines().stream().forEach(configLine -> {
for (ConfigLine componentConfigLine : configLine.getChildren()) {
if (componentConfigLine.getNamespace() == null) {
continue;
}
ComponentIdentifier componentIdentifier = ComponentIdentifier.builder().namespace(componentConfigLine.getNamespace()).name(componentConfigLine.getIdentifier()).build();
if (!providerFactoriesMap.containsKey(componentIdentifier)) {
continue;
}
DefaultConfigurationParameters.Builder configurationParametersBuilder = DefaultConfigurationParameters.builder();
ConfigurationParameters configurationParameters = resolveConfigurationParameters(configurationParametersBuilder, componentConfigLine, localResolver);
ConfigurationPropertiesProvider provider = providerFactoriesMap.get(componentIdentifier).createProvider(configurationParameters, externalResourceProvider);
if (provider instanceof Component) {
Component providerComponent = (Component) provider;
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(UNKNOWN).identifier(componentIdentifier).build();
DefaultComponentLocation.DefaultLocationPart locationPart = new DefaultComponentLocation.DefaultLocationPart(componentIdentifier.getName(), of(typedComponentIdentifier), of(configFile.getFilename()), of(configLine.getLineNumber()));
providerComponent.setAnnotations(ImmutableMap.<QName, Object>builder().put(AbstractComponent.LOCATION_KEY, new DefaultComponentLocation(of(componentIdentifier.getName()), singletonList(locationPart))).build());
}
configConfigurationPropertiesProviders.add(provider);
try {
initialiseIfNeeded(provider);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
}));
return configConfigurationPropertiesProviders;
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class TestParsersComponentBuildingDefinitionProvider method getComponentBuildingDefinitions.
@Override
public List<ComponentBuildingDefinition> getComponentBuildingDefinitions() {
List<ComponentBuildingDefinition> definitions = new ArrayList<>();
ComponentBuildingDefinition.Builder baseBuilder = new ComponentBuildingDefinition.Builder().withNamespace(TestParsersNamespaceInfoProvider.PARSERS_TEST_NAMESPACE);
ComponentBuildingDefinition.Builder baseParameterCollectionParserBuilder = baseBuilder.withTypeDefinition(fromType(ParsersTestObject.class)).asNamed().withSetterParameterDefinition("simpleTypeWithConverter", fromChildConfiguration(String.class).build()).withSetterParameterDefinition("simpleTypeList", fromChildConfiguration(List.class).withWrapperIdentifier("simple-type-child-list").build()).withSetterParameterDefinition("simpleTypeListWithConverter", fromChildConfiguration(List.class).withWrapperIdentifier("simple-type-child-list-with-converter").build()).withSetterParameterDefinition("simpleTypeSet", fromChildConfiguration(Set.class).withWrapperIdentifier("simple-type-child-set").build()).withSetterParameterDefinition("simpleTypeMap", fromChildMapConfiguration(String.class, Integer.class).withWrapperIdentifier("simple-type-map").build()).withSetterParameterDefinition("simpleListTypeMap", fromChildMapConfiguration(String.class, String.class).withWrapperIdentifier("simple-list-type-map").build()).withSetterParameterDefinition("complexTypeMap", fromChildMapConfiguration(Long.class, ParsersTestObject.class).withWrapperIdentifier("complex-type-map").build()).withSetterParameterDefinition("simpleParameters", fromMultipleDefinitions(newBuilder().withAttributeDefinition(fromSimpleParameter("firstname").build()).withKey("firstname").build(), newBuilder().withAttributeDefinition(fromSimpleParameter("lastname").build()).withKey("lastname").build(), newBuilder().withAttributeDefinition(fromSimpleParameter("age").build()).withKey("age").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(ParsersTestObject.class).withWrapperIdentifier("first-child").build()).withKey("first-child").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(ParsersTestObject.class).withWrapperIdentifier("second-child").build()).withKey("second-child").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-children").build()).withKey("other-children").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-children-custom-collection-type").build()).withKey("other-children-custom-collection-type").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-simple-type-child-list").build()).withKey("other-simple-type-child-list-custom-key").build()).build());
definitions.add(baseParameterCollectionParserBuilder.withIdentifier("parameter-collection-parser").build());
definitions.add(baseParameterCollectionParserBuilder.withIdentifier("elementTypeA").build());
definitions.add(baseParameterCollectionParserBuilder.withIdentifier("anotherElementTypeA").build());
definitions.add(baseBuilder.withIdentifier("simple-type-child-list").withTypeDefinition(fromType(List.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-type-child-list-with-converter").withTypeDefinition(fromType(List.class)).build());
definitions.add(baseBuilder.withIdentifier("other-children-custom-collection-type").withTypeDefinition(fromType(LinkedList.class)).build());
definitions.add(baseBuilder.withIdentifier("other-children").withTypeDefinition(fromType(List.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-type-child-set").withTypeDefinition(fromType(TreeSet.class)).build());
definitions.add(baseBuilder.withIdentifier("other-simple-type-child-list").withTypeDefinition(fromType(List.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-type-child").withTypeDefinition(fromType(String.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-type-child-with-converter").withTypeDefinition(fromType(String.class)).withTypeConverter(input -> input + "-with-converter").build());
definitions.add(baseBuilder.withIdentifier("simple-type-map").withTypeDefinition(fromType(TreeMap.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-type-entry").withTypeDefinition(fromMapEntryType(String.class, Integer.class)).withKeyTypeConverter(input -> input + "-with-converter").withTypeConverter(input -> valueOf((String) input) + 1).build());
definitions.add(baseBuilder.withIdentifier("simple-list-type-map").withTypeDefinition(fromType(Map.class)).build());
definitions.add(baseBuilder.withIdentifier("simple-list-entry").withTypeDefinition(fromMapEntryType(String.class, List.class)).build());
definitions.add(baseBuilder.withIdentifier("complex-type-map").withTypeDefinition(fromType(Map.class)).build());
definitions.add(baseBuilder.withIdentifier("complex-type-entry").withTypeDefinition(fromMapEntryType(Long.class, ParsersTestObject.class)).build());
definitions.add(baseBuilder.withIdentifier("global-element-with-object-factory").withTypeDefinition(fromType(LifecycleSensingMessageProcessor.class)).withObjectFactoryType(LifecycleSensingObjectFactory.class).build());
definitions.add(baseBuilder.withIdentifier("inner-element-with-object-factory").withTypeDefinition(fromType(LifecycleSensingMessageProcessor.class)).withObjectFactoryType(LifecycleSensingObjectFactory.class).build());
definitions.add(baseBuilder.withIdentifier("element-with-attribute-and-child").withTypeDefinition(fromType(ParameterAndChildElement.class)).withSetterParameterDefinition("simplePojo", fromSimpleParameter("myPojo", input -> new SimplePojo((String) input)).withDefaultValue("jose").build()).withSetterParameterDefinition("simplePojo", fromChildConfiguration(SimplePojo.class).build()).build());
definitions.add(baseBuilder.withIdentifier("my-pojo").withTypeDefinition(fromType(SimplePojo.class)).withSetterParameterDefinition("someParameter", fromSimpleParameter("someParameter").build()).build());
definitions.add(baseBuilder.withIdentifier("text-pojo").withTypeDefinition(fromType(SimplePojo.class)).withSetterParameterDefinition("someParameter", fromChildConfiguration(String.class).withIdentifier("text").build()).build());
definitions.add(baseBuilder.withIdentifier("text").withTypeDefinition(fromType(String.class)).build());
definitions.add(baseBuilder.withIdentifier("same-child-type-container").withTypeDefinition(fromType(PojoWithSameTypeChildren.class)).withSetterParameterDefinition("elementTypeA", fromChildConfiguration(ParsersTestObject.class).withIdentifier("elementTypeA").build()).withSetterParameterDefinition("anotherElementTypeA", fromChildConfiguration(ParsersTestObject.class).withIdentifier("anotherElementTypeA").build()).build());
definitions.add(baseBuilder.withIdentifier("simple-type").withTypeConverter(o -> new SimplePojo((String) o)).withTypeDefinition(fromType(String.class)).build());
definitions.add(baseBuilder.withIdentifier("component-created-with-object-factory").withObjectFactoryType(TestObjectFactory.class).withTypeDefinition(fromType(TestObject.class)).build());
definitions.add(baseBuilder.withIdentifier("composite-processor-chain-router").withTypeDefinition(fromType(CompositeProcessorChainRouter.class)).withSetterParameterDefinition("processorChains", fromChildCollectionConfiguration(Object.class).build()).build());
definitions.add(baseBuilder.withIdentifier("chain").withTypeDefinition(fromType(Component.class)).withObjectFactoryType(MessageProcessorChainObjectFactory.class).withSetterParameterDefinition("messageProcessors", fromChildCollectionConfiguration(Object.class).build()).build());
definitions.add(baseBuilder.withIdentifier("processor-chain-router").withTypeDefinition(fromType(ProcessorChainRouter.class)).withSetterParameterDefinition("processors", fromChildCollectionConfiguration(Object.class).build()).build());
return definitions;
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class ConnectionlessMessageSourceTestCase method obtainDisconnectedSourceConfigParameters.
@Test
public void obtainDisconnectedSourceConfigParameters() throws Exception {
Component element = locator.find(Location.builder().globalName("source").addSourcePart().build()).get();
assertThat(element, is(instanceOf(ConfiguredComponent.class)));
final ConfigurationInstance configurationInstance = ((ConfiguredComponent) element).getConfigurationInstance().get();
ConfigurationState configurationState = configurationInstance.getState();
assertThat(configurationState.getConfigParameters().size(), is(0));
assertThat(configurationState.getConnectionParameters().size(), is(0));
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class HeisenbergMessageSourceTestCase method obtainSourceParameters.
@Test
public void obtainSourceParameters() throws Exception {
Component element = locator.find(Location.builder().globalName("source").addSourcePart().build()).get();
assertThat(element, is(instanceOf(ParameterizedSource.class)));
ParameterizedSource source = (ParameterizedSource) element;
Map<String, Object> parameters = source.getInitialisationParameters();
assertThat(parameters.get("initialBatchNumber"), is(0));
assertThat(parameters.get("corePoolSize"), is(1));
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class HeisenbergMessageSourceTestCase method obtainSourceConfigParameters.
@Test
public void obtainSourceConfigParameters() throws Exception {
Component element = locator.find(Location.builder().globalName("source").addSourcePart().build()).get();
assertThat(element, is(instanceOf(ConfiguredComponent.class)));
ConfiguredComponent source = (ConfiguredComponent) element;
ConfigurationState configurationState = source.getConfigurationInstance().get().getState();
Map<String, Object> configParameters = configurationState.getConfigParameters();
assertThat(configParameters.size(), is(13));
assertParameter(configParameters, "enemies", hasSize(0));
assertParameter(configParameters, "monthlyIncomes", hasSize(2));
assertParameter(configParameters, "cancer", is(true));
assertParameter(configParameters, "money", equalTo(new BigDecimal("0")));
assertParameter(configParameters, "initialHealth", is(CANCER));
assertParameter(configParameters, "endingHealth", is(CANCER));
assertParameter(configParameters, "name", is("Heisenberg"));
assertParameter(configParameters, "age", is(50));
assertParameter(configParameters, "brotherInLaw", is(notNullValue()));
Map<String, Object> connectionParameters = configurationState.getConnectionParameters();
assertThat(connectionParameters.size(), is(2));
assertParameter(connectionParameters, "saulPhoneNumber", equalTo(SAUL_OFFICE_NUMBER));
}
Aggregations