Search in sources :

Example 1 with FunctionExecutor

use of org.mule.runtime.module.extension.internal.runtime.function.FunctionExecutor in project mule by mulesoft.

the class ExtensionActivator method registerExpressionFunctions.

private void registerExpressionFunctions(Stream<FunctionModel> functions, ExpressionModule.Builder module) {
    final FunctionParameterDefaultValueResolverFactory valueResolverFactory = (defaultValue, type) -> context -> {
        ExtendedExpressionManager em = muleContext.getExpressionManager();
        String value = String.valueOf(defaultValue);
        return em.isExpression(value) ? em.evaluate(value, type, context) : new TypedValue<>(defaultValue, type);
    };
    functions.forEach(function -> function.getModelProperty(FunctionExecutorModelProperty.class).ifPresent(mp -> {
        FunctionExecutor executor = mp.getExecutorFactory().createExecutor(function, valueResolverFactory);
        lifecycleAwareElements.add(executor);
        module.addBinding(function.getName(), new TypedValue<>(executor, fromFunction(executor)));
    }));
}
Also used : IntrospectionUtils.getSubtypeClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getSubtypeClasses) FunctionModel(org.mule.runtime.api.meta.model.function.FunctionModel) IntrospectionUtils.getParameterClasses(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getParameterClasses) FunctionExecutor(org.mule.runtime.module.extension.internal.runtime.function.FunctionExecutor) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) BindingContext(org.mule.runtime.api.el.BindingContext) StringToEnum(org.mule.runtime.core.internal.transformer.simple.StringToEnum) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) DefaultExpressionModuleBuilder(org.mule.runtime.core.internal.el.DefaultExpressionModuleBuilder) HashSet(java.util.HashSet) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) FunctionExecutorModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty) BeanUtils.getName(org.mule.runtime.core.privileged.util.BeanUtils.getName) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) LinkedList(java.util.LinkedList) Startable(org.mule.runtime.api.lifecycle.Startable) FunctionParameterDefaultValueResolverFactory(org.mule.runtime.module.extension.internal.runtime.function.FunctionParameterDefaultValueResolverFactory) DataType.fromFunction(org.mule.runtime.api.metadata.DataType.fromFunction) DefaultBindingContextBuilder(org.mule.runtime.core.internal.el.DefaultBindingContextBuilder) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Set(java.util.Set) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Transformer(org.mule.runtime.core.api.transformer.Transformer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) TypedValue(org.mule.runtime.api.metadata.TypedValue) List(java.util.List) Stream(java.util.stream.Stream) ExpressionModule(org.mule.runtime.api.el.ExpressionModule) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) LegacyRegistryUtils.registerObject(org.mule.runtime.core.privileged.registry.LegacyRegistryUtils.registerObject) ModuleNamespace(org.mule.runtime.api.el.ModuleNamespace) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) GlobalBindingContextProvider(org.mule.runtime.core.privileged.el.GlobalBindingContextProvider) FunctionParameterDefaultValueResolverFactory(org.mule.runtime.module.extension.internal.runtime.function.FunctionParameterDefaultValueResolverFactory) FunctionExecutor(org.mule.runtime.module.extension.internal.runtime.function.FunctionExecutor) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) TypedValue(org.mule.runtime.api.metadata.TypedValue)

Aggregations

HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 BindingContext (org.mule.runtime.api.el.BindingContext)1 ExpressionModule (org.mule.runtime.api.el.ExpressionModule)1 ModuleNamespace (org.mule.runtime.api.el.ModuleNamespace)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 FunctionModel (org.mule.runtime.api.meta.model.function.FunctionModel)1 DataType.fromFunction (org.mule.runtime.api.metadata.DataType.fromFunction)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 ExtendedExpressionManager (org.mule.runtime.core.api.el.ExtendedExpressionManager)1 LifecycleUtils.initialiseIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded)1