forked from apache/incubator-kie-drools
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
Showing
16 changed files
with
296 additions
and
31 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
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
40 changes: 40 additions & 0 deletions
40
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/runtime/NamedParameter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
/* | |||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* 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.kie.dmn.feel.lang.runtime; | |||
|
|||
public class NamedParameter { | |||
private final String name; | |||
private final Object value; | |||
|
|||
public NamedParameter(String name, Object value) { | |||
this.name = name; | |||
this.value = value; | |||
} | |||
|
|||
public String getName() { | |||
return name; | |||
} | |||
|
|||
public Object getValue() { | |||
return value; | |||
} | |||
|
|||
@Override | |||
public String toString() { | |||
return name + " : " + value; | |||
} | |||
} |
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
81 changes: 81 additions & 0 deletions
81
...ie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/runtime/functions/CustomFEELFunction.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,81 @@ | |||
/* | |||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | |||
* | |||
* 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.kie.dmn.feel.lang.runtime.functions; | |||
|
|||
import org.kie.dmn.feel.lang.EvaluationContext; | |||
import org.kie.dmn.feel.lang.ast.BaseNode; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
|
|||
public class CustomFEELFunction | |||
extends BaseFEELFunction { | |||
|
|||
private static final Logger logger = LoggerFactory.getLogger( CustomFEELFunction.class ); | |||
|
|||
private final List<String> parameters; | |||
private final BaseNode body; | |||
|
|||
public CustomFEELFunction(String name, List<String> parameters, BaseNode body) { | |||
super( name ); | |||
this.parameters = parameters; | |||
this.body = body; | |||
} | |||
|
|||
@Override | |||
public List<List<String>> getParameterNames() { | |||
return Arrays.asList( parameters ); | |||
} | |||
|
|||
public Object apply(EvaluationContext ctx, Object[] params ) { | |||
if( params.length != parameters.size() ) { | |||
logger.error( "Illegal invocation of function. Expecting " + getSignature() + " but got " + getName() + "( " + Arrays.asList(params)+" )" ); | |||
return null; | |||
} | |||
try { | |||
ctx.enterFrame(); | |||
for ( int i = 0; i < parameters.size(); i++ ) { | |||
ctx.setValue( parameters.get( i ), params[i] ); | |||
} | |||
Object result = this.body.evaluate( ctx ); | |||
return result; | |||
} catch( Exception e ) { | |||
logger.error( "Error invoking function " + getSignature() + ".", e ); | |||
} finally { | |||
ctx.exitFrame(); | |||
} | |||
return null; | |||
} | |||
|
|||
private String getSignature() { | |||
return getName()+"( "+parameters.stream().collect( Collectors.joining(", ") ) +" )"; | |||
} | |||
|
|||
@Override | |||
protected boolean isCustomFunction() { | |||
return true; | |||
} | |||
|
|||
@Override | |||
public String toString() { | |||
return "function "+getSignature(); | |||
} | |||
} |
Oops, something went wrong.