* @param link Data link
* @throws OpenBPException On error, e. g. if the evaluation of a destination parameter expression fails
*/
private void executeDataLink(DataLink link)
{
Param sourceParam = link.getSourceParam();
String sourceMember = link.getSourceMemberPath();
Param targetParam = link.getTargetParam();
String targetMember = link.getTargetMemberPath();
//
// Retrieve the source value
//
Object value;
if (sourceMember != null)
{
// We have a member path specification for the source.
// We need an expression parser to evaluate it.
ExpressionParser parser = EngineUtil.createExpressionParser(context, engine);
String contextName = sourceParam.getContextName();
String paramName = sourceParam.getName();
int pos = contextName.lastIndexOf(paramName);
String contextPrefix = contextName.substring(0, pos);
parser.setContextPrefix(contextPrefix);
// Any members that are missing in the path will cause a null value to be returned
String expr;
if (sourceMember.startsWith(ExpressionConstants.MEMBER_OPERATOR))
expr = paramName + sourceMember;
else if (sourceMember.startsWith(ExpressionConstants.REFERENCE_KEY_OPERATOR))
expr = paramName + sourceMember;
else
expr = paramName + ExpressionConstants.MEMBER_OPERATOR + sourceMember;
value = parser.getContextPathValue(expr, null, 0);
}
else
{
// Direct parameter value access, cache the parameter value for remaining data links
value = TokenContextUtil.getParamValue(context, sourceParam);
}
if (value != null && link.isCloningSource())
{
// This link want to have the source value cloned
try
{
value = CopyUtil.copyObject(value, Copyable.COPY_DEEP, context.getExecutingModel().getClassLoader());
}
catch (Exception e)
{
throw new EngineException("Clone", "Cloning of data link value failed.", e);
}
}
//
// Set the target value
//
if (targetMember != null)
{
// We have a member path specification for the target.
// We need an expression parser to evaluate it.
ExpressionParser parser = EngineUtil.createExpressionParser(context, engine);
String contextName = targetParam.getContextName();
String paramName = targetParam.getName();
int pos = contextName.lastIndexOf(paramName);
String contextPrefix = contextName.substring(0, pos);
parser.setContextPrefix(contextPrefix);
// Provide the target parameter type and the 'create all objects' flag to the parser,
// so any members that are missing in the path will be created on the fly.
parser.setContextPathValue(targetMember, value, targetParam.getDataType(), ExpressionParser.CREATE_ALL_OBJECTS);
}
else
{
// Add the value directly as target parameter value to the context
TokenContextUtil.setParamValue(context, targetParam, value);