當前位置: 首頁>>代碼示例>>Java>>正文


Java FunctionExpression類代碼示例

本文整理匯總了Java中org.kuali.rice.krms.framework.engine.expression.FunctionExpression的典型用法代碼示例。如果您正苦於以下問題:Java FunctionExpression類的具體用法?Java FunctionExpression怎麽用?Java FunctionExpression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FunctionExpression類屬於org.kuali.rice.krms.framework.engine.expression包,在下文中一共展示了FunctionExpression類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: translateToExpression

import org.kuali.rice.krms.framework.engine.expression.FunctionExpression; //導入依賴的package包/類
/**
 * Translates the parameters on the given proposition definition to create an expression for evaluation.
 * The proposition parameters are defined in a reverse-polish notation so a stack is used for
 * evaluation purposes.
 * 
 * @param propositionDefinition the proposition definition to translate
 * 
 * @return the translated expression for the given proposition, this
 * expression, when evaluated, will return a Boolean.
 */
protected Expression<Boolean> translateToExpression(PropositionDefinition propositionDefinition) {
	LinkedList<Expression<? extends Object>> stack = new LinkedList<Expression<? extends Object>>();
	for (PropositionParameter parameter : propositionDefinition.getParameters()) {
		PropositionParameterType parameterType = PropositionParameterType.fromCode(parameter.getParameterType());
		if (parameterType == PropositionParameterType.CONSTANT) {
			// TODO - need some way to define data type on the prop parameter as well?  Not all constants will actually be String values!!!
			stack.addFirst(new ConstantExpression<String>(parameter.getValue()));
		} else if (parameterType == PropositionParameterType.FUNCTION) {
			String functionId = parameter.getValue();
			FunctionDefinition functionDefinition = functionRepositoryService.getFunction(functionId);
			if (functionDefinition == null) {
				throw new RepositoryDataException("Unable to locate function with the given id: " + functionId);
			}
			FunctionTypeService functionTypeService = typeResolver.getFunctionTypeService(functionDefinition);
			Function function = functionTypeService.loadFunction(functionDefinition);
			// TODO throw an exception if function is null?
			List<FunctionParameterDefinition> parameters = functionDefinition.getParameters();
			if (stack.size() < parameters.size()) {
				throw new RepositoryDataException("Failed to initialize custom function '" + functionDefinition.getNamespace() + " " + functionDefinition.getName() +
						"'.  There were only " + stack.size() + " values on the stack but function requires at least " + parameters.size());
			}
			List<Expression<? extends Object>> arguments = new ArrayList<Expression<? extends Object>>();
			// work backward through the list to match params to the stack
			for (int index = parameters.size() - 1; index >= 0; index--) {
				FunctionParameterDefinition parameterDefinition = parameters.get(index);
				// TODO need to check types here? expression object probably needs a getType on it so that we can confirm that the types will be compatible?
                   parameterDefinition.getParameterType();
				Expression<? extends Object> argument = stack.removeFirst();
				arguments.add(argument);
			}

               String[] parameterTypes = getFunctionParameterTypes(functionDefinition);
			stack.addFirst(new FunctionExpression(function, parameterTypes, arguments, getComparisonOperatorService()));

		} else if (parameterType == PropositionParameterType.OPERATOR) {
			ComparisonOperator operator = ComparisonOperator.fromCode(parameter.getValue());
			if (stack.size() < 2) {
				throw new RepositoryDataException("Failed to initialize expression for comparison operator " +
                           operator + " because a sufficient number of arguments was not available on the stack.  "
                           + "Current contents of stack: " + stack.toString());
			}
			Expression<? extends Object> rhs = stack.removeFirst();
			Expression<? extends Object> lhs = stack.removeFirst();
			stack.addFirst(new BinaryOperatorExpression(operator, lhs, rhs));
		} else if (parameterType == PropositionParameterType.TERM) {
			String termId = parameter.getValue();

			TermDefinition termDefinition = getTermRepositoryService().getTerm(termId);
			if (termDefinition == null) { throw new RepositoryDataException("unable to load term with id " + termId);}
			Term term = translateTermDefinition(termDefinition);
			
			stack.addFirst(new TermExpression(term));
		}
	}
	if (stack.size() != 1) {
		throw new RepositoryDataException("Final contents of expression stack are incorrect, there should only be one entry but was " + stack.size() +".  Current contents of stack: " + stack.toString());
	}
	return new BooleanValidatingExpression(stack.removeFirst());
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:70,代碼來源:SimplePropositionTypeService.java


注:本文中的org.kuali.rice.krms.framework.engine.expression.FunctionExpression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。