KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mediator > plan > OpSourceEval


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 XQuark Group.
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.mediator.plan;
24
25 import java.util.ArrayList JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.xquark.mediator.decomposer.Utils;
30 import org.xquark.mediator.runtime.MediatorException;
31 import org.xquark.xml.xdbc.XMLResultSet;
32 import org.xquark.xml.xqueryevaluator.eval.EvalFilter;
33 import org.xquark.xquery.parser.FLWRExpression;
34 import org.xquark.xquery.parser.XQueryExpression;
35
36 public class OpSourceEval extends ZeroOp {
37     // **********************************************************************
38
// * VERSIONING
39
// **********************************************************************
40
private static final String JavaDoc RCSRevision = "$Revision: 1.11 $";
41     private static final String JavaDoc RCSName = "$Name: $";
42
43     // **********************************************************************
44
// * CLASS VARIABLES
45
// **********************************************************************
46
//private XMLConnection connection = null;
47
//private String source = null;
48

49     // ***********************************************************************
50
// * INITIALIZATION
51
// ***********************************************************************
52
/**
53      *
54      */

55     public OpSourceEval(ExecutionPlan plan, XQueryExpression expression, ArrayList JavaDoc origpaths, boolean hasIdentifier) throws MediatorException {
56         super(plan, expression);
57
58         try {
59             for (int i = 0; i < origpaths.size(); i++) {
60                 addPath((XQueryExpression) ((XQueryExpression) origpaths.get(i)).clone());
61             }
62         } catch (CloneNotSupportedException JavaDoc cnse) {
63         }
64         //addPaths(origpaths);
65
this.size = this.getPaths().size();
66         if (hasIdentifier)
67             this.idsize = 1;
68     }
69
70     // #############################################################################
71
// VISITOR STUFF
72
// #############################################################################
73

74     public void accept(OperatorVisitor visitor) throws MediatorException {
75         visitor.visit(this);
76     }
77
78     // ***********************************************************************
79
// * EXECUTE QUERY
80
// ***********************************************************************
81
/**
82      *
83      */

84     protected ResultSet getResultSet(DynamicContext context) throws MediatorException {
85         return new SourceEvalResultSet(this, context);
86     }
87
88     // **********************************************************************
89
// * OPTIMIZE
90
// **********************************************************************
91
/**
92      * Return all the sources depending of this node.
93      */

94     public ArrayList JavaDoc getSources() {
95         return null;
96     }
97
98     public String JavaDoc toCompleteString(int indent) {
99         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
100         buf.append(Utils.makeIndent(indent) + "<" + getClass().getName() + " size=" + size + " id size=" + idsize + " isLet=\"" + islet + "\" valueDepends=\"" + valueDepends + "\" whereDepends=\"" + whereDepends + "\">\n");
101         buf.append(Utils.makeIndent(indent + 1) + "<Expression>\n");
102         buf.append(Utils.makeIndent(indent + 2) + expression + "\n");
103         buf.append(Utils.makeIndent(indent + 1) + "</Expression>\n");
104         // buf.append(Utils.makeIndent(indent + 1) + "<Source>" + source + "</Source>\n");
105
// if (variables != null) {
106
// buf.append(Utils.makeIndent(indent + 1) + "<Variables>\n");
107
// for (int i = 0; i < variables.size(); i++) {
108
// buf.append(Utils.makeIndent(indent + 2) + "<Variable>" + variables.get(i) + "</Variable>\n");
109
// }
110
// buf.append(Utils.makeIndent(indent + 1) + "</Variables>\n");
111
// }
112
if (paths != null) {
113             buf.append(Utils.makeIndent(indent + 1) + "<Paths>\n");
114             for (int i = 0; i < paths.size(); i++) {
115                 buf.append(Utils.makeIndent(indent + 2) + "<Path>" + paths.get(i) + "</Path>\n");
116             }
117             buf.append(Utils.makeIndent(indent + 1) + "</Paths>\n");
118         }
119         buf.append(Utils.makeIndent(indent) + "</" + getClass().getName() + ">\n");
120         return buf.toString();
121     }
122
123 }
124
125 class SourceEvalResultSet extends ZeroResultSet {
126     // **********************************************************************
127
// * VERSIONING
128
// **********************************************************************
129
private static final String JavaDoc RCSRevision = "$Revision: 1.11 $";
130     private static final String JavaDoc RCSName = "$Name: $";
131
132     private static Log log = LogFactory.getLog(SourceEvalResultSet.class);
133
134     // **********************************************************************
135
// * CLASS VARIABLES
136
// **********************************************************************
137
private XMLResultSet resultset = null;
138     private EvalFilter evalFilter;
139
140     // ***********************************************************************
141
// * INITIALIZATION
142
// ***********************************************************************
143
/**
144      *
145      */

146     public SourceEvalResultSet(OpSourceEval operator, DynamicContext context) throws MediatorException {
147         super(operator, context);
148         if (log.isDebugEnabled())
149             log.debug("MEMORY EXECUTING \n" + expression.getStringValue());
150         evalFilter = new EvalFilter(this.buftuples, context, this.paths, (FLWRExpression) this.expression);
151     }
152
153     // ***********************************************************************
154
// * EVALUATE IMPLEMENTATION
155
// ***********************************************************************
156
/**
157      *
158      * @param non_blocking if the evaluation is blocking, we must
159      * generate all the results before passing.
160      */

161     //int tupleindex = 0;
162
protected void evaluate(boolean non_blocking) throws MediatorException {
163         boolean isDone = false;
164         isDone = evalFilter.evaluate();
165         if (isDone)
166             setFinishedWhenEmpty();
167     }
168
169 }
170
Popular Tags