KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > VariableTable


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

22
23 package org.xquark.extractor.algebra;
24
25 import java.util.*;
26
27 import org.xquark.extractor.common.Debug;
28
29 public final class VariableTable {
30     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
31     private static final String JavaDoc RCSName = "$Name: $";
32
33
34     VariableTable _defautVariableTable;
35     HashMap _varTable;
36
37     public VariableTable ()
38     {
39         //Trace.enter(this,"VariableTable ()");
40
_varTable = new HashMap();
41         //Trace.exit(this,"VariableTable ()");
42
}
43     /**
44     Access method for the _defautVariableTable property.
45
46     @return the current value of the _defautVariableTable property
47      */

48     public VariableTable getDefautVariableTable()
49     {
50         //Trace.enter(this,"getDefautVariableTable()");
51
//Trace.exit(this,"getDefautVariableTable()");
52
return _defautVariableTable;
53     }
54
55     /**
56     Sets the value of the _defautVariableTable property.
57
58     @param aDefautVariableTable the new value of the _defautVariableTable property
59      */

60     public void setDefautVariableTable(VariableTable aDefautVariableTable)
61     {
62         //Trace.enter(this,"setDefautVariableTable(VariableTable aDefautVariableTable)");
63
_defautVariableTable = aDefautVariableTable;
64         //Trace.exit(this,"setDefautVariableTable(VariableTable aDefautVariableTable)");
65
}
66
67
68     /**
69      * get the translations of the variable.
70      *
71      * if the varName is null, throw java.lang.NullPointerException
72         @param varName
73         @return Expression
74         @throws java.lang.NullPointerException
75         @roseuid 3BD16E3602C0
76      */

77     public Expression get(String JavaDoc varName)
78     {
79         //Trace.enter(this,"get(String varName)");
80

81         Expression retVal = null;
82
83         retVal = (Expression)_varTable.get(varName);
84         if (null==retVal && _defautVariableTable != null) {
85             retVal = _defautVariableTable.get(varName);
86         }
87
88         //Trace.exit(this,"get(String varName)");
89
return retVal;
90     }
91
92     /**
93      * put a variable name and the translation of the variable in this object.
94      *
95      * if either of the parameters is null, throw ???? Exception @todo
96     @param varName : the name of variable. case-sensitive.
97     @param translation : the translations of this variable, often a tree.
98     @roseuid 3BD16E6E03B1
99      */

100     public void put(String JavaDoc varName, Expression translation)
101     {
102         //Trace.enter(this,"put(String varName, Expression translation)", "$" + varName);
103
Debug.assertTrue(null!=varName,"null!=varName");
104         Debug.assertTrue(null!=translation,"null!=translation");
105         _varTable.put(varName, translation);
106         //Trace.exit(this,"put(String varName, Expression translation)", "$" + varName);
107
}
108
109     public HashSet getCurrentLevelTableInstances()
110     {
111         //Trace.enter(this,"getPredefinedTableInstances()");
112
HashSet retVal = new HashSet();
113         Collection varTrans = _varTable.values();
114         Iterator iter = varTrans.iterator();
115         while (iter.hasNext()) {
116             Object JavaDoc item = iter.next();
117             if (item instanceof TupleExpression) {
118                 retVal.add( ((TupleExpression)item).getTableInstance() );
119             }
120             else if (item instanceof AttributeExpression) {
121                 retVal.add( ((AttributeExpression)item).getTableInstance() );
122             }
123         }
124         //Trace.exit(this,"getPredefinedTableInstances()");
125
return retVal;
126     }
127     public HashSet getPredefinedTableInstances()
128     {
129         //Trace.enter(this,"getPredefinedTableInstances()");
130
HashSet retVal = new HashSet();
131         VariableTable nextVT = getDefautVariableTable();
132         while (null != nextVT ) {
133             retVal.addAll(nextVT.getCurrentLevelTableInstances());
134             nextVT = nextVT.getDefautVariableTable();
135         }
136         //Trace.exit(this,"getPredefinedTableInstances()");
137
return retVal;
138     }
139 }
140
Popular Tags