KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > event > NamePoolConverter


1 package net.sf.saxon.event;
2 import net.sf.saxon.om.NamePool;
3 import net.sf.saxon.trans.XPathException;
4
5 /**
6 * This class is a filter that passes all Receiver events through unchanged,
7 * except that it changes namecodes to allow for the source and the destination
8 * using different NamePools. This is necessary when a stylesheet has been constructed
9 * as a general document (e.g. as the result of a transformation) and is passed to
10 * newTemplates() to be compiled as a stylesheet.
11 *
12 * @author Michael Kay
13 */

14
15
16 public class NamePoolConverter extends ProxyReceiver {
17
18     NamePool oldPool;
19     NamePool newPool;
20
21     /**
22     * Constructor
23     */

24
25     public NamePoolConverter(NamePool oldPool, NamePool newPool) {
26         this.oldPool = oldPool;
27         this.newPool = newPool;
28     }
29
30     /**
31     * Set the underlying emitter. This call is mandatory before using the Emitter.
32     * This version is modified from that of the parent class to avoid setting the namePool
33     * of the destination Receiver.
34     */

35
36     public void setUnderlyingReceiver(Receiver receiver) {
37         nextReceiver = receiver;
38     }
39
40     /**
41     * Output element start tag
42     */

43
44     public void startElement(int nameCode, int typeCode, int locationId, int properties) throws XPathException {
45         int nc = newPool.allocate(oldPool.getPrefix(nameCode), oldPool.getURI(nameCode), oldPool.getLocalName(nameCode));
46         super.startElement(nc, typeCode, locationId, properties);
47     }
48
49     /**
50     * Handle a namespace
51     */

52
53     public void namespace(int namespaceCode, int properties) throws XPathException {
54         int nc = newPool.allocateNamespaceCode(oldPool.getPrefixFromNamespaceCode(namespaceCode),
55                                                 oldPool.getURIFromNamespaceCode(namespaceCode));
56         super.namespace(nc, properties);
57     }
58
59     /**
60     * Handle an attribute
61     */

62
63     public void attribute(int nameCode, int typeCode, CharSequence JavaDoc value, int locationId, int properties)
64     throws XPathException {
65         int nc = newPool.allocate(oldPool.getPrefix(nameCode), oldPool.getURI(nameCode), oldPool.getLocalName(nameCode));
66         super.attribute(nc, typeCode, value, locationId, properties);
67     }
68
69 };
70
71 //
72
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
73
// you may not use this file except in compliance with the License. You may obtain a copy of the
74
// License at http://www.mozilla.org/MPL/
75
//
76
// Software distributed under the License is distributed on an "AS IS" basis,
77
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
78
// See the License for the specific language governing rights and limitations under the License.
79
//
80
// The Original Code is: all this file.
81
//
82
// The Initial Developer of the Original Code is Michael H. Kay
83
//
84
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
85
//
86
// Contributor(s): none.
87
//
88

89
Popular Tags