1 23 24 package org.apache.slide.common; 25 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 import java.util.Enumeration ; 29 import java.util.NoSuchElementException ; 30 31 47 public final class ScopeTokenizer extends StringTokenizer { 48 49 50 52 53 58 public ScopeTokenizer(SlideToken slideToken, Namespace namespace, String uri) { 59 super(uri, "/"); 60 61 scopes = new Vector (); 63 64 this.slideToken = slideToken; 66 this.namespace = namespace; 67 68 String courScope = new String (); 69 70 scopes.insertElementAt("/", 0); 71 72 while(super.hasMoreTokens()) { 74 courScope = courScope + "/" + super.nextToken(); 75 scopes.insertElementAt(courScope, 0); 76 } 77 78 pos = 0; 79 } 80 81 82 88 public ScopeTokenizer(Namespace namespace, String uri) { 89 this(null, namespace, uri); 90 } 91 92 93 99 public ScopeTokenizer(Namespace namespace, Scope scope) { 100 this(null, namespace, scope.toString()); 101 } 102 103 104 106 107 110 Vector scopes; 111 112 113 116 int pos; 117 118 119 122 Namespace namespace; 123 SlideToken slideToken; 124 125 126 128 129 134 public Uri getParentUri() { 135 if (scopes.size() <= 1) { 136 return null; 137 } else { 138 return namespace.getUri(slideToken, (String ) scopes.elementAt(1)); 139 } 140 } 141 142 143 148 public boolean hasMoreElements() { 149 return scopes.size() > pos; 150 } 151 152 153 158 public boolean hasMoreTokens() { 159 return hasMoreElements(); 160 } 161 162 163 169 public Object nextElement() 170 throws NoSuchElementException { 171 Object obj = null; 172 try { 173 if (!hasMoreElements()) { 174 throw new NoSuchElementException (); 175 } 176 obj = scopes.elementAt(pos); 177 pos = pos + 1; 178 } catch (ArrayIndexOutOfBoundsException e) { 179 e.printStackTrace(); 181 } 182 return obj; 183 } 184 185 186 192 public String nextToken() 193 throws NoSuchElementException { 194 return (String ) nextElement(); 195 } 196 197 198 204 public Scope nextScope() 205 throws NoSuchElementException { 206 return new Scope(nextToken()); 207 } 208 209 210 216 public String nextToken(String delim) 217 throws NoSuchElementException { 218 return nextToken(); 219 } 220 221 222 227 public Enumeration elements() { 228 return scopes.elements(); 229 } 230 231 232 234 235 240 String getUri() { 241 if (scopes.size() < 1) { 242 return null; 243 } else { 244 return (String ) scopes.elementAt(0); 245 } 246 } 247 248 } 249 | Popular Tags |