Skip to content

Commit

Permalink
Add support for configuring the bean and json node EL Resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Sep 25, 2023
1 parent 09fe1bd commit 6c5b934
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import javax.sql.DataSource;

Expand Down Expand Up @@ -134,6 +135,7 @@ public class AppEngineConfiguration extends AbstractEngineConfiguration implemen
protected DeploymentCache<AppDefinitionCacheEntry> appDefinitionCache;

protected ExpressionManager expressionManager;
protected Collection<Consumer<ExpressionManager>> expressionManagerConfigurers;
protected SchemaManager identityLinkSchemaManager;
protected SchemaManager variableSchemaManager;

Expand Down Expand Up @@ -284,6 +286,10 @@ public void initMybatisTypeHandlers(Configuration configuration) {
public void initExpressionManager() {
if (expressionManager == null) {
expressionManager = new DefaultExpressionManager(beans);

if (expressionManagerConfigurers != null) {
expressionManagerConfigurers.forEach(configurer -> configurer.accept(expressionManager));
}
}
}

Expand Down Expand Up @@ -688,6 +694,19 @@ public AppEngineConfiguration setExpressionManager(ExpressionManager expressionM
return this;
}

public Collection<Consumer<ExpressionManager>> getExpressionManagerConfigurers() {
return expressionManagerConfigurers;
}

@Override
public AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer) {
if (this.expressionManagerConfigurers == null) {
this.expressionManagerConfigurers = new ArrayList<>();
}
this.expressionManagerConfigurers.add(configurer);
return this;
}

public SchemaManager getIdentityLinkSchemaManager() {
return identityLinkSchemaManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Consumer;

import javax.sql.DataSource;

Expand Down Expand Up @@ -418,6 +419,7 @@ public class CmmnEngineConfiguration extends AbstractEngineConfiguration impleme
protected boolean enableCaseDefinitionHistoryLevel;

protected ExpressionManager expressionManager;
protected Collection<Consumer<ExpressionManager>> expressionManagerConfigurers;
protected List<FlowableFunctionDelegate> flowableFunctionDelegates;
protected List<FlowableFunctionDelegate> customFlowableFunctionDelegates;
protected List<FlowableAstFunctionCreator> astFunctionCreators;
Expand Down Expand Up @@ -949,6 +951,10 @@ public void initExpressionManager() {
cmmnExpressionManager.setExpressionCache(new DefaultDeploymentCache<>(expressionCacheSize));
cmmnExpressionManager.setExpressionTextLengthCacheLimit(expressionTextLengthCacheLimit);
}

if (expressionManagerConfigurers != null) {
expressionManagerConfigurers.forEach(configurer -> configurer.accept(cmmnExpressionManager));
}

expressionManager = cmmnExpressionManager;
}
Expand Down Expand Up @@ -2638,6 +2644,19 @@ public CmmnEngineConfiguration setExpressionManager(ExpressionManager expression
return this;
}

public Collection<Consumer<ExpressionManager>> getExpressionManagerConfigurers() {
return expressionManagerConfigurers;
}

@Override
public AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer) {
if (this.expressionManagerConfigurers == null) {
this.expressionManagerConfigurers = new ArrayList<>();
}
this.expressionManagerConfigurers.add(configurer);
return this;
}

public boolean isExpressionCacheEnabled() {
return isExpressionCacheEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.sql.DataSource;

Expand Down Expand Up @@ -149,6 +150,7 @@ public class DmnEngineConfiguration extends AbstractEngineConfiguration

// EXPRESSION MANAGER /////////////////////////////////////////////
protected ExpressionManager expressionManager;
protected Collection<Consumer<ExpressionManager>> expressionManagerConfigurers;
protected List<FlowableFunctionDelegate> flowableFunctionDelegates;
protected List<FlowableFunctionDelegate> customFlowableFunctionDelegates;
protected Collection<ELResolver> preDefaultELResolvers;
Expand Down Expand Up @@ -451,6 +453,10 @@ public void initExpressionManager() {
postDefaultELResolvers.forEach(dmnExpressionManager::addPostDefaultResolver);
}

if (expressionManagerConfigurers != null) {
expressionManagerConfigurers.forEach(configurer -> configurer.accept(dmnExpressionManager));
}

expressionManager = dmnExpressionManager;
}

