EMMA Coverage Report (generated Tue Jul 10 07:50:22 IST 2012)
[all classes][org.wso2.siddhi.core.util.parser]

COVERAGE SUMMARY FOR SOURCE FILE [ExecutorParser.java]

nameclass, %method, %block, %line, %
ExecutorParser.java100% (1/1)67%  (2/3)64%  (190/296)77%  (30/39)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExecutorParser100% (1/1)67%  (2/3)64%  (190/296)77%  (30/39)
ExecutorParser (): void 0%   (0/1)0%   (0/3)0%   (0/1)
parseCondition (Condition, List, String): ConditionExecutor 100% (1/1)58%  (111/193)73%  (16/22)
parseExpression (Expression, List, String): ExpressionExecutor 100% (1/1)79%  (79/100)88%  (14/16)

1/*
2*  Copyright (c) 2005-2012, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3*
4*  WSO2 Inc. licenses this file to you under the Apache License,
5*  Version 2.0 (the "License"); you may not use this file except
6*  in compliance with the License.
7*  You may obtain a copy of the License at
8*
9*    http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing,
12* software distributed under the License is distributed on an
13* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14* KIND, either express or implied.  See the License for the
15* specific language governing permissions and limitations
16* under the License.
17*/
18package org.wso2.siddhi.core.util.parser;
19 
20import org.wso2.siddhi.core.exception.OperationNotSupportedException;
21import org.wso2.siddhi.core.executor.conditon.AndConditionExecutor;
22import org.wso2.siddhi.core.executor.conditon.BooleanConditionExecutor;
23import org.wso2.siddhi.core.executor.conditon.ConditionExecutor;
24import org.wso2.siddhi.core.executor.conditon.NotConditionExecutor;
25import org.wso2.siddhi.core.executor.conditon.OrConditionExecutor;
26import org.wso2.siddhi.core.executor.expression.ConstantExpressionExecutor;
27import org.wso2.siddhi.core.executor.expression.ExpressionExecutor;
28import org.wso2.siddhi.core.executor.expression.VariableExpressionExecutor;
29import org.wso2.siddhi.query.api.condition.AndCondition;
30import org.wso2.siddhi.query.api.condition.BooleanCondition;
31import org.wso2.siddhi.query.api.condition.Compare;
32import org.wso2.siddhi.query.api.condition.Condition;
33import org.wso2.siddhi.query.api.condition.NotCondition;
34import org.wso2.siddhi.query.api.condition.OrCondition;
35import org.wso2.siddhi.query.api.definition.Attribute;
36import org.wso2.siddhi.query.api.expression.Expression;
37import org.wso2.siddhi.query.api.expression.Variable;
38import org.wso2.siddhi.query.api.expression.constant.BoolConstant;
39import org.wso2.siddhi.query.api.expression.constant.Constant;
40import org.wso2.siddhi.query.api.expression.constant.DoubleConstant;
41import org.wso2.siddhi.query.api.expression.constant.FloatConstant;
42import org.wso2.siddhi.query.api.expression.constant.IntConstant;
43import org.wso2.siddhi.query.api.expression.constant.LongConstant;
44import org.wso2.siddhi.query.api.expression.constant.StringConstant;
45import org.wso2.siddhi.query.api.query.QueryEventStream;
46 
47import java.util.List;
48 
49public class ExecutorParser {
50 
51 
52    public static ConditionExecutor parseCondition(Condition condition,
53                                                   List<QueryEventStream> queryEventStreamList,
54                                                   String currentStreamReference) {
55        if (condition instanceof AndCondition) {
56            return new AndConditionExecutor(parseCondition(((AndCondition) condition).getLeftCondition(), queryEventStreamList, currentStreamReference),
57                                            parseCondition(((AndCondition) condition).getRightCondition(), queryEventStreamList, currentStreamReference));
58        } else if (condition instanceof OrCondition) {
59            return new OrConditionExecutor(parseCondition(((OrCondition) condition).getLeftCondition(), queryEventStreamList, currentStreamReference),
60                                           parseCondition(((OrCondition) condition).getRightCondition(), queryEventStreamList, currentStreamReference));
61        } else if (condition instanceof NotCondition) {
62            return new NotConditionExecutor(parseCondition(((NotCondition) condition).getCondition(), queryEventStreamList, currentStreamReference));
63        } else if (condition instanceof BooleanCondition) {
64            return new BooleanConditionExecutor(parseExpression(((BooleanCondition) condition).getExpression(), queryEventStreamList, currentStreamReference));
65        } else if (condition instanceof Compare) {
66            if (((Compare) condition).getOperator() == Condition.Operator.EQUAL) {
67                return ComparatorParser.parseEqualCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
68                                                          parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
69            } else if (((Compare) condition).getOperator() == Condition.Operator.NOT_EQUAL) {
70                return ComparatorParser.parseNotEqualCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
71                                                             parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
72            } else if (((Compare) condition).getOperator() == Condition.Operator.GREATER_THAN) {
73                return ComparatorParser.parseGreaterThanCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
74                                                                parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
75            } else if (((Compare) condition).getOperator() == Condition.Operator.GREATER_THAN_EQUAL) {
76                return ComparatorParser.parseGreaterThanEqualCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
77                                                                     parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
78            } else if (((Compare) condition).getOperator() == Condition.Operator.LESS_THAN) {
79                return ComparatorParser.parseLessThanCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
80                                                             parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
81            } else if (((Compare) condition).getOperator() == Condition.Operator.LESS_THAN_EQUAL) {
82                return ComparatorParser.parseLessThanEqualCompare(parseExpression(((Compare) condition).getLeftExpression(), queryEventStreamList, currentStreamReference),
83                                                                  parseExpression(((Compare) condition).getRightExpression(), queryEventStreamList, currentStreamReference));
84 
85            }
86        }
87        throw new OperationNotSupportedException(condition + " not supported !");
88    }
89 
90    public static ExpressionExecutor parseExpression(Expression expression,
91                                                     List<QueryEventStream> queryEventStreamList,
92                                                     String currentStreamReference) {
93        if (expression instanceof Constant) {
94            if (expression instanceof BoolConstant) {
95                return new ConstantExpressionExecutor(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
96            } else if (expression instanceof StringConstant) {
97                return new ConstantExpressionExecutor(((StringConstant) expression).getValue(), Attribute.Type.STRING);
98            } else if (expression instanceof IntConstant) {
99                return new ConstantExpressionExecutor(((IntConstant) expression).getValue(), Attribute.Type.INT);
100            } else if (expression instanceof LongConstant) {
101                return new ConstantExpressionExecutor(((LongConstant) expression).getValue(), Attribute.Type.LONG);
102            } else if (expression instanceof FloatConstant) {
103                return new ConstantExpressionExecutor(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
104            } else if (expression instanceof DoubleConstant) {
105                return new ConstantExpressionExecutor(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
106            }
107        } else if (expression instanceof Variable) {
108            return new VariableExpressionExecutor(((Variable) expression).getStreamId(), ((Variable) expression).getAttributeName(), ((Variable) expression).getPosition(), queryEventStreamList, currentStreamReference);
109 
110        }
111 
112        throw new UnsupportedOperationException(expression.toString() + " not supported!");
113 
114    }
115}

[all classes][org.wso2.siddhi.core.util.parser]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov