KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > Optimizer


1 package net.sf.saxon.expr;
2
3 import net.sf.saxon.type.AtomicType;
4 import net.sf.saxon.trans.XPathException;
5 import net.sf.saxon.trans.StaticError;
6 import net.sf.saxon.Configuration;
7 import net.sf.saxon.om.SequenceIterator;
8 import net.sf.saxon.om.ValueRepresentation;
9 import net.sf.saxon.value.Closure;
10 import net.sf.saxon.value.MemoClosure;
11
12 import java.io.Serializable JavaDoc;
13
14 /**
15  * This class doesn't actually do any optimization itself, despite the name. Rather, it is
16  * intended to act as a factory for implementation classes that perform optimization, so that
17  * the appropriate level of optimization can be selected.
18  */

19 public class Optimizer implements Serializable JavaDoc {
20
21     protected Configuration config;
22
23     public Optimizer(Configuration config) {
24         this.config = config;
25     }
26
27     public Configuration getConfiguration() {
28         return config;
29     }
30
31     /**
32      * Create a GeneralComparison expression
33      */

34
35     public BinaryExpression makeGeneralComparison(Expression p0, int op, Expression p1, boolean backwardsCompatible) {
36         if (backwardsCompatible) {
37             return new GeneralComparison10(p0, op, p1);
38         } else {
39             return new GeneralComparison(p0, op, p1);
40         }
41     }
42
43     /**
44      * Attempt to optimize a copy operation. Return null if no optimization is possible.
45      * @param select the expression that selects the items to be copied
46      * @return null if no optimization is possible, or an expression that does an optimized
47      * copy of these items otherwise
48      */

49
50     public Expression optimizeCopy(Expression select) throws XPathException {
51         if (select.getItemType() instanceof AtomicType) {
52             return select;
53         }
54         return null;
55     }
56
57     /**
58      * Make a Closure, given the expected reference count
59      */

60
61     public Closure makeClosure(Expression expression, int ref) {
62         if (ref == 1) {
63             return new Closure();
64         } else {
65             return new MemoClosure();
66         }
67     }
68
69     /**
70      * Examine a path expression to see whether it can be replaced by a call on the key() function;
71      * if so, generate an appropriate key definition and return the call on key(). If not, return null.
72      * @param pathExp The path expression to be converted.
73      */

74
75     public Expression convertPathExpressionToKey(PathExpression pathExp, StaticContext env) throws XPathException {
76         return null;
77     }
78
79     /**
80      * Convert a path expression such as a/b/c[predicate] into a filter expression
81      * of the form (a/b/c)[predicate]. This is possible whenever the predicate is non-positional.
82      * The conversion is useful in the case where the path expression appears inside a loop,
83      * where the predicate depends on the loop variable but a/b/c does not.
84      * @param pathExp the path expression to be converted
85      * @return the resulting filterexpression if conversion is possible, or null if not
86      */

87
88     public FilterExpression convertToFilterExpression(PathExpression pathExp) throws StaticError {
89         return null;
90     }
91
92     public SequenceIterator tryIndexedFilter(ValueRepresentation startValue, Expression filter,
93                                              int isIndexable, XPathContext context) throws XPathException {
94         return null;
95     }
96
97     /**
98      * Test whether a filter predicate is indexable.
99      * @param filter the predicate expression
100      * @return 0 if not indexable; +1 if the predicate is in the form expression=value; -1 if it is in
101      * the form value=expression
102      */

103
104     public int isIndexableFilter(Expression filter) {
105         return 0;
106     }
107 }
108
109 //
110
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
111
// you may not use this file except in compliance with the License. You may obtain a copy of the
112
// License at http://www.mozilla.org/MPL/
113
//
114
// Software distributed under the License is distributed on an "AS IS" basis,
115
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
116
// See the License for the specific language governing rights and limitations under the License.
117
//
118
// The Original Code is: all this file.
119
//
120
// The Initial Developer of the Original Code is Michael H. Kay.
121
//
122
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
123
//
124
// Contributor(s): none.
125
//
126

127
Popular Tags