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 package org.astrogrid.filestore.resolver ;
32
33 import org.apache.commons.logging.Log ;
34 import org.apache.commons.logging.LogFactory ;
35
36 import java.net.URL ;
37
38 import java.util.Map ;
39 import java.util.HashMap ;
40
41 import org.astrogrid.store.Ivorn ;
42
43 import org.astrogrid.registry.client.query.RegistryService ;
44
45 import org.astrogrid.filestore.common.FileStore ;
46 import org.astrogrid.filestore.common.ivorn.FileStoreIvornParser ;
47 import org.astrogrid.filestore.client.FileStoreDelegate ;
48 import org.astrogrid.filestore.client.FileStoreSoapDelegate ;
49 import org.astrogrid.filestore.client.FileStoreMockDelegate ;
50 import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
51 import org.astrogrid.filestore.common.exception.FileStoreServiceException ;
52
53 /***
54 * A resolver for mock filestores.
55 *
56 */
57 public class FileStoreDelegateResolverMock
58 implements FileStoreDelegateResolver
59 {
60 /***
61 * Our debug logger.
62 *
63 */
64 private static Log log = LogFactory.getLog(FileStoreDelegateResolverMock.class);
65
66 /***
67 * Public constructor.
68 *
69 */
70 public FileStoreDelegateResolverMock()
71 {
72 }
73
74 /***
75 * Our internal map of services.
76 *
77 */
78 private Map map = new HashMap() ;
79
80 /***
81 * Register a new filestore.
82 *
83 */
84 public void register(FileStoreDelegate store)
85 throws FileStoreServiceException
86 {
87 map.put(
88 store.identifier(),
89 store
90 );
91 }
92
93 /***
94 * Resolve an Ivorn into a delegate.
95 * @param ivorn An Ivorn containing a filestore identifier.
96 * @return A FileStoreDelegate for the service.
97 * @throws FileStoreIdentifierException If the identifier is not valid.
98 * @throws FileStoreResolverException If unable to resolve the identifier.
99 *
100 */
101 public FileStoreDelegate resolve(Ivorn ivorn)
102 throws FileStoreIdentifierException, FileStoreResolverException
103 {
104 log.debug("") ;
105 log.debug("----\"----") ;
106 log.debug("FileStoreDelegateResolverMock.resolve()") ;
107 log.debug(" Ivorn : " + ivorn) ;
108
109
110 String ident = new FileStoreIvornParser(
111 ivorn
112 ).getServiceIdent() ;
113
114
115 if (map.containsKey(ident))
116 {
117 return (FileStoreDelegate) map.get(ident) ;
118 }
119 else {
120 throw new FileStoreResolverException(
121 "FileStore not found"
122 ) ;
123 }
124 }
125 }
126