001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.filter.function;
018
019import org.apache.activemq.filter.FunctionCallExpression;
020import org.apache.activemq.filter.MessageEvaluationContext;
021
022/**
023 * Filter function that creates a list with each argument being one element in the list.
024 * For example:
025 * <p/>
026 * <p style="margin-left: 4em">
027 * MAKELIST( '1', '2', '3' )
028 * </p>
029 */
030
031public class makeListFunction implements FilterFunction {
032    /**
033     * Check whether the given expression is a valid call of this function.  Any number of arguments is accepted.
034     *
035     * @param    expr - the expression consisting of a call to this function.
036     * @return true - if the expression is valid; false - otherwise.
037     */
038
039    public boolean isValid(FunctionCallExpression expr) {
040        return true;
041    }
042
043
044    /**
045     * Indicate that this function never evaluates to a Boolean result.
046     *
047     * @param    expr - the expression consisting of a call to this function.
048     * @return false - this Filter Function never evaluates to a Boolean.
049     */
050
051    public boolean returnsBoolean(FunctionCallExpression expr) {
052        return false;
053    }
054
055
056    /**
057     * Evalutate the given expression, which consists of a call to this function, in the context given.  Creates
058     * a list containing the evaluated results of its argument expressions.
059     *
060     * @param    expr - the expression consisting of a call to this function.
061     * @param    message_ctx - the context in which the call is being evaluated.
062     * @return java.util.List - the result of the evaluation.
063     */
064
065    public Object evaluate(FunctionCallExpression expr, MessageEvaluationContext message)
066            throws javax.jms.JMSException {
067        java.util.ArrayList ele_arr;
068        int num_arg;
069        int cur;
070
071        num_arg = expr.getNumArguments();
072        ele_arr = new java.util.ArrayList(num_arg);
073
074        cur = 0;
075        while (cur < num_arg) {
076            ele_arr.add(expr.getArgument(cur).evaluate(message));
077            cur++;
078        }
079
080        return (java.util.List) ele_arr;
081    }
082}