01: package net.sf.saxon.instruct;
02:
03: import net.sf.saxon.om.NamespaceConstant;
04: import net.sf.saxon.om.NamespaceResolver;
05:
06: import java.io.Serializable;
07: import java.util.ArrayList;
08: import java.util.Iterator;
09: import java.util.List;
10:
11: /**
12: * A dummy namespace resolver used when validating QName-valued attributes written to
13: * the result tree. The namespace node might be created after the initial validation
14: * of the attribute, so in the first round of validation we only check the lexical form
15: * of the value, and we defer prefix checks until later.
16: */
17:
18: public final class DummyNamespaceResolver implements Serializable,
19: NamespaceResolver {
20:
21: private static DummyNamespaceResolver theInstance = new DummyNamespaceResolver();
22:
23: /**
24: * Return the singular instance of this class
25: * @return the singular instance
26: */
27:
28: public static DummyNamespaceResolver getInstance() {
29: return theInstance;
30: }
31:
32: private DummyNamespaceResolver() {
33: };
34:
35: /**
36: * Get the namespace URI corresponding to a given prefix.
37: * @param prefix the namespace prefix
38: * @param useDefault true if the default namespace is to be used when the
39: * prefix is ""
40: * @return the uri for the namespace, or null if the prefix is not in scope
41: */
42:
43: public String getURIForPrefix(String prefix, boolean useDefault) {
44: if ("".equals(prefix)) {
45: return "";
46: } else if ("xml".equals(prefix)) {
47: return NamespaceConstant.XML;
48: } else {
49: // this is a dummy namespace resolver, we don't actually know the URI
50: return "";
51: }
52: }
53:
54: /**
55: * Get an iterator over all the prefixes declared in this namespace context. This will include
56: * the default namespace (prefix="") and the XML namespace where appropriate
57: */
58:
59: public Iterator iteratePrefixes() {
60: List list = new ArrayList(2);
61: list.add("");
62: list.add("xml");
63: return list.iterator();
64: }
65: }
66:
67: //
68: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
69: // you may not use this file except in compliance with the License. You may obtain a copy of the
70: // License at http://www.mozilla.org/MPL/
71: //
72: // Software distributed under the License is distributed on an "AS IS" basis,
73: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
74: // See the License for the specific language governing rights and limitations under the License.
75: //
76: // The Original Code is: all this file.
77: //
78: // The Initial Developer of the Original Code is Michael H. Kay
79: //
80: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
81: //
82: // Contributor(s): none.
83: //
|