KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > decomposer > VariableDependencies


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.mediator.decomposer;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28
29 import org.xquark.mediator.runtime.MediatorException;
30 import org.xquark.xquery.parser.Variable;
31 import org.xquark.xquery.parser.XQueryException;
32 import org.xquark.xquery.parser.XQueryExpression;
33
34 public class VariableDependencies {
35     // **********************************************************************
36
// * VERSIONING
37
// **********************************************************************
38
private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
39     private static final String JavaDoc RCSName = "$Name: $";
40     // **********************************************************************
41
// * CLASS VARIABLES
42
// **********************************************************************
43
// object containing
44
// for each var all simple conditions in which this var appears
45
private HashMap JavaDoc varSimpleConditionsMap = null;
46     // for each var a map of (var,conditions) reprensenting simple joins
47
private HashMap JavaDoc varJoinConditionsMap = null;
48     // for each var a list of complex conditions in which it appears
49
private HashMap JavaDoc varComplexConditionsMap = null;
50     // for each var all conditions in which this var appears
51
private HashMap JavaDoc varAllConditionsMap = null;
52     // for each var all variables appearing in common conditions
53
private HashMap JavaDoc varAssociatedVariablesMap = null; // { var1 [var2, var3], var2 [var3, var4] ...
54
// for each condition all variables appearing
55
private HashMap JavaDoc condAssociatedVariablesMap = null; // { c1 [var2, var3], c2 [var3, var4] ...
56
// a list of all simple conditions
57
private ArrayList JavaDoc allSimpleConditionsList = null;
58     // a list of all join conditions
59
private ArrayList JavaDoc allJoinConditionsList = null;
60     // a list of all complex conditions
61
private ArrayList JavaDoc allComplexConditionsList = null;
62     // a list of all conditions
63
private ArrayList JavaDoc allConditionsList = null;
64     // a list of all conditions without variables !!!
65
private ArrayList JavaDoc allNoVariablesConditionsList = null;
66     // a visitor
67
AtomizeWhereVisitor awvisitor = new AtomizeWhereVisitor();
68     // **********************************************************************
69
// * INITIALIZATION
70
// **********************************************************************
71

72     public VariableDependencies(XQueryExpression expr) throws MediatorException {
73         try {
74             expr.accept(awvisitor);
75         } catch (XQueryException e) {
76             throw new MediatorException("Could not atomize where clause : " + expr, e);
77         }
78         varSimpleConditionsMap = awvisitor.getVarSimpleConditionsMap();
79         varJoinConditionsMap = awvisitor.getVarJoinConditionsMap();
80         varComplexConditionsMap = awvisitor.getVarComplexConditionsMap();
81         varAllConditionsMap = awvisitor.getVarAllConditionsMap();
82         varAssociatedVariablesMap = awvisitor.getVarAssociatedVariablesMap();
83         condAssociatedVariablesMap = awvisitor.getCondAssociatedVariablesMap();
84         allNoVariablesConditionsList = awvisitor.getAllNoVariablesConditionsList();
85         allSimpleConditionsList = awvisitor.getAllSimpleConditionsList();
86         allJoinConditionsList = awvisitor.getAllJoinConditionsList();
87         allComplexConditionsList = awvisitor.getAllComplexConditionsList();
88         allConditionsList = awvisitor.getAllConditionsList();
89     }
90     
91     // access methods
92
public ArrayList JavaDoc getAllAssociatedVariables (Variable var) {
93         return (ArrayList JavaDoc)varAssociatedVariablesMap.get(var);
94     }
95     public HashMap JavaDoc getJoinMap(Variable var) {
96         return (HashMap JavaDoc)varJoinConditionsMap.get(var);
97     }
98     public boolean hasJoins() {
99         if (allJoinConditionsList.isEmpty()) return false;
100         return true;
101     }
102     public HashMap JavaDoc getJoinsMap() {
103         return varJoinConditionsMap;
104     }
105 // public ArrayList getAllConditionsWithVar(Variable var) {
106
// return (ArrayList)varAllConditionsMap.get(var);
107
// }
108
public ArrayList JavaDoc getAllComplexConditionsWithVar(Variable var) {
109         return (ArrayList JavaDoc)varComplexConditionsMap.get(var);
110     }
111     public ArrayList JavaDoc getVarsOfCond(XQueryExpression expr) {
112         return (ArrayList JavaDoc)condAssociatedVariablesMap.get(expr);
113     }
114     // debug methods
115
public String JavaDoc toString() {
116         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
117         sb.append("varSimpleConditionsMap : ");
118         sb.append(varSimpleConditionsMap);
119         sb.append("\nvarJoinConditionsMap : ");
120         sb.append(varJoinConditionsMap);
121         sb.append("\nvarComplexConditionsMap : ");
122         sb.append(varComplexConditionsMap);
123         sb.append("\nvarAllConditionsMap : ");
124         sb.append(varAllConditionsMap);
125         sb.append("\nvarAssociatedVariablesMap : ");
126         sb.append(varAssociatedVariablesMap);
127         sb.append("\ncondAssociatedVariablesMap : ");
128         sb.append(condAssociatedVariablesMap);
129         sb.append("\nallNoVariablesConditionsList : ");
130         sb.append(allNoVariablesConditionsList);
131         sb.append("\nallSimpleConditionsList : ");
132         sb.append(allSimpleConditionsList);
133         sb.append("\nallJoinConditionsList : ");
134         sb.append(allJoinConditionsList);
135         sb.append("\nallComplexConditionsList : ");
136         sb.append(allComplexConditionsList);
137         sb.append("\nallConditionsList : ");
138         sb.append(allConditionsList);
139         return sb.toString();
140     }
141
142 }
143
Popular Tags