1 23 24 package org.apache.slide.common; 25 26 import java.io.IOException ; 27 import java.util.Enumeration ; 28 29 import org.apache.slide.store.Store; 30 31 37 public class Uri implements Cloneable , java.io.Serializable { 38 39 40 42 43 51 public Uri(Namespace namespace, String uri) { 52 this(null, namespace, uri); 53 } 54 55 56 63 public Uri(SlideToken token, Namespace namespace, String uri) { 64 this.token = token; 65 this.namespace = namespace; 66 parseUri(uri); 67 } 68 69 70 72 73 76 protected transient Namespace namespace; 77 78 79 82 protected transient String uri; 83 84 85 88 protected transient ScopeTokenizer scopes; 89 90 91 94 protected transient Scope scope; 95 96 97 100 protected transient Store store; 101 102 103 106 protected transient SlideToken token; 107 108 109 111 112 117 public void setUri(String uri) { 118 parseUri(uri); 119 } 120 121 122 130 public static Uri getRoot(Uri uri) { 131 return new Uri(uri.getToken(), uri.getNamespace(), uri.getScope().toString()); 132 } 133 134 135 140 public Scope getScope() { 141 return this.scope; 142 } 143 144 145 151 public Enumeration getScopes() { 152 return this.scopes.elements(); 153 } 154 155 156 161 public Store getStore() { 162 return this.store; 163 } 164 165 166 172 public SlideToken getToken() { 173 return token; 174 } 175 176 177 182 public void setToken(SlideToken token) { 183 this.token = token; 184 } 185 186 187 189 190 195 public Namespace getNamespace() { 196 return namespace; 197 } 198 199 200 205 public Uri getParentUri() { 206 Uri result = scopes.getParentUri(); 207 if (result != null) 208 result.setToken(token); 209 return result; 210 } 211 212 213 217 public void invalidateServices() { 218 store = null; 219 parseUri(this.uri); 220 } 221 222 223 226 public void reconnectServices() { 227 try { 228 if (token == null) { 229 store.connectIfNeeded(null); 230 } else { 231 store.connectIfNeeded(token.getCredentialsToken()); 232 } 233 } catch (ServiceConnectionFailedException e) { 234 parseUri(this.uri); 235 } catch (ServiceAccessException e) { 236 parseUri(this.uri); 237 } 238 } 239 240 241 244 public String getRelative() { 245 return (uri.substring(scope.toString().length())); 246 } 247 248 252 public boolean isStoreRoot() { 253 UriPath thisPath = new UriPath(uri); 254 UriPath scopePath = new UriPath(scope.toString()); 255 return thisPath.equals(scopePath); 256 } 257 258 260 261 266 public String toString() { 267 return uri; 268 } 269 270 271 276 public int hashCode() { 277 return this.uri.hashCode(); 278 } 279 280 281 287 public boolean equals(Object obj) { 288 if ((obj != null) && (obj instanceof Uri)) { 289 return (uri.equals(obj.toString())); 290 } else { 291 return false; 292 } 293 } 294 295 296 299 public Uri cloneObject() { 300 Uri result = null; 301 try { 302 result = (Uri) super.clone(); 303 } catch (CloneNotSupportedException e) { 304 e.printStackTrace(); 305 } 306 return result; 307 } 308 309 310 316 public boolean isParent(Uri uri) { 317 return this.uri.startsWith(uri.toString()); 318 } 319 320 321 323 324 329 private void parseUri(String uri) { 330 332 scopes = new ScopeTokenizer(token, namespace, uri); 333 334 this.uri = scopes.getUri(); 335 336 store = null; 340 while ((store == null) && (scopes.hasMoreElements())) { 341 Scope courScope = scopes.nextScope(); 342 try { 343 if (store == null) { 344 if (token == null) { 345 store = namespace.retrieveStore(courScope, null); 346 } else { 347 store = namespace.retrieveStore(courScope, token.getCredentialsToken()); 348 } 349 350 if (store != null) { 351 scope = courScope; 352 } 353 } 354 } catch (ServiceConnectionFailedException e) { 355 } catch (ServiceAccessException e) { 358 } 361 } 362 363 if (store == null) { 366 throw new ServiceMissingOnRootNodeException(); 367 } 368 369 } 370 371 372 374 375 378 private void readObject(java.io.ObjectInputStream in) 379 throws IOException , ClassNotFoundException { 380 String namespaceName = (String ) in.readObject(); 381 namespace = Domain.getNamespace(namespaceName); 382 parseUri((String ) in.readObject()); 383 } 384 385 386 389 private void writeObject(java.io.ObjectOutputStream out) 390 throws IOException { 391 out.writeObject(namespace.getName()); 392 out.writeObject(uri); 393 } 394 395 } 396 | Popular Tags |