Statistics
| Revision:

root / trunk / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / engine / instruction / Adapter.java @ 10627

History | View | Annotate | Download (2.53 KB)

1
package com.hardcode.gdbms.engine.instruction;
2

    
3
import com.hardcode.gdbms.parser.Node;
4
import com.hardcode.gdbms.parser.SimpleNode;
5

    
6

    
7
/**
8
 * Clase base para todos los adaptadores de elementos del arbol sint?ctico
9
 * generado por el parser a elementos descendientes de SelectInstruction
10
 *
11
 * @author Fernando Gonz?lez Cort?s
12
 */
13
public class Adapter {
14
        private Adapter parent = null;
15
        private Adapter[] childs;
16
        private Node entity;
17
        private InstructionContext ic;
18

    
19
        /**
20
         * set the context of the instruction being executed. Should be invoked on
21
         * the root adapter to make all the adapter nodes have the same
22
         * instruction context
23
         *
24
         * @param ic instruction context to set
25
         */
26
        public void setInstructionContext(InstructionContext ic) {
27
                this.ic = ic;
28

    
29
                Adapter[] hijos = getChilds();
30

    
31
                for (int i = 0; i < hijos.length; i++) {
32
                        hijos[i].setInstructionContext(ic);
33
                }
34
        }
35

    
36
        /**
37
         * DOCUMENT ME!
38
         *
39
         * @return DOCUMENT ME!
40
         */
41
        public InstructionContext getInstructionContext() {
42
                return ic;
43
        }
44

    
45
        /**
46
         * Establece la entidad del arbol sint?ctico de la que es adaptador este
47
         * objeto
48
         *
49
         * @param o Nodo de arbol sint?ctico
50
         */
51
        public void setEntity(Node o) {
52
                entity = o;
53
        }
54

    
55
        /**
56
         * Obtiene la entidad del arbol sint?ctico de la que es adaptador este
57
         * objeto
58
         *
59
         * @return Nodo del arbol sint?ctico
60
         */
61
        public SimpleNode getEntity() {
62
                return (SimpleNode) entity;
63
        }
64

    
65
        /**
66
         * A?ade un hijo al adaptador
67
         *
68
         * @param a Adaptador hijo
69
         */
70
        public void setChilds(Adapter[] a) {
71
                childs = a;
72
        }
73

    
74
        /**
75
         * Obtiene el array de hijos del adaptador
76
         *
77
         * @return Array de hijos del adaptador. Si no existe ning?n hijo se
78
         *                    retorna un array vac?o
79
         */
80
        public Adapter[] getChilds() {
81
                return childs;
82
        }
83

    
84
        /**
85
         * Establece el padre del nodo en el arbol de adaptadores
86
         *
87
         * @param parent
88
         */
89
        protected void setParent(Adapter parent) {
90
                this.parent = parent;
91
        }
92

    
93
        /**
94
         * En los ?rboles de expresiones es com?n tener varios adaptadores que lo
95
         * ?nico que hacen es devolver el valor de su ?nico hijo. Para evitar esto
96
         * se pone al hijo en contacto directo con el padre invocando directamente
97
         * este m?todo
98
         *
99
         * @param child Hijo a sustituir
100
         * @param newChild Hijo que reemplaza al anterior
101
         */
102
        protected void replaceChild(Adapter child, Adapter newChild) {
103
                for (int i = 0; i < childs.length; i++) {
104
                        if (childs[i] == child) {
105
                                childs[i] = newChild;
106
                        }
107
                }
108
        }
109

    
110
        /**
111
         * Obtiene el padre de este adaptador en el arbol de adaptadores
112
         *
113
         * @return Returns the parent.
114
         */
115
        public Adapter getParent() {
116
                return parent;
117
        }
118
}