KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > Collection


1 package net.sf.saxon.functions;
2 import net.sf.saxon.CollectionURIResolver;
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.expr.StaticContext;
5 import net.sf.saxon.expr.XPathContext;
6 import net.sf.saxon.om.EmptyIterator;
7 import net.sf.saxon.om.SequenceIterator;
8 import net.sf.saxon.trans.XPathException;
9
10 /**
11  * Implement the fn:collection() function. The Saxon implementation loads an XML
12  * document called the collection catalogue, which acts as an index of the collection.
13  *
14  * <p>The structure of this index is:
15  * <pre>
16  * &lt;collection&gt;
17  * &lt;doc HREF="doc1.xml"&gt;
18  * &lt;doc HREF="doc2.xml"&gt;
19  * &lt;doc HREF="doc3.xml"&gt;
20  * &lt;/collection&gt;
21  * </pre></p>
22  *
23  * <p>The document URIs are resolved relative to the base URI of the doc element
24  * in the catalogue document.</p>
25  */

26
27 public class Collection extends SystemFunction {
28
29     private String JavaDoc expressionBaseURI = null;
30
31     public void checkArguments(StaticContext env) throws XPathException {
32         if (expressionBaseURI == null) {
33             super.checkArguments(env);
34             expressionBaseURI = env.getBaseURI();
35         }
36     }
37
38     /**
39     * preEvaluate: this method suppresses compile-time evaluation by doing nothing
40     */

41
42     public Expression preEvaluate(StaticContext env) {
43         return this;
44     }
45
46     public SequenceIterator iterate(XPathContext context) throws XPathException {
47
48         String JavaDoc href;
49
50         // Zero-argument function:
51

52         if (getNumberOfArguments() == 0) {
53             href = null;
54         } else {
55             href = argument[0].evaluateItem(context).getStringValue();
56         }
57
58         CollectionURIResolver resolver = context.getController().getConfiguration().getCollectionURIResolver();
59         SequenceIterator iter = resolver.resolve(href, expressionBaseURI, context);
60
61         if (iter == null) {
62             return EmptyIterator.getInstance();
63         } else {
64             return iter;
65         }
66     }
67
68
69
70     // TODO: provide control over error recovery (etc) through options in the catalog file.
71

72 }
73
74
75
76
77
78 //
79
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
80
// you may not use this file except in compliance with the License. You may obtain a copy of the
81
// License at http://www.mozilla.org/MPL/
82
//
83
// Software distributed under the License is distributed on an "AS IS" basis,
84
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
85
// See the License for the specific language governing rights and limitations under the License.
86
//
87
// The Original Code is: all this file.
88
//
89
// The Initial Developer of the Original Code is Michael H. Kay.
90
//
91
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
92
//
93
// Contributor(s): none.
94
//
95
Popular Tags