KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > compiler > NamespaceManager


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.compiler;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import com.sun.facelets.tag.TagLibrary;
21
22 /**
23  * @author Jacob Hookom
24  * @version $Id: NamespaceManager.java,v 1.4 2005/08/24 04:38:54 jhook Exp $
25  */

26 final class NamespaceManager {
27
28     private final static class NS {
29         public final String JavaDoc prefix;
30
31         public final String JavaDoc namespace;
32
33         public NS(String JavaDoc prefix, String JavaDoc ns) {
34             this.prefix = prefix;
35             this.namespace = ns;
36         }
37     }
38
39     private final List JavaDoc namespaces;
40
41     /**
42      *
43      */

44     public NamespaceManager() {
45         this.namespaces = new ArrayList JavaDoc();
46     }
47
48     public void reset() {
49         this.namespaces.clear();
50     }
51
52     public void pushNamespace(String JavaDoc prefix, String JavaDoc namespace) {
53         NS ns = new NS(prefix, namespace);
54         this.namespaces.add(0, ns);
55     }
56
57     public String JavaDoc getNamespace(String JavaDoc prefix) {
58         NS ns = null;
59         for (int i = 0; i < this.namespaces.size(); i++) {
60             ns = (NS) this.namespaces.get(i);
61             if (ns.prefix.equals(prefix)) {
62                 return ns.namespace;
63             }
64         }
65         return null;
66     }
67
68     public void popNamespace(String JavaDoc prefix) {
69         NS ns = null;
70         for (int i = 0; i < this.namespaces.size(); i++) {
71             ns = (NS) this.namespaces.get(i);
72             if (ns.prefix.equals(prefix)) {
73                 this.namespaces.remove(i);
74                 return;
75             }
76         }
77     }
78     
79     public final NamespaceUnit toNamespaceUnit(TagLibrary library) {
80         NamespaceUnit unit = new NamespaceUnit(library);
81         if (this.namespaces.size() > 0) {
82             NS ns = null;
83             for (int i = this.namespaces.size() - 1; i >= 0; i--) {
84                 ns = (NS) this.namespaces.get(i);
85                 unit.setNamespace(ns.prefix, ns.namespace);
86             }
87         }
88         return unit;
89     }
90
91 }
92
Popular Tags