-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d241119
commit b349f3d
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...-commons/src/main/java/com/livk/commons/expression/aviator/PrioritizedFunctionLoader.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,53 @@ | ||
/* | ||
* Copyright 2021-2024 spring-boot-extension the original author or authors. | ||
* 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 | ||
* https://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 com.livk.commons.expression.aviator; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.googlecode.aviator.FunctionLoader; | ||
import com.googlecode.aviator.runtime.type.AviatorFunction; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author livk | ||
*/ | ||
public class PrioritizedFunctionLoader implements FunctionLoader { | ||
|
||
private final List<FunctionLoader> loaders; | ||
|
||
public PrioritizedFunctionLoader() { | ||
this(new ArrayList<>()); | ||
} | ||
|
||
public PrioritizedFunctionLoader(List<FunctionLoader> loaders) { | ||
this.loaders = loaders; | ||
} | ||
|
||
public PrioritizedFunctionLoader(FunctionLoader... loaders) { | ||
this(Lists.newArrayList(loaders)); | ||
} | ||
|
||
@Override | ||
public AviatorFunction onFunctionNotFound(String name) { | ||
for (FunctionLoader loader : loaders) { | ||
AviatorFunction function = loader.onFunctionNotFound(name); | ||
if (function != null) { | ||
return function; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...sion-commons/src/main/java/com/livk/commons/expression/aviator/ServiceFunctionLoader.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,49 @@ | ||
/* | ||
* Copyright 2021-2024 spring-boot-extension the original author or authors. | ||
* 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 | ||
* https://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 com.livk.commons.expression.aviator; | ||
|
||
import com.googlecode.aviator.FunctionLoader; | ||
import com.googlecode.aviator.runtime.type.AviatorFunction; | ||
|
||
import java.util.Map; | ||
import java.util.ServiceLoader; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* <p> | ||
* ServiceFunctionLoader | ||
* </p> | ||
* | ||
* @author livk | ||
*/ | ||
public class ServiceFunctionLoader implements FunctionLoader { | ||
|
||
private final Map<String, AviatorFunction> functions = new ConcurrentHashMap<>(); | ||
|
||
public ServiceFunctionLoader() { | ||
load(); | ||
} | ||
|
||
@Override | ||
public AviatorFunction onFunctionNotFound(String name) { | ||
return functions.get(name); | ||
} | ||
|
||
public void load() { | ||
for (AviatorFunction function : ServiceLoader.load(AviatorFunction.class)) { | ||
this.functions.put(function.getName(), function); | ||
} | ||
} | ||
|
||
} |
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