1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 package org.astrogrid.filemanager.resolver ;
34
35 import org.apache.commons.logging.Log ;
36 import org.apache.commons.logging.LogFactory ;
37
38 import java.net.URL ;
39
40 import java.util.Map ;
41 import java.util.HashMap ;
42
43 import org.astrogrid.store.Ivorn ;
44
45 import org.astrogrid.registry.client.query.RegistryService ;
46
47 import org.astrogrid.filemanager.common.FileManager ;
48 import org.astrogrid.filemanager.common.ivorn.FileManagerIvornParser ;
49
50 import org.astrogrid.filemanager.common.exception.FileManagerServiceException ;
51 import org.astrogrid.filemanager.common.exception.FileManagerIdentifierException ;
52
53 import org.astrogrid.filemanager.client.delegate.FileManagerDelegate ;
54 import org.astrogrid.filemanager.client.delegate.FileManagerMockDelegate ;
55
56 /***
57 * A resolver for mock filemanagers.
58 *
59 */
60 public class FileManagerDelegateResolverMock
61 implements FileManagerDelegateResolver
62 {
63 /***
64 * Our debug logger.
65 *
66 */
67 private static Log log = LogFactory.getLog(FileManagerDelegateResolverMock.class);
68
69 /***
70 * Public constructor.
71 *
72 */
73 public FileManagerDelegateResolverMock()
74 {
75 }
76
77 /***
78 * Our internal map of services.
79 *
80 */
81 private Map map = new HashMap() ;
82
83 /***
84 * Register a new filemanager.
85 *
86 */
87 public void register(FileManagerDelegate delegate)
88 throws FileManagerServiceException
89 {
90 map.put(
91 delegate.getServiceIvorn().toString(),
92 delegate
93 );
94 }
95
96 /***
97 * Resolve an Ivorn into a delegate.
98 * @param ivorn An Ivorn containing a filemanager identifier.
99 * @return A FileManagerDelegate for the service.
100 * @throws FileManagerResolverException If unable to resolve the identifier.
101 *
102 */
103 public FileManagerDelegate resolve(Ivorn ivorn)
104 throws FileManagerResolverException
105 {
106 log.debug("") ;
107 log.debug("----\"----") ;
108 log.debug("FileManagerDelegateResolverMock.resolve()") ;
109 log.debug(" Ivorn : " + ivorn) ;
110 if (null == ivorn)
111 {
112 throw new IllegalArgumentException(
113 "Null service ivorn"
114 );
115 }
116
117
118 String ident = null ;
119 try {
120 ident = new FileManagerIvornParser(
121 ivorn
122 ).getServiceIdent() ;
123 }
124 catch (FileManagerIdentifierException ouch)
125 {
126 throw new FileManagerResolverException(
127 "Unable to parse service ivorn : " + ivorn.toString()
128 ) ;
129 }
130
131
132 if (map.containsKey(ident))
133 {
134 return (FileManagerDelegate) map.get(ident) ;
135 }
136 else {
137 throw new FileManagerResolverException(
138 "FileManager not found"
139 ) ;
140 }
141 }
142 }
143