1 14 15 package com.sun.facelets.compiler; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import com.sun.facelets.tag.TagLibrary; 21 22 26 final class NamespaceManager { 27 28 private final static class NS { 29 public final String prefix; 30 31 public final String namespace; 32 33 public NS(String prefix, String ns) { 34 this.prefix = prefix; 35 this.namespace = ns; 36 } 37 } 38 39 private final List namespaces; 40 41 44 public NamespaceManager() { 45 this.namespaces = new ArrayList (); 46 } 47 48 public void reset() { 49 this.namespaces.clear(); 50 } 51 52 public void pushNamespace(String prefix, String namespace) { 53 NS ns = new NS(prefix, namespace); 54 this.namespaces.add(0, ns); 55 } 56 57 public String getNamespace(String 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 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 |