// This file is copyrighted and is part of nzdis-oql package. // See the file LICENSE for copyright information and the terms and conditions for copying, distributing and modifications of nzdis-oql package. // @copyright@ package nzdis.lang.oql; /**/ import nzdis.lang.oql.node.Node; import nzdis.lang.oql.node.PExpr; import java.util.HashSet; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; /** * Represents the logical structure of the query. This is to help * developers to analyse AST without digging in the AST too much. * *

* QueryAnalyser.java
* Created: Fri Feb 25 12:30:12 2000
* * @author Mariusz Nowostawski * @version @version@ $Revision: 1.1 $ */ public class QueryAnalyser { /** Set of all free variables names. */ private HashSet freeVariables; private Hashtable projections; private Vector projNames; public QueryAnalyser() { this.projections = new Hashtable(); this.freeVariables = new HashSet(); } public void analyse(Node node){ projectionAnalysis(node); variableAnalysis(node); } private void projectionAnalysis(Node node) { ProjectionWalker out = new ProjectionWalker(); ProjectionNamesWalker ins = new ProjectionNamesWalker(); node.apply(out); final Hashtable proj = out.getAllProjections(); Enumeration enum = proj.elements(); while(enum.hasMoreElements()){ ((PExpr) enum.nextElement()).apply(ins); } this.projections = ins.getList(); this.projNames = ins.getNames(); } private void variableAnalysis(Node node) { final FreeVariableWalker w = new FreeVariableWalker(); node.apply(w); final Hashtable res = w.getVariables(); final HashSet set = new HashSet(); final Enumeration enum = res.elements(); while(enum.hasMoreElements()){ set.add((String) enum.nextElement()); } this.freeVariables = set; } /** Returns Projection nodes with names as elemnts. */ public Hashtable getProjections(){ return this.projections; } /** Returns projection variable names. */ public String[] getProjectionNames(){ final String[] result = new String[this.projNames.size()]; for(int i=0; i < projNames.size(); i++){ result[i] = (String)projNames.elementAt(i); } return result; } public String[] getVariableList(){ final Object[] ar = freeVariables.toArray(); final String[] result = new String[ar.length]; for(int i=0; i