Search in sources :

Example 1 with DiscoverableTransformer

use of org.mule.runtime.core.api.transformer.DiscoverableTransformer 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)

Aggregations

DataTypeParamsBuilder (org.mule.runtime.api.metadata.DataTypeParamsBuilder)1 DiscoverableTransformer (org.mule.runtime.core.api.transformer.DiscoverableTransformer)1 Transformer (org.mule.runtime.core.api.transformer.Transformer)1 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)1