1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.utils.security;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.gwe.drivers.HandleCreationException;
24 import org.gwe.drivers.ResourceHandle;
25 import org.gwe.drivers.ResourceHandleFactory;
26 import org.gwe.drivers.netAccess.HostHandle;
27
28
29
30
31
32 public class ResourceLink<HANDLE_TYPE extends ResourceHandle> implements Serializable {
33
34 private static Log log = LogFactory.getLog(ResourceLink.class);
35
36 private static ResourceHandleFactory repo;
37
38 public static void setHandleFactory(ResourceHandleFactory repo) {
39 ResourceLink.repo = repo;
40 }
41
42 protected ThinURI uri;
43 protected AccountInfo account;
44
45 public ResourceLink(ThinURI uri, AccountInfo account) {
46 this.uri = uri;
47 this.account = account;
48 if (account == null)
49 log.warn("Account not found for uri" + uri);
50 }
51
52 public AccountInfo getAccountInfo() {
53 return account;
54 }
55
56 public ThinURI getURI() {
57 return uri;
58 }
59
60 public String getURIHost() {
61 return (uri == null) ? null : uri.getHost();
62 }
63
64 public ResourceLink<HostHandle> cloneToHostLink(ProtocolScheme hostScheme) {
65 ThinURI hostURI = new ThinURI(hostScheme, uri.getHost(), "");
66 return new ResourceLink<HostHandle>(hostURI, account);
67 }
68
69 public HANDLE_TYPE createHandle() throws HandleCreationException {
70 return repo.createHandle(this);
71 }
72
73 public Class<HANDLE_TYPE> getHandleClass() {
74 return repo.getHandleClass(this);
75 }
76
77 public String toString() {
78 String accountName = (account != null) ? account.getUser() : "NONE";
79 return "[" + accountName + "]@[" + uri + "]";
80 }
81 }
82