KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > jdom > DocumentWrapper


1 package net.sf.saxon.jdom;
2 import net.sf.saxon.Configuration;
3 import net.sf.saxon.om.DocumentInfo;
4 import net.sf.saxon.om.NamePool;
5 import net.sf.saxon.om.NodeInfo;
6 import net.sf.saxon.type.Type;
7 import org.jdom.Document;
8
9 /**
10   * The root node of an XPath tree. (Or equivalently, the tree itself).<P>
11   * This class should have been named Root; it is used not only for the root of a document,
12   * but also for the root of a result tree fragment, which is not constrained to contain a
13   * single top-level element.
14   * @author Michael H. Kay
15   */

16
17 public class DocumentWrapper extends NodeWrapper implements DocumentInfo {
18
19     protected Configuration config;
20     protected String JavaDoc baseURI;
21     protected int documentNumber;
22
23     /**
24      * Create a Saxon wrapper for a JDOM document
25      * @param doc The JDOM document
26      * @param baseURI The base URI for all the nodes in the document
27      */

28
29     public DocumentWrapper(Document doc, String JavaDoc baseURI, Configuration config) {
30         super(doc, null, 0);
31         node = doc;
32         nodeKind = Type.DOCUMENT;
33         this.baseURI = baseURI;
34         docWrapper = this;
35         setConfiguration(config);
36     }
37
38     /**
39      * Wrap a node in the JDOM document.
40      * @param node The node to be wrapped. This must be a node in the same document
41      * (the system does not check for this).
42      * @return the wrapping NodeInfo object
43      */

44
45     public NodeWrapper wrap(Object JavaDoc node) {
46         if (node==this.node) {
47             return this;
48         }
49         return makeWrapper(node, this);
50     }
51
52
53
54     /**
55     * Set the configuration (containing the name pool used for all names in this document)
56     */

57
58     public void setConfiguration(Configuration config) {
59         this.config = config;
60         documentNumber = config.getDocumentNumberAllocator().allocateDocumentNumber();
61     }
62
63     /**
64      * Get the configuration previously set using setConfiguration
65      * (or the default configuraton allocated automatically)
66      */

67
68     public Configuration getConfiguration() {
69         return config;
70     }
71
72
73     /**
74     * Get the name pool used for the names in this document
75     */

76
77     public NamePool getNamePool() {
78         return config.getNamePool();
79     }
80
81     /**
82     * Get the unique document number
83     */

84
85     public int getDocumentNumber() {
86         return documentNumber;
87     }
88
89     /**
90     * Get the element with a given ID, if any
91     * @param id the required ID value
92     * @return null: JDOM does not provide any information about attribute types.
93     */

94
95     public NodeInfo selectID(String JavaDoc id) {
96         return null;
97     }
98
99     /**
100     * Get the unparsed entity with a given name
101     * @param name the name of the entity
102     * @return null: JDOM does not provide access to unparsed entities
103     */

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