KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > instruct > DummyNamespaceResolver


1 package net.sf.saxon.instruct;
2 import net.sf.saxon.om.NamespaceConstant;
3 import net.sf.saxon.om.NamespaceResolver;
4
5 import java.io.Serializable JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 /**
11   * A dummy namespace resolver used when validating QName-valued attributes written to
12   * the result tree. The namespace node might be created after the initial validation
13   * of the attribute, so in the first round of validation we only check the lexical form
14   * of the value, and we defer prefix checks until later.
15   */

16
17 public final class DummyNamespaceResolver implements Serializable JavaDoc, NamespaceResolver {
18
19     private static DummyNamespaceResolver theInstance = new DummyNamespaceResolver();
20
21     /**
22      * Return the singular instance of this class
23      * @return the singular instance
24      */

25
26     public static DummyNamespaceResolver getInstance() {
27         return theInstance;
28     }
29
30     private DummyNamespaceResolver() {};
31
32
33     /**
34     * Get the namespace URI corresponding to a given prefix.
35     * @param prefix the namespace prefix
36     * @param useDefault true if the default namespace is to be used when the
37     * prefix is ""
38     * @return the uri for the namespace, or null if the prefix is not in scope
39     */

40
41     public String JavaDoc getURIForPrefix(String JavaDoc prefix, boolean useDefault) {
42         if ("".equals(prefix)) {
43             return "";
44         } else if ("xml".equals(prefix)) {
45             return NamespaceConstant.XML;
46         } else {
47             // this is a dummy namespace resolver, we don't actually know the URI
48
return "";
49         }
50     }
51
52     /**
53      * Get an iterator over all the prefixes declared in this namespace context. This will include
54      * the default namespace (prefix="") and the XML namespace where appropriate
55      */

56
57     public Iterator JavaDoc iteratePrefixes() {
58         List JavaDoc list = new ArrayList JavaDoc(2);
59         list.add("");
60         list.add("xml");
61         return list.iterator();
62     }
63 }
64
65 //
66
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
67
// you may not use this file except in compliance with the License. You may obtain a copy of the
68
// License at http://www.mozilla.org/MPL/
69
//
70
// Software distributed under the License is distributed on an "AS IS" basis,
71
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
72
// See the License for the specific language governing rights and limitations under the License.
73
//
74
// The Original Code is: all this file.
75
//
76
// The Initial Developer of the Original Code is Michael H. Kay
77
//
78
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
79
//
80
// Contributor(s): none.
81
//
82
Popular Tags