KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > datamodel > ValidationContextProvider


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 XQuark Group.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xpath.datamodel;
24
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 public class ValidationContextProvider
30     implements org.xquark.schema.validation.ValidationContextProvider {
31     public static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
32     public static final String JavaDoc RCSName = "$Name: $";
33
34     protected HashMap JavaDoc namespaces;
35     protected HashMap JavaDoc notations;
36     protected String JavaDoc documentBase;
37     protected HashMap JavaDoc reverseNamespaces = null;
38
39     /**
40      * Constructor for ValidationContextProvider.
41      */

42     public ValidationContextProvider(Map JavaDoc namespaces, HashMap JavaDoc notations,
43                                      String JavaDoc documentBase) {
44         this.namespaces = new HashMap JavaDoc(namespaces);
45
46         if (notations != null) {
47             this.notations = new HashMap JavaDoc(notations);
48         }
49
50         this.documentBase = documentBase;
51     }
52
53     /**
54      * @see ValidationContextProvider#getDocumentBase()
55      */

56     public String JavaDoc getDocumentBase() {
57         return documentBase;
58     }
59
60     /**
61      * @see ValidationContextProvider#getNotationDeclarations()
62      */

63     public Map JavaDoc getNotationDeclarations() {
64         return notations;
65     }
66
67     /**
68      * @see ValidationContextProvider#getNamespaceURI(String)
69      */

70     public String JavaDoc getNamespaceURI(String JavaDoc prefix) {
71         return (String JavaDoc) namespaces.get(prefix);
72     }
73
74     /**
75      * @see ValidationContextProvider#getPrefix(String)
76      */

77     public String JavaDoc getPrefix(String JavaDoc uri) {
78         if (reverseNamespaces == null) {
79             reverseNamespaces = new HashMap JavaDoc(namespaces.size());
80
81             Iterator JavaDoc iterator = namespaces.keySet().iterator();
82             Object JavaDoc pre;
83             Object JavaDoc name;
84
85             while (iterator.hasNext()) {
86                 pre = iterator.next();
87                 name = namespaces.get(pre);
88                 reverseNamespaces.put(name, pre);
89             }
90         }
91
92         return (String JavaDoc) reverseNamespaces.get(uri);
93     }
94 }
95
Popular Tags