Search in sources :

Example 6 with DataTypeParamsBuilder

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()));
}
Also used : DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder) Test(org.junit.Test)

Example 7 with DataTypeParamsBuilder

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);
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder) Transformer(org.mule.runtime.core.api.transformer.Transformer) DiscoverableTransformer(org.mule.runtime.core.api.transformer.DiscoverableTransformer) DiscoverableTransformer(org.mule.runtime.core.api.transformer.DiscoverableTransformer)

Example 8 with DataTypeParamsBuilder

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());
    }
}
Also used : DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder)

Example 9 with DataTypeParamsBuilder

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);
}
Also used : DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder)

Aggregations

DataTypeParamsBuilder (org.mule.runtime.api.metadata.DataTypeParamsBuilder)9 Test (org.junit.Test)2 DataType (org.mule.runtime.api.metadata.DataType)2 AbstractTransformer (org.mule.runtime.core.api.transformer.AbstractTransformer)2 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 Message (org.mule.runtime.api.message.Message)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 DiscoverableTransformer (org.mule.runtime.core.api.transformer.DiscoverableTransformer)1 Transformer (org.mule.runtime.core.api.transformer.Transformer)1 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1