use of org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair in project mule by mulesoft.
the class BeanDefinitionFactory method getWrapperIdentifierAndTypeMap.
private <T> Map<String, WrapperElementType> getWrapperIdentifierAndTypeMap(ComponentBuildingDefinition<T> buildingDefinition) {
final Map<String, WrapperElementType> wrapperIdentifierAndTypeMap = new HashMap<>();
AbstractAttributeDefinitionVisitor wrapperIdentifiersCollector = new AbstractAttributeDefinitionVisitor() {
@Override
public void onComplexChildCollection(Class<?> type, Optional<String> wrapperIdentifierOptional) {
wrapperIdentifierOptional.ifPresent(wrapperIdentifier -> wrapperIdentifierAndTypeMap.put(wrapperIdentifier, COLLECTION));
}
@Override
public void onComplexChild(Class<?> type, Optional<String> wrapperIdentifierOptional, Optional<String> childIdentifier) {
wrapperIdentifierOptional.ifPresent(wrapperIdentifier -> wrapperIdentifierAndTypeMap.put(wrapperIdentifier, SINGLE));
}
@Override
public void onComplexChildMap(Class<?> keyType, Class<?> valueType, String wrapperIdentifier) {
wrapperIdentifierAndTypeMap.put(wrapperIdentifier, MAP);
}
@Override
public void onMultipleValues(KeyAttributeDefinitionPair[] definitions) {
for (KeyAttributeDefinitionPair attributeDefinition : definitions) {
attributeDefinition.getAttributeDefinition().accept(this);
}
}
};
Consumer<AttributeDefinition> collectWrappersConsumer = attributeDefinition -> attributeDefinition.accept(wrapperIdentifiersCollector);
buildingDefinition.getSetterParameterDefinitions().stream().map(setterAttributeDefinition -> setterAttributeDefinition.getAttributeDefinition()).forEach(collectWrappersConsumer);
buildingDefinition.getConstructorAttributeDefinition().stream().forEach(collectWrappersConsumer);
return wrapperIdentifierAndTypeMap;
}
use of org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair in project mule by mulesoft.
the class ExtensionDefinitionParser method parse.
/**
* Creates a list of {@link ComponentBuildingDefinition} built on copies of {@link #baseDefinitionBuilder}. It also sets the
* parsed parsed parameters on the backing {@link AbstractExtensionObjectFactory}
*
* @return a list with the generated {@link ComponentBuildingDefinition}
* @throws ConfigurationException if a parsing error occurs
*/
public final List<ComponentBuildingDefinition> parse() throws ConfigurationException {
Builder builder = baseDefinitionBuilder;
builder = doParse(builder);
AttributeDefinition parametersDefinition = fromFixedValue(new HashMap<>()).build();
if (!parameters.isEmpty()) {
KeyAttributeDefinitionPair[] attributeDefinitions = parameters.entrySet().stream().map(entry -> newBuilder().withAttributeDefinition(entry.getValue().build()).withKey(entry.getKey()).build()).toArray(KeyAttributeDefinitionPair[]::new);
parametersDefinition = fromMultipleDefinitions(attributeDefinitions).build();
}
builder = builder.withSetterParameterDefinition("parameters", parametersDefinition);
addDefinition(builder.build());
return parsedDefinitions;
}
use of org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair in project mule by mulesoft.
the class CoreComponentBuildingDefinitionProvider method getTransformersBuildingDefinitions.
private List<ComponentBuildingDefinition> getTransformersBuildingDefinitions() {
List<ComponentBuildingDefinition> transformerComponentBuildingDefinitions = new ArrayList<>();
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(XmlEntityEncoder.class).withIdentifier("xml-entity-encoder-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(XmlEntityDecoder.class).withIdentifier("xml-entity-decoder-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(GZipCompressTransformer.class).withIdentifier("gzip-compress-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(GZipUncompressTransformer.class).withIdentifier("gzip-uncompress-transformer").build());
KeyAttributeDefinitionPair strategyParameterDefinition = newBuilder().withKey("strategy").withAttributeDefinition(fromSimpleReferenceParameter("strategy-ref").build()).build();
transformerComponentBuildingDefinitions.add(getTransformerBaseBuilder(getEncryptionTransformerConfigurationFactory(EncryptionTransformer.class), EncryptionTransformer.class, strategyParameterDefinition).withIdentifier("encrypt-transformer").withNamespace(CORE_PREFIX).build());
transformerComponentBuildingDefinitions.add(getTransformerBaseBuilder(getEncryptionTransformerConfigurationFactory(DecryptionTransformer.class), DecryptionTransformer.class, strategyParameterDefinition).withIdentifier("decrypt-transformer").withNamespace(CORE_PREFIX).build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ByteArrayToHexString.class).withIdentifier("byte-array-to-hex-string-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(HexStringToByteArray.class).withIdentifier("hex-string-to-byte-array-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ByteArrayToObject.class).withIdentifier("byte-array-to-object-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ObjectToByteArray.class).withIdentifier("object-to-byte-array-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ObjectToString.class).withIdentifier("object-to-string-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ByteArrayToSerializable.class).withIdentifier("byte-array-to-serializable-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(SerializableToByteArray.class).withIdentifier("serializable-to-byte-array-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ObjectToString.class).withIdentifier("byte-array-to-string-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(ObjectToByteArray.class).withIdentifier("string-to-byte-array-transformer").build());
transformerComponentBuildingDefinitions.add(baseDefinition.withIdentifier("parse-template").withTypeDefinition(fromType(ParseTemplateProcessor.class)).withSetterParameterDefinition("content", fromChildConfiguration(String.class).withIdentifier("content").build()).withSetterParameterDefinition("target", fromSimpleParameter("target").build()).withSetterParameterDefinition("location", fromSimpleParameter("location").build()).withSetterParameterDefinition("targetValue", fromSimpleParameter("targetValue").build()).build());
transformerComponentBuildingDefinitions.add(getCoreMuleMessageTransformerBaseBuilder().withIdentifier("content").withTypeDefinition(fromType(String.class)).build());
transformerComponentBuildingDefinitions.add(getCoreTransformerBaseBuilder(AutoTransformer.class).withIdentifier("auto-transformer").build());
transformerComponentBuildingDefinitions.add(getCoreMuleMessageTransformerBaseBuilder().withIdentifier("append-string-transformer").withTypeDefinition(fromType(StringAppendTransformer.class)).withSetterParameterDefinition("message", fromSimpleParameter("message").build()).build());
transformerComponentBuildingDefinitions.add(getTransformerBaseBuilder(getCustomTransformerConfigurationFactory(), Transformer.class, newBuilder().withKey("class").withAttributeDefinition(fromSimpleParameter("class").build()).build()).withTypeDefinition(fromConfigurationAttribute("class")).withIdentifier("custom-transformer").withNamespace(CORE_PREFIX).build());
transformerComponentBuildingDefinitions.add(getTransformerBaseBuilder(getExpressionTransformerConfigurationFactory(), ExpressionTransformer.class, newBuilder().withKey("returnSourceIfNull").withAttributeDefinition(fromSimpleParameter("returnSourceIfNull").build()).build(), newBuilder().withKey("expression").withAttributeDefinition(fromSimpleParameter("expression").build()).build(), newBuilder().withKey("arguments").withAttributeDefinition(fromChildCollectionConfiguration(ExpressionArgument.class).build()).build()).withIdentifier("expression-transformer").withNamespace(CORE_PREFIX).withTypeDefinition(fromType(ExpressionTransformer.class)).build());
transformerComponentBuildingDefinitions.add(baseDefinition.withObjectFactoryType(ConfigurableObjectFactory.class).withIdentifier("return-argument").withTypeDefinition(fromType(ExpressionArgument.class)).withSetterParameterDefinition("factory", fromFixedValue(getExpressionArgumentConfigurationFactory()).build()).withSetterParameterDefinition("parameters", fromMultipleDefinitions(newBuilder().withKey("optional").withAttributeDefinition(fromSimpleParameter("optional").build()).build(), newBuilder().withKey("expression").withAttributeDefinition(fromSimpleParameter("expression").build()).build(), newBuilder().withKey("muleContext").withAttributeDefinition(fromReferenceObject(MuleContext.class).build()).build()).build()).build());
transformerComponentBuildingDefinitions.add(baseDefinition.withObjectFactoryType(ConfigurableObjectFactory.class).withIdentifier("bean-property").withTypeDefinition(fromType(ExpressionArgument.class)).withSetterParameterDefinition("factory", fromFixedValue(getExpressionArgumentConfigurationFactory()).build()).withSetterParameterDefinition("parameters", fromMultipleDefinitions(newBuilder().withKey("optional").withAttributeDefinition(fromSimpleParameter("optional").build()).build(), newBuilder().withKey("expression").withAttributeDefinition(fromSimpleParameter("expression").build()).build(), newBuilder().withKey("muleContext").withAttributeDefinition(fromReferenceObject(MuleContext.class).build()).build(), newBuilder().withKey("propertyName").withAttributeDefinition(fromSimpleParameter("property-name").build()).build()).build()).build());
return transformerComponentBuildingDefinitions;
}
Aggregations