use of org.mule.runtime.api.metadata.DataTypeParamsBuilder in project mule by mulesoft.
the class DataTypeBuilderTestCase method cachedInstances.
@Test
public void cachedInstances() {
final DataTypeParamsBuilder builder1 = DataType.builder().type(String.class);
final DataTypeParamsBuilder builder2 = DataType.builder().type(String.class);
assertThat(builder1, equalTo(builder2));
assertThat(builder1.build(), sameInstance(builder2.build()));
}
use of org.mule.runtime.api.metadata.DataTypeParamsBuilder in project mule by mulesoft.
the class SimpleRegistryBootstrap method doRegisterTransformer.
@Override
protected void doRegisterTransformer(TransformerBootstrapProperty bootstrapProperty, Class<?> returnClass, Class<? extends Transformer> transformerClass) throws Exception {
Transformer trans = ClassUtils.instantiateClass(transformerClass);
if (!(trans instanceof DiscoverableTransformer)) {
throw new RegistrationException(CoreMessages.transformerNotImplementDiscoverable(trans));
}
if (returnClass != null) {
DataTypeParamsBuilder builder = DataType.builder().type(returnClass);
if (isNotEmpty(bootstrapProperty.getMimeType())) {
builder = builder.mediaType(bootstrapProperty.getMimeType());
}
trans.setReturnDataType(builder.build());
}
if (bootstrapProperty.getName() != null) {
trans.setName(bootstrapProperty.getName());
} else {
// Prefixes the generated default name to ensure there is less chance of conflict if the user registers
// the transformer with the same name
trans.setName("_" + trans.getName());
}
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(trans);
}
use of org.mule.runtime.api.metadata.DataTypeParamsBuilder in project mule by mulesoft.
the class AddVariablePropertyConfigurator method configure.
/**
* Configures the common parameters of every transformer.
*
* @param propVarSetterInstance the transformar instance
* @param parameters the set of parameters configured in the component model according to the
* {@link org.mule.runtime.dsl.api.component.ComponentBuildingDefinition}
*/
@Override
public void configure(AbstractAddVariablePropertyProcessor propVarSetterInstance, Map<String, Object> parameters) {
String mimeType = (String) parameters.get("mimeType");
String encoding = (String) parameters.get("encoding");
if (mimeType != null) {
DataTypeParamsBuilder builder = DataType.builder();
if (isNotEmpty(mimeType)) {
builder.mediaType(mimeType);
}
propVarSetterInstance.setReturnDataType(builder.charset(encoding).build());
}
}
use of org.mule.runtime.api.metadata.DataTypeParamsBuilder in project mule by mulesoft.
the class TransformerConfigurator method configure.
/**
* Configures the common parameters of every transformer.
*
* @param transformerInstance the transformar instance
* @param parameters the set of parameters configured in the component model according to the
* {@link org.mule.runtime.dsl.api.component.ComponentBuildingDefinition}
*/
@Override
public void configure(AbstractTransformer transformerInstance, Map<String, Object> parameters) {
String returnClass = (String) parameters.get("returnClass");
String mimeType = (String) parameters.get("mimeType");
String name = (String) parameters.get("name");
String encoding = (String) parameters.get("encoding");
Boolean ignoreBadInput = parameters.get("ignoreBadInput") == null ? null : Boolean.valueOf((String) parameters.get("ignoreBadInput"));
if (returnClass != null || mimeType != null) {
DataTypeParamsBuilder builder = DataType.builder().type(getReturnType(returnClass));
if (isNotEmpty(mimeType)) {
builder.mediaType(mimeType);
}
transformerInstance.setReturnDataType(builder.charset(encoding).build());
}
if (ignoreBadInput != null) {
transformerInstance.setIgnoreBadInput(ignoreBadInput);
}
transformerInstance.setName(name);
}
Aggregations