public Object evaluate(Object object) { return evaluate(object, functionName.getReturn().getType()); }
if (args.get(0).getMinOccurs() != 0) { throw new IllegalArgumentException( String.format( "No arguments specified for arg " + "%s, minOccurs = %d", last.getName().toString(), last.getMinOccurs())); String argName = arg.getName().toString(); Object o = expr.get(i).evaluate(obj, arg.getType()); if (o == null) { if (expr.get(i).evaluate(obj) != null) { "Failure converting value for " + "argument %s. %s could not be converted to %s", arg.getName(), obj.toString(), arg.getType().getName())); if (arg.getMaxOccurs() == 1) { throw new IllegalArgumentException( String.format( } else { if (arg.getMaxOccurs() < 0 || arg.getMaxOccurs() > 1) { List l = new ArrayList(); l.add(o);
public int getArgumentCount() { int count = 0; int variable = 1; for (Parameter<?> argument : args) { if (argument.getMinOccurs() != argument.getMaxOccurs()) { variable = -1; // flag for variable arguments } count += argument.getMinOccurs(); } return variable * count; }
Parameter<?> parameter = getFunctionName().getArguments().get(argumentIndex); if (params.size() <= argumentIndex) { if (parameter.getMinOccurs() == 0) { return null; } else { String.format( "No arguments specified for arg " + "%s, minOccurs = %d", parameter.getName().toString(), parameter.getMinOccurs())); Object value = expression.evaluate(object, parameter.getType()); if (value == null && expression.evaluate(object) != null) { throw new IllegalArgumentException( "Failure converting value for " + "argument %s. %s could not be converted to %s", parameter.getName(), expression.toString(), parameter.getType().getName()));
Parameter<?> parameter, ProcessFunctionParameterValue value) { if (parameter != null) { value.setName(parameter.getName()); value.setType(parameter.getType()); if (parameter.getType().isEnum()) { value.setObjectValue( valueFactory.getEnum( parameter.getType(), Arrays.asList(parameter.getType().getEnumConstants()))); if (parameter.getDefaultValue() != null) { value.getObjectValue().setDefaultValue(parameter.getDefaultValue().toString()); value.getObjectValue().setDefaultValue(parameter.getDefaultValue()); value.setOptional(!parameter.isRequired()); value.setDataType(parameter.getType().getSimpleName()); value.setMinOccurences(parameter.getMinOccurs()); value.setMaxOccurences(parameter.getMaxOccurs());
if (!classList.contains(function.getArguments().get(index).getType())) { classList.add(function.getArguments().get(index).getType()); + function.getArgumentNames().get(index) + "\t" + function.getArguments().get(index).getType().getName() + "\t\t" + function.getArguments().get(index).getMinOccurs() + "\t" + function.getArguments().get(index).getMaxOccurs()); if (!classList.contains(function.getReturn().getType())) { classList.add(function.getReturn().getType()); logger.debug("\tRet : " + function.getReturn().getType().getName());
&& (lastArgument.getMaxOccurs() > 0 || lastArgument.getMaxOccurs() == -1)) { context = lastArgument.getType(); } else { context = arguments.get(i).getType();
/** Sets the function. */ private void setFunction() { Function functionExpression = (Function) this.expression; FunctionName functionName = functionExpression.getFunctionName(); TypeManager.getInstance().setDataType(functionName.getReturn().getType()); int overallIndex = 0; for (Parameter<?> param : functionName.getArguments()) { if (param.getMinOccurs() == 0) { overallIndex = setFunctionOptional(functionExpression, overallIndex, param); } else { overallIndex = setFunctionFixed(functionExpression, overallIndex, param); } } }
/** * Validates the structure of arguments, basically enforcing java conventions for variable * level arguments. */ private void validateArguments() throws IllegalArgumentException { List<Parameter<?>> args = getFunctionName().getArguments(); for (int i = 0; i < args.size(); i++) { Parameter<?> arg = args.get(i); if (arg.getMaxOccurs() == 0) { throw new IllegalArgumentException(String.format("Argument %s has zero max")); } if (arg.getMinOccurs() != 1 || arg.getMaxOccurs() != 1) { //this can only happen for the last argument if (i != args.size()-1) { throw new IllegalArgumentException(String.format("Argument %s(%d,%d) invalid." + " Variable arguments must be the last argument of function.", arg.getName(), arg.getMinOccurs(), arg.getMaxOccurs())); } } } }
/** * Optional ArgumentNames. * * <p>This is a fixed length list the same size as getArgumentCount(). */ public List<String> getArgumentNames() { List<String> names = new ArrayList<String>(); for (Parameter<?> arg : args) { names.add(arg.getName()); } return names; }
for (int index = 0; index < param.getMinOccurs(); index++) { params.add(null);
/** Sets the function impl. */ private void setFunctionImpl() { FunctionImpl functionExpression = (FunctionImpl) this.expression; FunctionName functionName = functionExpression.getFunctionName(); TypeManager.getInstance().setDataType(functionName.getReturn().getType()); int maxArgument = Math.abs(functionName.getArgumentCount()); for (int index = 0; index < maxArgument; index++) { ExpressionNode childNode = new ExpressionNode(); Parameter<?> parameter = functionName.getArguments().get(0); childNode.setType(parameter.getType()); childNode.setName(parameter.getName()); if (index < functionExpression.getParameters().size()) { childNode.setExpression(functionExpression.getParameters().get(index)); } this.insert(childNode, this.getChildCount()); } }
/** * Optional ArgumentNames. * <p> * This is a fixed length list the same size as getArgumentCount(). */ public List<String> getArgumentNames() { List<String> names = new ArrayList(); for (Parameter<?> arg : args) { names.add(arg.getName()); } return names; }
/** * Sets the function fixed. * * @param functionExpression the function expression * @param overallIndex the overall index * @param param the param * @return the int */ private int setFunctionFixed( Function functionExpression, int overallIndex, Parameter<?> param) { for (int index = 0; index < param.getMinOccurs(); index++) { ExpressionNode childNode = new ExpressionNode(); childNode.setParameter(param); if (index < functionExpression.getParameters().size()) { if (overallIndex < functionExpression.getParameters().size()) { childNode.setExpression(functionExpression.getParameters().get(overallIndex)); } else { childNode.setExpression(null); } } overallIndex++; this.insert(childNode, this.getChildCount()); } return overallIndex; }
@Override public Object visit(Function f, Object extraData) { FunctionName fn = f.getFunctionName(); if (fn != null && fn.getReturn() != null && fn.getReturn().getType() != Object.class) { return fn.getReturn().getType(); } else if (f instanceof FilterFunction_Convert) { // special case for the convert function, which has the return type as // a parameter return f.getParameters().get(1).evaluate(null, Class.class); } return null; }
void check(Parameter p, String name, Class type, int min, int max) { assertEquals(name, p.getName()); assertEquals(type, p.getType()); assertEquals(min, p.getMinOccurs()); assertEquals(max, p.getMaxOccurs()); } }
protected Name lookupTypeName(List<Schema> profiles, Parameter arg) { // hack, look up for geometry mae if ("geometry".equals(arg.getName())) { return new NameImpl(org.geotools.gml3.v3_2.GML.AbstractGeometryType); } // default Class clazz = arg.getType(); if (clazz == null || clazz == Object.class) { return new NameImpl(XS.STRING); } // TODO: this is stolen from FeaturTypeSchemaBuilder, factor out into utility class for (Schema profile : profiles) { for (Map.Entry<Name, AttributeType> e : profile.entrySet()) { AttributeType at = e.getValue(); if (at.getBinding() != null && at.getBinding().equals(clazz)) { return at.getName(); } } for (AttributeType at : profile.values()) { if (clazz.isAssignableFrom(at.getBinding())) { return at.getName(); } } } return new NameImpl(XS.STRING); } }
@Override public Object visit(Function expression, Object extraData) { FunctionName name = expression.getFunctionName(); if (name != null && name.getReturn() != null) { return name.getReturn().getType(); } else { return Object.class; } }