-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from powerflows/develop
Develop
- Loading branch information
Showing
106 changed files
with
5,657 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ | |
# Others | ||
target/ | ||
.settings/ | ||
bin/ | ||
bin/ | ||
/.attach_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../dmn/engine/evaluator/expression/provider/DefaultExpressionEvaluationProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2018-present PowerFlows.org - all rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.powerflows.dmn.engine.evaluator.expression.provider; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.powerflows.dmn.engine.model.decision.expression.ExpressionType; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Optional; | ||
import java.util.ServiceLoader; | ||
|
||
@Slf4j | ||
public class DefaultExpressionEvaluationProviderFactory { | ||
|
||
private static final ServiceLoader<ExpressionEvaluationProviderFactory> serviceLoader = ServiceLoader.load(ExpressionEvaluationProviderFactory.class); | ||
|
||
private final EnumMap<ExpressionType, ExpressionEvaluationProviderFactory> factories = new EnumMap<>(ExpressionType.class); | ||
|
||
private final EnumMap<ExpressionType, ExpressionEvaluationProvider> providers = new EnumMap<>(ExpressionType.class); | ||
private final ExpressionEvaluationConfiguration configuration; | ||
|
||
|
||
public DefaultExpressionEvaluationProviderFactory() { | ||
this(ExpressionEvaluationConfiguration.simpleConfiguration()); | ||
} | ||
|
||
public DefaultExpressionEvaluationProviderFactory(final ExpressionEvaluationConfiguration configuration) { | ||
this.configuration = configuration; | ||
serviceLoader.forEach(provider -> | ||
provider.supportedExpressionTypes() | ||
.forEach(type -> { | ||
log.debug("Found ExpressionEvaluationProvider for type {} - {}", type, provider); | ||
factories.put(type, provider); | ||
} | ||
) | ||
); | ||
} | ||
|
||
public ExpressionEvaluationProvider getInstance(final ExpressionType expressionType) { | ||
final ExpressionEvaluationProvider expressionEvaluationProvider = providers.computeIfAbsent(expressionType, key -> Optional | ||
.ofNullable(factories.get(key)) | ||
.map(factory -> factory.createProvider(configuration)) | ||
.orElse(null) | ||
); | ||
|
||
if (expressionEvaluationProvider == null) { | ||
throw new IllegalArgumentException("Unknown expression type " + expressionType); | ||
} | ||
|
||
return expressionEvaluationProvider; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...owerflows/dmn/engine/evaluator/expression/provider/ExpressionEvaluationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2018-present PowerFlows.org - all rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.powerflows.dmn.engine.evaluator.expression.provider; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.powerflows.dmn.engine.evaluator.expression.provider.binding.MethodBinding; | ||
|
||
import javax.script.ScriptEngineManager; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class ExpressionEvaluationConfiguration { | ||
|
||
private final List<MethodBinding> methodBinding; | ||
private final ScriptEngineManager scriptEngineManager; | ||
|
||
private ExpressionEvaluationConfiguration(final List<MethodBinding> methodBinding, final ScriptEngineManager scriptEngineManager) { | ||
this.methodBinding = methodBinding == null ? Collections.emptyList() : methodBinding; | ||
this.scriptEngineManager = scriptEngineManager == null ? new ScriptEngineManager() : scriptEngineManager; | ||
} | ||
|
||
public static ExpressionEvaluationConfiguration simpleConfiguration() { | ||
return ExpressionEvaluationConfiguration.builder().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.