Expand Down Expand Up @@ -819,6 +825,19 @@ public DmnEngineConfiguration setExpressionManager(ExpressionManager expressionM
return this;
}

public Collection<Consumer<ExpressionManager>> getExpressionManagerConfigurers() {
return expressionManagerConfigurers;
}

@Override
public AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer) {
if (this.expressionManagerConfigurers == null) {
this.expressionManagerConfigurers = new ArrayList<>();
}
this.expressionManagerConfigurers.add(configurer);
return this;
}

public List<FlowableFunctionDelegate> getFlowableFunctionDelegates() {
return flowableFunctionDelegates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.flowable.common.engine.impl;

import java.util.function.Consumer;

import org.flowable.common.engine.impl.el.ExpressionManager;

/**
Expand All @@ -22,4 +24,6 @@ public interface HasExpressionManagerEngineConfiguration {
ExpressionManager getExpressionManager();

AbstractEngineConfiguration setExpressionManager(ExpressionManager expressionManager);

AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public class DefaultExpressionManager implements ExpressionManager {
protected int expressionTextLengthCacheLimit = -1;

protected List<ELResolver> preDefaultResolvers;
protected ELResolver jsonNodeResolver;
protected List<ELResolver> postDefaultResolvers;
protected List<ELResolver> preBeanResolvers;
protected ELResolver beanResolver;

protected ELResolver staticElResolver;

Expand Down Expand Up @@ -134,7 +136,10 @@ protected List<ELResolver> createDefaultElResolvers() {
elResolvers.add(new ArrayELResolver());
elResolvers.add(new ListELResolver());
elResolvers.add(new MapELResolver());
elResolvers.add(new JsonNodeELResolver());
ELResolver jsonNodeElResolver = createJsonNodeElResolver();
if (jsonNodeElResolver != null) {
elResolvers.add(jsonNodeElResolver);
}
if (preBeanResolvers != null) {
elResolvers.addAll(preBeanResolvers);
}
Expand All @@ -156,9 +161,13 @@ protected List<ELResolver> createDefaultElResolvers() {
protected ELResolver createVariableElResolver() {
return new VariableContainerELResolver();
}

protected ELResolver createJsonNodeElResolver() {
return jsonNodeResolver == null ? new JsonNodeELResolver() : jsonNodeResolver;
}

protected ELResolver createBeanElResolver() {
return new BeanELResolver();
return beanResolver == null ? new BeanELResolver() : beanResolver;
}

@Override
Expand Down Expand Up @@ -243,6 +252,16 @@ public void addPreDefaultResolver(ELResolver elResolver) {
this.preDefaultResolvers.add(elResolver);
}

public ELResolver getJsonNodeResolver() {
return jsonNodeResolver;
}

public void setJsonNodeResolver(ELResolver jsonNodeResolver) {
// When the bean resolver is modified we need to reset the el resolver
this.staticElResolver = null;
this.jsonNodeResolver = jsonNodeResolver;
}

public void addPostDefaultResolver(ELResolver elResolver) {
if (this.postDefaultResolvers == null) {
this.postDefaultResolvers = new ArrayList<>();
Expand All @@ -258,5 +277,14 @@ public void addPreBeanResolver(ELResolver elResolver) {

this.preBeanResolvers.add(elResolver);
}


public ELResolver getBeanResolver() {
return beanResolver;
}

public void setBeanResolver(ELResolver beanResolver) {
// When the bean resolver is modified we need to reset the el resolver
this.staticElResolver = null;
this.beanResolver = beanResolver;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public Object getValue(ELContext context, Object base, Object property) {
Method method = beanProperty.getReadMethod(base);
if (method != null) {
try {
result = method.invoke(base);
result = invoke(method, base);
} catch (InvocationTargetException e) {
throw new ELException(e.getCause());
} catch (Exception e) {
Expand Down Expand Up @@ -385,7 +385,7 @@ public void setValue(ELContext context, Object base, Object property, Object val
throw new PropertyNotWritableException("Cannot write property: " + property);
}
try {
method.invoke(base, value);
invoke(method, base, value);
} catch (InvocationTargetException e) {
throw new ELException("Cannot write property: " + property, e.getCause());
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -473,7 +473,7 @@ public Object invoke(ELContext context, Object base, Object method, Class<?>[] p

Object[] parameters = Util.buildParameters(target.getParameterTypes(), target.isVarArgs(), params, factory);
try {
result = target.invoke(base, parameters);
result = invoke(target, base, parameters);
} catch (InvocationTargetException e) {
throw new ELException(e.getCause());
} catch (IllegalAccessException e) {
Expand All @@ -484,6 +484,10 @@ public Object invoke(ELContext context, Object base, Object method, Class<?>[] p
return result;
}

protected Object invoke(Method target, Object base, Object... parameters) throws InvocationTargetException, IllegalAccessException {
return target.invoke(base, parameters);
}

/**
* Lookup an expression factory used to coerce method parameters in context under key
* <code>"javax.el.ExpressionFactory"</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Consumer;

import javax.xml.namespace.QName;

Expand All @@ -47,6 +48,7 @@
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
import org.flowable.common.engine.impl.EngineConfigurator;
import org.flowable.common.engine.impl.EngineDeployer;
import org.flowable.common.engine.impl.HasExpressionManagerEngineConfiguration;
Expand Down Expand Up @@ -721,6 +723,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
protected boolean parallelMultiInstanceAsyncLeave = true;

protected ExpressionManager expressionManager;
protected Collection<Consumer<ExpressionManager>> expressionManagerConfigurers;
protected Collection<ELResolver> preDefaultELResolvers;
protected Collection<ELResolver> preBeanELResolvers;
protected Collection<ELResolver> postDefaultELResolvers;
Expand Down Expand Up @@ -2367,6 +2370,10 @@ public void initExpressionManager() {
postDefaultELResolvers.forEach(processExpressionManager::addPostDefaultResolver);
}

if (expressionManagerConfigurers != null) {
expressionManagerConfigurers.forEach(configurer -> configurer.accept(processExpressionManager));
}

expressionManager = processExpressionManager;
}
expressionManager.setFunctionDelegates(flowableFunctionDelegates);
Expand Down Expand Up @@ -3261,6 +3268,19 @@ public ProcessEngineConfigurationImpl setExpressionManager(ExpressionManager exp
return this;
}

public Collection<Consumer<ExpressionManager>> getExpressionManagerConfigurers() {
return expressionManagerConfigurers;
}

@Override
public AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer) {
if (this.expressionManagerConfigurers == null) {
this.expressionManagerConfigurers = new ArrayList<>();
}
this.expressionManagerConfigurers.add(configurer);
return this;
}

public boolean isExpressionCacheEnabled() {
return isExpressionCacheEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.flowable.common.engine.api.scope.ScopeTypes;
import org.flowable.common.engine.impl.AbstractEngineConfiguration;
Expand Down Expand Up @@ -123,6 +124,7 @@ public class EventRegistryEngineConfiguration extends AbstractEngineConfiguratio
protected EventResourceEntityManager resourceEntityManager;

protected ExpressionManager expressionManager;
protected Collection<Consumer<ExpressionManager>> expressionManagerConfigurers;
protected Collection<ELResolver> preDefaultELResolvers;
protected Collection<ELResolver> preBeanELResolvers;
protected Collection<ELResolver> postDefaultELResolvers;
Expand Down Expand Up @@ -291,6 +293,10 @@ public void initExpressionManager() {
postDefaultELResolvers.forEach(eventRegistryExpressionManager::addPostDefaultResolver);
}

if (expressionManagerConfigurers != null) {
expressionManagerConfigurers.forEach(configurer -> configurer.accept(eventRegistryExpressionManager));
}

expressionManager = eventRegistryExpressionManager;
}
}
Expand Down Expand Up @@ -906,6 +912,19 @@ public EventRegistryEngineConfiguration setExpressionManager(ExpressionManager e
return this;
}

public Collection<Consumer<ExpressionManager>> getExpressionManagerConfigurers() {
return expressionManagerConfigurers;
}

@Override
public AbstractEngineConfiguration addExpressionManagerConfigurer(Consumer<ExpressionManager> configurer) {
if (this.expressionManagerConfigurers == null) {
this.expressionManagerConfigurers = new ArrayList<>();
}
this.expressionManagerConfigurers.add(configurer);
return this;
}

public Collection<ELResolver> getPreDefaultELResolvers() {
return preDefaultELResolvers;
}
Expand Down

0 comments on commit 6c5b934

Please sign in to comment.