Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / instruction / NotExprAdapter.java @ 466

History | View | Annotate | Download (2.84 KB)

1
/* Generated by Together */
2
package com.hardcode.gdbms.engine.instruction;
3

    
4
import com.hardcode.gdbms.engine.data.DriverException;
5
import com.hardcode.gdbms.engine.values.BooleanValue;
6
import com.hardcode.gdbms.engine.values.Value;
7
import com.hardcode.gdbms.parser.Node;
8

    
9

    
10
/**
11
 * Adapter de las Expresiones Not del arbol sint?ctico
12
 *
13
 * @author Fernando Gonz?lez Cort?s
14
 */
15
public class NotExprAdapter extends AbstractExpression implements Expression {
16
    private boolean not = false;
17

    
18
    /**
19
     * Evalua expresi?n invocando el m?todo adecuado en funci?n del tipo de
20
     * expresion (suma, producto, ...) de los objetos Value de la expresion,
21
     * de las subexpresiones y de los objetos Field
22
     *
23
     * @param row Fila en la que se eval?a la expresi?n, en este caso no es
24
     *        necesario, pero las subexpresiones sobre las que se opera pueden
25
     *        ser campos de una tabla, en cuyo caso si es necesario
26
     *
27
     * @return Objeto Value resultado de la operaci?n propia de la expresi?n
28
     *         representada por el nodo sobre el cual ?ste objeto es adaptador
29
     *
30
     * @throws SemanticException Si se produce un error sem?ntico
31
     * @throws DriverException Si se produce un error de I/O
32
     * @throws IncompatibleTypesException Si la expresi?n es una negaci?n y la
33
     *         expresi?n que se niega no es booleana
34
     */
35
    public Value evaluate(long row) throws SemanticException, DriverException {
36
        Value ret = null;
37

    
38
        Expression c = (Expression) getChilds()[0];
39

    
40
        try {
41
            Value value = c.evaluateExpression(row);
42

    
43
            if (not) {
44
                ((BooleanValue) value).setValue(!((BooleanValue) value).getValue());
45
            }
46

    
47
            return value;
48
        } catch (ClassCastException e) {
49
            throw new IncompatibleTypesException(e);
50
        }
51
    }
52

    
53
    /**
54
     * @see com.hardcode.gdbms.engine.instruction.Expression#getFieldName()
55
     */
56
    public String getFieldName() {
57
        return null;
58
    }
59

    
60
    /**
61
     * @see com.hardcode.gdbms.engine.instruction.Expression#isLiteral()
62
     */
63
    public boolean isLiteral() {
64
        return literal;
65
    }
66

    
67
    /**
68
     * @see com.hardcode.gdbms.engine.instruction.Expression#simplify()
69
     */
70
    public void simplify() {
71
        if (!not) {
72
            getParent().replaceChild(this, getChilds()[0]);
73
        }
74
    }
75

    
76
    /**
77
     * @see com.hardcode.gdbms.engine.instruction.Adapter#setEntity(com.hardcode.gdbms.parser.Node)
78
     */
79
    public void setEntity(Node o) {
80
        super.setEntity(o);
81

    
82
        String text = Utilities.getText(getEntity()).trim();
83

    
84
        if (text.startsWith("not")) {
85
            not = true;
86
        }
87
    }
88

    
89
        /**
90
         * @see com.hardcode.gdbms.engine.instruction.Expression#calculateLiteralCondition()
91
         */
92
        public void calculateLiteralCondition() {
93
        literal = ((Expression) getChilds()[0]).isLiteral();
94
        }
95
}